From e927ac950681665b35094871f6d005e91868f9a4 Mon Sep 17 00:00:00 2001 From: Draculabo Date: Wed, 21 Jan 2026 00:37:42 +0800 Subject: [PATCH] feat: verify Google OAuth code automatically after receipt --- src/components/CloudAccountList.tsx | 62 ++++++++++++++++------------- src/ipc/cloud/authServer.ts | 4 +- src/ipc/process/handler.ts | 2 - 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/components/CloudAccountList.tsx b/src/components/CloudAccountList.tsx index 5683970..454ed67 100644 --- a/src/components/CloudAccountList.tsx +++ b/src/components/CloudAccountList.tsx @@ -62,19 +62,49 @@ export function CloudAccountList() { const [isAddDialogOpen, setIsAddDialogOpen] = useState(false); const [authCode, setAuthCode] = useState(''); + const handleAddAccount = (codeVal?: string) => { + const codeToUse = codeVal || authCode; + if (!codeToUse) { + return; + } + addMutation.mutate( + { authCode: codeToUse }, + { + onSuccess: () => { + setIsAddDialogOpen(false); + setAuthCode(''); + toast({ title: t('cloud.toast.addSuccess') }); + }, + onError: (err) => { + toast({ + title: t('cloud.toast.addFailed.title'), + description: err.message, + variant: 'destructive', + }); + }, + }, + ); + }; // Listen for Google Auth Code useEffect(() => { if (window.electron?.onGoogleAuthCode) { + console.log('[OAuth] Setting up auth code listener, dialog open:', isAddDialogOpen); const cleanup = window.electron.onGoogleAuthCode((code) => { + console.log('[OAuth] Received auth code via IPC:', code?.substring(0, 10) + '...'); setAuthCode(code); - // Auto submit if dialog is open - if (isAddDialogOpen) { - handleAddAccount(code); - } + // Note: Auto-submit will be triggered by the authCode change effect below }); return cleanup; } - }, [isAddDialogOpen]); + }, []); + + // Auto-submit when authCode is set and dialog is open + useEffect(() => { + if (authCode && isAddDialogOpen && !addMutation.isPending) { + console.log('[OAuth] Auto-submitting auth code'); + handleAddAccount(authCode); + } + }, [authCode, isAddDialogOpen]); // Batch Operations State const [selectedIds, setSelectedIds] = useState>(new Set()); @@ -176,28 +206,6 @@ export function CloudAccountList() { }); }; - const handleAddAccount = (codeVal?: string) => { - const codeToUse = codeVal || authCode; - if (!codeToUse) return; - addMutation.mutate( - { authCode: codeToUse }, - { - onSuccess: () => { - setIsAddDialogOpen(false); - setAuthCode(''); - toast({ title: t('cloud.toast.addSuccess') }); - }, - onError: (err) => { - toast({ - title: t('cloud.toast.addFailed.title'), - description: err.message, - variant: 'destructive', - }); - }, - }, - ); - }; - const openAuthUrl = async () => { try { await startAuthFlow(); diff --git a/src/ipc/cloud/authServer.ts b/src/ipc/cloud/authServer.ts index 61861e4..ad22ff6 100644 --- a/src/ipc/cloud/authServer.ts +++ b/src/ipc/cloud/authServer.ts @@ -20,11 +20,13 @@ export class AuthServer { const error = url.searchParams.get('error'); if (code) { - logger.info('AuthServer: Received authorization code'); + logger.info(`AuthServer: Received authorization code: ${code.substring(0, 10)}...`); // Send code to renderer if (ipcContext.mainWindow) { + logger.info('AuthServer: Sending code to renderer via IPC'); ipcContext.mainWindow.webContents.send('GOOGLE_AUTH_CODE', code); + logger.info('AuthServer: Code sent successfully'); } else { logger.error('AuthServer: Main window not found, cannot send code'); } diff --git a/src/ipc/process/handler.ts b/src/ipc/process/handler.ts index 7697c0b..3e1a49a 100644 --- a/src/ipc/process/handler.ts +++ b/src/ipc/process/handler.ts @@ -32,8 +32,6 @@ export async function isProcessRunning(): Promise { // Increased timeout to 4000ms to avoid flakiness with tasklist/wmic try { const { stdout } = await execAsync(command, { timeout: 4000 }); - logger.debug(`Process check stdout: ${stdout.trim()}`); - if (platform === 'win32' || isWsl()) { return stdout.includes('Antigravity.exe'); } else {