From 2ecc62b04ad3a5e5bdc0c637965936ced8c012db Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Sun, 19 Jul 2026 17:59:20 +0200 Subject: [PATCH] feat(desktop): add toggle to disable auto-update checks --- .../settings/desktop/Desktop.test.tsx | 2 +- src/app/features/settings/desktop/Desktop.tsx | 25 +++++++++++++++++++ src/app/pages/client/DesktopUpdater.tsx | 7 +++++- src/app/state/autoUpdateCheck.ts | 13 ++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/app/state/autoUpdateCheck.ts diff --git a/src/app/features/settings/desktop/Desktop.test.tsx b/src/app/features/settings/desktop/Desktop.test.tsx index 6cc6fe763..58c7fa37a 100644 --- a/src/app/features/settings/desktop/Desktop.test.tsx +++ b/src/app/features/settings/desktop/Desktop.test.tsx @@ -93,7 +93,7 @@ describe('Desktop', () => { 'Show a system tray icon while Sable is running. Disable this if you want Sable to stay available without a tray icon.' ) ).toBeInTheDocument(); - expect(container.getElementsByClassName(SequenceCardStyle)).toHaveLength(2); + expect(container.getElementsByClassName(SequenceCardStyle)).toHaveLength(3); }); it('shows fallback copy while the tray icon is enabled but unavailable', () => { diff --git a/src/app/features/settings/desktop/Desktop.tsx b/src/app/features/settings/desktop/Desktop.tsx index 282814b02..a4f40a29f 100644 --- a/src/app/features/settings/desktop/Desktop.tsx +++ b/src/app/features/settings/desktop/Desktop.tsx @@ -1,5 +1,7 @@ import { isTauri } from '@tauri-apps/api/core'; +import { useAtom } from 'jotai'; import { Box, Text, Scroll, Switch, color } from 'folds'; +import { autoUpdateCheckAtom } from '$state/autoUpdateCheck'; import { PageContent } from '$components/page'; import { SequenceCard } from '$components/sequence-card'; import { SettingTile } from '$components/setting-tile'; @@ -26,6 +28,7 @@ export function Desktop({ requestBack, requestClose }: DesktopProps) { 'closeToBackgroundOnClose' ); const [showSystemTrayIcon, setShowSystemTrayIcon] = useDesktopSetting('showSystemTrayIcon'); + const [autoUpdateCheck, setAutoUpdateCheck] = useAtom(autoUpdateCheckAtom); if (!isTauri() || !ready) return null; @@ -93,6 +96,28 @@ export function Desktop({ requestBack, requestClose }: DesktopProps) { )} + + Updates + + + } + /> + + diff --git a/src/app/pages/client/DesktopUpdater.tsx b/src/app/pages/client/DesktopUpdater.tsx index fcaa17adb..88595335b 100644 --- a/src/app/pages/client/DesktopUpdater.tsx +++ b/src/app/pages/client/DesktopUpdater.tsx @@ -1,6 +1,8 @@ import { useEffect } from 'react'; +import { useAtomValue } from 'jotai'; import { isTauri } from '@tauri-apps/api/core'; import { type as osType } from '@tauri-apps/plugin-os'; +import { autoUpdateCheckAtom } from '$state/autoUpdateCheck'; import { createLogger } from '$utils/debug'; const log = createLogger('DesktopUpdater'); @@ -37,10 +39,13 @@ async function checkForDesktopUpdate(): Promise { } export function DesktopUpdater() { + const autoUpdateCheck = useAtomValue(autoUpdateCheckAtom); + useEffect(() => { if (!isDesktopTauri()) return; + if (!autoUpdateCheck) return; checkForDesktopUpdate().catch((err) => log.error('update check failed', err)); - }, []); + }, [autoUpdateCheck]); return null; } diff --git a/src/app/state/autoUpdateCheck.ts b/src/app/state/autoUpdateCheck.ts new file mode 100644 index 000000000..1e6a267d1 --- /dev/null +++ b/src/app/state/autoUpdateCheck.ts @@ -0,0 +1,13 @@ +import { + atomWithLocalStorage, + getLocalStorageItem, + setLocalStorageItem, +} from './utils/atomWithLocalStorage'; + +const AUTO_UPDATE_CHECK_KEY = 'autoUpdateCheck'; + +export const autoUpdateCheckAtom = atomWithLocalStorage( + AUTO_UPDATE_CHECK_KEY, + (key) => getLocalStorageItem(key, true), + (key, value) => setLocalStorageItem(key, value) +);