Enhance app update checks with improved error handling and duplicate installation detection
Some checks reported errors
farmcontrol/farmcontrol-ui/pipeline/head Something is wrong with the build of this commit

- Updated `AppUpdateProvider` to handle errors during startup checks for app updates and duplicate installations, improving robustness.
- Refactored logic to ensure duplicate installation checks are integrated into the update process, providing clearer feedback to users.
- Adjusted modal visibility conditions for duplicate installation prompts to streamline user experience.
This commit is contained in:
Tom Butcher 2026-08-08 20:08:55 +01:00
parent c5d8d9cf70
commit e32eda100a
2 changed files with 24 additions and 8 deletions

View File

@ -308,19 +308,29 @@ export const AppUpdateProvider = ({ children }) => {
let cancelled = false let cancelled = false
const runStartupChecks = async () => { const runStartupChecks = async () => {
let result = null
try { try {
const result = await checkAppUpdateResult?.() result = await checkAppUpdateResult?.()
if (!cancelled && result?.updated) { if (!cancelled && result?.updated) {
setCompletedUpdate(result) setCompletedUpdate(result)
} }
} catch (error) {
console.warn('[AppUpdateContext] Startup update check failed:', error)
}
const installations = await checkDuplicateInstallations?.() try {
const installations =
result?.duplicates || (await checkDuplicateInstallations?.())
if (!cancelled && installations?.duplicatePath) { if (!cancelled && installations?.duplicatePath) {
setDuplicateInstall(installations) setDuplicateInstall(installations)
setDuplicatePromptOpen(true) setDuplicatePromptOpen(true)
} }
} catch (error) { } catch (error) {
console.warn('[AppUpdateContext] Startup update checks failed:', error) console.warn(
'[AppUpdateContext] Duplicate installation check failed:',
error
)
} }
} }
@ -537,9 +547,7 @@ export const AppUpdateProvider = ({ children }) => {
</Modal> </Modal>
<Modal <Modal
title='Duplicate Installation Found' title='Duplicate Installation Found'
open={Boolean( open={Boolean(duplicatePromptOpen && duplicateInstall)}
duplicatePromptOpen && duplicateInstall && !completedUpdate
)}
style={{ maxWidth: 480 }} style={{ maxWidth: 480 }}
centered centered
closable={!removingDuplicate} closable={!removingDuplicate}

View File

@ -7,6 +7,7 @@ import process from "node:process";
import { Utils } from "electrobun/bun"; import { Utils } from "electrobun/bun";
import { launchMacInstaller } from "./macappupdate.js"; import { launchMacInstaller } from "./macappupdate.js";
import { launchWindowsInstaller } from "./winappupdate.js"; import { launchWindowsInstaller } from "./winappupdate.js";
import { checkForDuplicateInstallations } from "./check-duplicate-installations.js";
import { scheduleAppRestart } from "./updater-runner.js"; import { scheduleAppRestart } from "./updater-runner.js";
import { getAppSettings, setAppSettings } from "./store.js"; import { getAppSettings, setAppSettings } from "./store.js";
@ -266,10 +267,17 @@ export const checkForCompletedUpdate = async (mainWindow) => {
normalizeEngine(current.engine), normalizeEngine(current.engine),
)); ));
completedUpdateResult = { updated, previous, current }; const duplicates = checkForDuplicateInstallations();
completedUpdateResult = { updated, previous, current, duplicates };
} catch (error) { } catch (error) {
console.warn("[app-update] Failed to check for a completed update.", error); console.warn("[app-update] Failed to check for a completed update.", error);
completedUpdateResult = { updated: false, previous: null, current: null }; completedUpdateResult = {
updated: false,
previous: null,
current: null,
duplicates: checkForDuplicateInstallations(),
};
} }
return completedUpdateResult; return completedUpdateResult;