feat: in-app update checker + Spinner import for General settings
- Add useTauriUpdater hook (check_for_update / install_update commands) - Add AppUpdates section to General settings (Tauri-only, hidden on web) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
|
||||
type TauriInternals = { invoke: (cmd: string, args?: Record<string, unknown>) => Promise<unknown> };
|
||||
const tauriInvoke = (): TauriInternals['invoke'] | undefined =>
|
||||
(window as unknown as { __TAURI_INTERNALS__?: TauriInternals }).__TAURI_INTERNALS__?.invoke;
|
||||
|
||||
type UpdateStatus =
|
||||
| { state: 'idle' }
|
||||
| { state: 'checking' }
|
||||
| { state: 'up-to-date' }
|
||||
| { state: 'available'; version: string }
|
||||
| { state: 'installing' }
|
||||
| { state: 'error'; message: string };
|
||||
|
||||
export function useTauriUpdater() {
|
||||
const isTauri = !!tauriInvoke();
|
||||
const [status, setStatus] = useState<UpdateStatus>({ state: 'idle' });
|
||||
|
||||
const check = useCallback(async () => {
|
||||
const invoke = tauriInvoke();
|
||||
if (!invoke) return;
|
||||
setStatus({ state: 'checking' });
|
||||
try {
|
||||
const result = (await invoke('check_for_update')) as { available: boolean; version?: string };
|
||||
setStatus(
|
||||
result.available && result.version
|
||||
? { state: 'available', version: result.version }
|
||||
: { state: 'up-to-date' },
|
||||
);
|
||||
} catch (e) {
|
||||
setStatus({ state: 'error', message: String(e) });
|
||||
}
|
||||
}, []);
|
||||
|
||||
const install = useCallback(async () => {
|
||||
const invoke = tauriInvoke();
|
||||
if (!invoke) return;
|
||||
setStatus({ state: 'installing' });
|
||||
try {
|
||||
await invoke('install_update');
|
||||
} catch (e) {
|
||||
setStatus({ state: 'error', message: String(e) });
|
||||
}
|
||||
}, []);
|
||||
|
||||
return { isTauri, status, check, install };
|
||||
}
|
||||
Reference in New Issue
Block a user