From d6a4e0966d8051f05bb9041d6ea0c1db92f99109 Mon Sep 17 00:00:00 2001 From: Sun Tao <2605127667@qq.com> Date: Thu, 20 Nov 2025 00:40:07 +0800 Subject: [PATCH 1/2] Update useInstallationSetup.ts --- src/hooks/useInstallationSetup.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/hooks/useInstallationSetup.ts b/src/hooks/useInstallationSetup.ts index 228c7073..01882823 100644 --- a/src/hooks/useInstallationSetup.ts +++ b/src/hooks/useInstallationSetup.ts @@ -14,6 +14,7 @@ export const useInstallationSetup = () => { // Extract only the functions we need to avoid dependency issues const startInstallation = useInstallationStore(state => state.startInstallation); + const performInstallation = useInstallationStore(state => state.performInstallation); const addLog = useInstallationStore(state => state.addLog); const setSuccess = useInstallationStore(state => state.setSuccess); const setError = useInstallationStore(state => state.setError); @@ -60,6 +61,13 @@ export const useInstallationSetup = () => { if (installationStatus.success && installationStatus.isInstalling) { startInstallation(); + } else if (initState !== 'done') { + // If not installing and not done, check if we need to install + const toolResult = await window.ipcRenderer.invoke("check-tool-installed"); + if (toolResult.success && !toolResult.isInstalled) { + console.log('[useInstallationSetup] Tools missing and not installing. Starting installation...'); + performInstallation(); + } } } catch (err) { console.error('[useInstallationSetup] Failed to check installation status:', err); From a596cc7460befbc82f162d06c7b853228323b67a Mon Sep 17 00:00:00 2001 From: Wendong-Fan Date: Thu, 20 Nov 2025 13:33:10 +0800 Subject: [PATCH 2/2] update wendong --- src/hooks/useInstallationSetup.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/hooks/useInstallationSetup.ts b/src/hooks/useInstallationSetup.ts index 01882823..dbac234e 100644 --- a/src/hooks/useInstallationSetup.ts +++ b/src/hooks/useInstallationSetup.ts @@ -32,7 +32,6 @@ export const useInstallationSetup = () => { try { const result = await window.ipcRenderer.invoke("check-tool-installed"); - // Only perform tool check during setup phase (permissions or carousel) // Once user is in 'done' state (main app), don't check again // This prevents unexpected navigation away from the main app @@ -49,24 +48,29 @@ export const useInstallationSetup = () => { } } } + return result; } catch (error) { console.error("[useInstallationSetup] Tool installation check failed:", error); + return { success: false, error }; } }; - const checkBackendStatus = async() => { + const checkBackendStatus = async(toolResult?: any) => { try { // Also check if installation is currently in progress const installationStatus = await window.electronAPI.getInstallationStatus(); if (installationStatus.success && installationStatus.isInstalling) { startInstallation(); - } else if (initState !== 'done') { - // If not installing and not done, check if we need to install - const toolResult = await window.ipcRenderer.invoke("check-tool-installed"); + } else if (initState !== 'done' && toolResult) { + // Use the tool result from the previous check to avoid duplicate API calls if (toolResult.success && !toolResult.isInstalled) { console.log('[useInstallationSetup] Tools missing and not installing. Starting installation...'); - performInstallation(); + try { + await performInstallation(); + } catch (installError) { + console.error('[useInstallationSetup] Installation failed:', installError); + } } } } catch (err) { @@ -74,8 +78,13 @@ export const useInstallationSetup = () => { } } - checkToolInstalled(); - checkBackendStatus(); + // Run checks sequentially to avoid race conditions and duplicate API calls + const runInitialChecks = async () => { + const toolResult = await checkToolInstalled(); + await checkBackendStatus(toolResult); + }; + + runInitialChecks(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []);