Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/hooks/useInstallationSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -31,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
Expand All @@ -48,26 +48,43 @@ 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' && 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...');
try {
await performInstallation();
} catch (installError) {
console.error('[useInstallationSetup] Installation failed:', installError);
}
}
}
} catch (err) {
console.error('[useInstallationSetup] Failed to check installation status:', err);
}
}

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
}, []);

Expand Down