From 7480dec8ebdd6d5b59a259685a0617dfa6524e7f Mon Sep 17 00:00:00 2001 From: Wendong-Fan Date: Fri, 10 Oct 2025 00:23:04 +0800 Subject: [PATCH] fix: install when the task is running --- src/hooks/useInstallationSetup.ts | 38 +++++++++++++++++++------------ 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/hooks/useInstallationSetup.ts b/src/hooks/useInstallationSetup.ts index 16e19275d..7c4e1b7a7 100644 --- a/src/hooks/useInstallationSetup.ts +++ b/src/hooks/useInstallationSetup.ts @@ -1,4 +1,4 @@ -import { useEffect } from 'react'; +import { useEffect, useRef } from 'react'; import { useInstallationStore } from '@/store/installationStore'; import { useAuthStore } from '@/store/authStore'; @@ -8,15 +8,25 @@ import { useAuthStore } from '@/store/authStore'; */ export const useInstallationSetup = () => { const { initState, setInitState } = useAuthStore(); - + + // Use ref to track if initial check is done to prevent repeated checks + const hasCheckedOnMount = useRef(false); + // Extract only the functions we need to avoid dependency issues const startInstallation = useInstallationStore(state => state.startInstallation); const addLog = useInstallationStore(state => state.addLog); const setSuccess = useInstallationStore(state => state.setSuccess); const setError = useInstallationStore(state => state.setError); - // Check tool installation status on mount + // Check tool installation status on mount - but only during setup phase useEffect(() => { + // Only run this check once on initial mount + if (hasCheckedOnMount.current) { + return; + } + + hasCheckedOnMount.current = true; + const checkToolInstalled = async () => { try { console.log('[useInstallationSetup] Checking tool installation status...'); @@ -24,16 +34,15 @@ export const useInstallationSetup = () => { console.log('[useInstallationSetup] Tool check result:', result, 'initState:', initState); - // If tools are NOT installed and we're in done state, go back to carousel - if (result.success && initState === "done" && !result.isInstalled) { - console.log('[useInstallationSetup] Tool not installed, setting initState to carousel'); - setInitState("carousel"); - } - - // If tools ARE installed and we're in carousel state, go to done - if (result.success && initState === "carousel" && result.isInstalled) { - console.log('[useInstallationSetup] Tools installed but initState is carousel, setting to done'); - setInitState("done"); + // 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 + if (initState !== 'done') { + // If tools ARE installed and we're in carousel state, go to done + if (result.success && initState === "carousel" && result.isInstalled) { + console.log('[useInstallationSetup] Tools installed but initState is carousel, setting to done'); + setInitState("done"); + } } } catch (error) { console.error("[useInstallationSetup] Tool installation check failed:", error); @@ -57,7 +66,8 @@ export const useInstallationSetup = () => { checkToolInstalled(); checkBackendStatus(); - }, [initState, setInitState, startInstallation]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); // Setup Electron IPC listeners (only once) useEffect(() => {