diff --git a/.vscode/launch.json b/.vscode/launch.json index 0b6b9a6499..1519379f6e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "windows": { "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite.cmd" }, - "runtimeArgs": ["--sourcemap"], + "runtimeArgs": ["--inspect", "--sourcemap"], "env": { "REMOTE_DEBUGGING_PORT": "9222" } @@ -21,7 +21,7 @@ "request": "attach", "type": "chrome", "webRoot": "${workspaceFolder}/src/renderer", - "timeout": 60000, + "timeout": 3000000, "presentation": { "hidden": true } diff --git a/src/renderer/src/components/MinApp/MinappPopupContainer.tsx b/src/renderer/src/components/MinApp/MinappPopupContainer.tsx index f9a4ee7e1e..4ba7badff6 100644 --- a/src/renderer/src/components/MinApp/MinappPopupContainer.tsx +++ b/src/renderer/src/components/MinApp/MinappPopupContainer.tsx @@ -22,7 +22,7 @@ import { useAppDispatch } from '@renderer/store' import { setMinappsOpenLinkExternal } from '@renderer/store/settings' import { MinAppType } from '@renderer/types' import { delay } from '@renderer/utils' -import { Avatar, Drawer, Tooltip } from 'antd' +import { Alert, Avatar, Button, Drawer, Tooltip } from 'antd' import { WebviewTag } from 'electron' import { useEffect, useMemo, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' @@ -39,6 +39,100 @@ interface AppExtraInfo { type AppInfo = MinAppType & AppExtraInfo +/** Google login tip component */ +const GoogleLoginTip = ({ + isReady, + currentUrl, + currentAppId +}: { + appId?: string | null + isReady: boolean + currentUrl: string | null + currentAppId: string | null +}) => { + const { t } = useTranslation() + const [visible, setVisible] = useState(false) + const { openMinappById } = useMinappPopup() + + // 判断当前URL是否涉及Google登录 + const needsGoogleLogin = useMemo(() => { + // 如果当前已经在Google小程序中,不需要显示提示 + if (currentAppId === 'google') return false + + if (!currentUrl) return false + + const googleLoginPatterns = [ + 'accounts.google.com', + 'signin/oauth', + 'auth/google', + 'login/google', + 'sign-in/google', + 'google.com/signin', + 'gsi/client' + ] + + return googleLoginPatterns.some((pattern) => currentUrl.toLowerCase().includes(pattern.toLowerCase())) + }, [currentUrl, currentAppId]) + + // 在URL更新时检查是否需要显示提示 + useEffect(() => { + let showTimer: NodeJS.Timeout | null = null + let hideTimer: NodeJS.Timeout | null = null + + // 如果是Google登录相关URL且小程序已加载完成,则延迟显示提示 + if (needsGoogleLogin && isReady) { + showTimer = setTimeout(() => { + setVisible(true) + hideTimer = setTimeout(() => { + setVisible(false) + }, 30000) + }, 500) + } else { + setVisible(false) + } + + return () => { + if (showTimer) clearTimeout(showTimer) + if (hideTimer) clearTimeout(hideTimer) + } + }, [needsGoogleLogin, isReady, currentUrl]) + + // 处理关闭提示 + const handleClose = () => { + setVisible(false) + } + + // 跳转到Google小程序 + const openGoogleMinApp = () => { + // 使用openMinappById方法打开Google小程序 + openMinappById('google', true) + // 关闭提示 + setVisible(false) + } + + // 只在需要Google登录时显示提示 + if (!needsGoogleLogin || !visible) return null + + // 使用直接的消息文本 + const message = t('miniwindow.alert.google_login') + + return ( + + {t('common.open')} Google + + } + style={{ zIndex: 10, animation: 'fadeIn 0.3s ease-in-out' }} + /> + ) +} + /** The main container for MinApp popup */ const MinappPopupContainer: React.FC = () => { const { openedKeepAliveMinapps, openedOneOffMinapp, currentMinappId, minappShow } = useRuntime() @@ -198,9 +292,11 @@ const MinappPopupContainer: React.FC = () => { } } - /** the callback function to handle the webview navigate to new url */ + /** the callback function to handle webview navigation */ const handleWebviewNavigate = (appid: string, url: string) => { + // 记录当前URL,用于GoogleLoginTip判断 if (appid === currentMinappId) { + console.log('URL changed:', url) setCurrentUrl(url) } } @@ -297,36 +393,36 @@ const MinappPopupContainer: React.FC = () => { {appInfo.canOpenExternalLink && ( - + )} - + - + - + {appInfo.canPinned && ( - + )} { } mouseEnterDelay={0.8} placement="bottom"> - + {isInDevelopment && ( - + )} {canMinimize && ( - + )} - + @@ -399,6 +495,8 @@ const MinappPopupContainer: React.FC = () => { marginLeft: 'var(--sidebar-width)', backgroundColor: window.root.style.background }}> + {/* 在所有小程序中显示GoogleLoginTip */} + {!isReady && (