fix(desktop): remember the manual update-check result across Settings open/close
CI / Build & Quality Checks (push) Successful in 1m53s
CI / Docker image build & smoke test (push) Skipped
CI / Secret scan (gitleaks) (push) Successful in 6s
CI / Trigger Desktop Build (push) Successful in 6s
CI / Playwright smoke (e2e) (push) Successful in 1m46s
CI / Build & Quality Checks (push) Successful in 1m53s
CI / Docker image build & smoke test (push) Skipped
CI / Secret scan (gitleaks) (push) Successful in 6s
CI / Trigger Desktop Build (push) Successful in 6s
CI / Playwright smoke (e2e) (push) Successful in 1m46s
The status was component state in the settings tab, so closing Settings threw away "update available" and forced another check. Move it to a module-level atom shared by the settings panel and the update toast. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { useState, useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
import { atom, useAtom } from 'jotai';
|
||||||
|
|
||||||
type TauriInternals = { invoke: (cmd: string, args?: Record<string, unknown>) => Promise<unknown> };
|
type TauriInternals = { invoke: (cmd: string, args?: Record<string, unknown>) => Promise<unknown> };
|
||||||
const tauriInvoke = (): TauriInternals['invoke'] | undefined =>
|
const tauriInvoke = (): TauriInternals['invoke'] | undefined =>
|
||||||
@@ -12,9 +13,16 @@ type UpdateStatus =
|
|||||||
| { state: 'installing' }
|
| { state: 'installing' }
|
||||||
| { state: 'error'; message: string };
|
| { state: 'error'; message: string };
|
||||||
|
|
||||||
|
// Module-level so the result of a manual "Check for updates" survives closing
|
||||||
|
// and reopening Settings (it used to be component state, so the "update
|
||||||
|
// available" answer was thrown away with the tab and had to be re-checked).
|
||||||
|
// A transient 'checking'/'installing' state is reset if the tab unmounts
|
||||||
|
// mid-request by the resolve/reject below, so nothing gets stuck.
|
||||||
|
const updateStatusAtom = atom<UpdateStatus>({ state: 'idle' });
|
||||||
|
|
||||||
export function useTauriUpdater() {
|
export function useTauriUpdater() {
|
||||||
const isTauri = !!tauriInvoke();
|
const isTauri = !!tauriInvoke();
|
||||||
const [status, setStatus] = useState<UpdateStatus>({ state: 'idle' });
|
const [status, setStatus] = useAtom(updateStatusAtom);
|
||||||
|
|
||||||
const check = useCallback(async () => {
|
const check = useCallback(async () => {
|
||||||
const invoke = tauriInvoke();
|
const invoke = tauriInvoke();
|
||||||
@@ -30,7 +38,7 @@ export function useTauriUpdater() {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
setStatus({ state: 'error', message: String(e) });
|
setStatus({ state: 'error', message: String(e) });
|
||||||
}
|
}
|
||||||
}, []);
|
}, [setStatus]);
|
||||||
|
|
||||||
const install = useCallback(async () => {
|
const install = useCallback(async () => {
|
||||||
const invoke = tauriInvoke();
|
const invoke = tauriInvoke();
|
||||||
@@ -45,7 +53,7 @@ export function useTauriUpdater() {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
setStatus({ state: 'error', message: String(e) });
|
setStatus({ state: 'error', message: String(e) });
|
||||||
}
|
}
|
||||||
}, []);
|
}, [setStatus]);
|
||||||
|
|
||||||
return { isTauri, status, check, install };
|
return { isTauri, status, check, install };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user