From 692cc64d15b85f2a8d315bf7fa9d1104d849bea1 Mon Sep 17 00:00:00 2001 From: Wendong-Fan Date: Fri, 21 Nov 2025 02:52:06 +0800 Subject: [PATCH] Revert "fix: login (#739)" This reverts commit e0f867d26e4f306ddf159453c939d13a5241284e, reversing changes made to e3c61a958b159762a8597838c56a6628b2694369. --- electron/preload/index.ts | 1 - src/hooks/useInstallationSetup.ts | 56 +------------------------------ src/pages/Setting/General.tsx | 3 -- src/store/authStore.ts | 3 +- src/types/electron.d.ts | 12 +++---- 5 files changed, 7 insertions(+), 68 deletions(-) diff --git a/electron/preload/index.ts b/electron/preload/index.ts index 0ef7933a5..7ef37abf1 100644 --- a/electron/preload/index.ts +++ b/electron/preload/index.ts @@ -69,7 +69,6 @@ contextBridge.exposeInMainWorld('electronAPI', { checkInstallBrowser: () => ipcRenderer.invoke('check-install-browser'), getInstallationStatus: () => ipcRenderer.invoke('get-installation-status'), restartBackend: () => ipcRenderer.invoke('restart-backend'), - getBackendPort: () => ipcRenderer.invoke('get-backend-port'), onInstallDependenciesStart: (callback: () => void) => { ipcRenderer.on('install-dependencies-start', callback); }, diff --git a/src/hooks/useInstallationSetup.ts b/src/hooks/useInstallationSetup.ts index 28f9945bc..b7bca2e3e 100644 --- a/src/hooks/useInstallationSetup.ts +++ b/src/hooks/useInstallationSetup.ts @@ -7,12 +7,11 @@ import { useAuthStore } from '@/store/authStore'; * This should be called once in your App component or Layout component */ export const useInstallationSetup = () => { - const { initState, setInitState, email } = useAuthStore(); + const { initState, setInitState } = useAuthStore(); const hasCheckedOnMount = useRef(false); const installationCompleted = useRef(false); const backendReady = useRef(false); - const previousEmail = useRef(null); const startInstallation = useInstallationStore(state => state.startInstallation); const performInstallation = useInstallationStore(state => state.performInstallation); const addLog = useInstallationStore(state => state.addLog); @@ -21,59 +20,6 @@ export const useInstallationSetup = () => { const setBackendError = useInstallationStore(state => state.setBackendError); const setWaitingBackend = useInstallationStore(state => state.setWaitingBackend); - // Monitor email changes to detect account switching - useEffect(() => { - // Detect new login: email changed from null/different to a new value - if (previousEmail.current !== email && email !== null) { - console.log('[useInstallationSetup] Account switch detected:', previousEmail.current, '->', email); - - // For account switching, tools are already installed, only backend needs restart - // So we mark installation as completed and only wait for backend - installationCompleted.current = true; - backendReady.current = false; - - // Set to waiting-backend state since backend is restarting - if (initState === 'carousel') { - console.log('[useInstallationSetup] New account login detected, waiting for backend restart'); - setWaitingBackend(); - - // Poll backend status every 2 seconds to ensure we catch when it's ready - // This is a fallback in case the backend-ready event is missed - const pollInterval = setInterval(async () => { - try { - const backendPort = await window.electronAPI.getBackendPort(); - if (backendPort && backendPort > 0) { - console.log('[useInstallationSetup] Backend poll detected ready on port:', backendPort); - - // Verify backend is actually responding - const response = await fetch(`http://localhost:${backendPort}/health`).catch(() => null); - if (response && response.ok) { - console.log('[useInstallationSetup] Backend health check passed'); - clearInterval(pollInterval); - - if (!backendReady.current) { - backendReady.current = true; - setSuccess(); - setInitState('done'); - } - } - } - } catch (error) { - console.log('[useInstallationSetup] Backend poll check failed:', error); - } - }, 2000); - - // Clear polling after 30 seconds to prevent infinite polling - setTimeout(() => { - clearInterval(pollInterval); - }, 30000); - } - } - - // Update previous email - previousEmail.current = email; - }, [email, initState, setWaitingBackend, setSuccess, setInitState]); - useEffect(() => { if (hasCheckedOnMount.current) { return; diff --git a/src/pages/Setting/General.tsx b/src/pages/Setting/General.tsx index 5c3236f53..85fc89477 100644 --- a/src/pages/Setting/General.tsx +++ b/src/pages/Setting/General.tsx @@ -6,7 +6,6 @@ import light from "@/assets/light.png"; import dark from "@/assets/dark.png"; import transparent from "@/assets/transparent.png"; import { useAuthStore } from "@/store/authStore"; -import { useInstallationStore } from "@/store/installationStore"; import { useNavigate } from "react-router-dom"; import { proxyFetchPut, proxyFetchGet } from "@/api/http"; import { createRef, RefObject } from "react"; @@ -30,7 +29,6 @@ import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; export default function SettingGeneral() { const { t } = useTranslation(); const authStore = useAuthStore(); - const resetInstallation = useInstallationStore(state => state.reset); const navigate = useNavigate(); const [isLoading, setIsLoading] = useState(false); const setAppearance = authStore.setAppearance; @@ -161,7 +159,6 @@ export default function SettingGeneral() { size="xs" onClick={() => { chatStore.clearTasks(); - resetInstallation(); // Reset installation state for new account authStore.logout(); navigate("/login"); }} diff --git a/src/store/authStore.ts b/src/store/authStore.ts index 7024a2a7f..aa7d3ff57 100644 --- a/src/store/authStore.ts +++ b/src/store/authStore.ts @@ -80,8 +80,7 @@ const authStore = create()( token: null, username: null, email: null, - user_id: null, - initState: 'carousel' // Reset to carousel state to wait for backend restart + user_id: null }), // set related methods diff --git a/src/types/electron.d.ts b/src/types/electron.d.ts index 78e1870a7..116a06a8f 100644 --- a/src/types/electron.d.ts +++ b/src/types/electron.d.ts @@ -56,16 +56,14 @@ interface ElectronAPI { error?: string }>; restartBackend: () => Promise<{ success: boolean; error?: string }>; - getBackendPort: () => Promise; onInstallDependenciesStart: (callback: () => void) => void; onInstallDependenciesLog: (callback: (data: { type: string; data: string }) => void) => void; onInstallDependenciesComplete: (callback: (data: { success: boolean; code?: number; error?: string }) => void) => void; - onBackendReady: (callback: (data: { success: boolean; port?: number; error?: string }) => void) => void; - onUpdateNotification: (callback: (data: { - type: string; - currentVersion: string; - previousVersion: string; - reason: string; + onUpdateNotification: (callback: (data: { + type: string; + currentVersion: string; + previousVersion: string; + reason: string; }) => void) => void; removeAllListeners: (channel: string) => void; getEmailFolderPath: (email: string) => Promise<{