Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/app/features/settings/desktop/Desktop.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
});

describe('Desktop', () => {
const renderDesktop = () =>

Check warning on line 70 in src/app/features/settings/desktop/Desktop.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

unicorn(consistent-function-scoping)

Function `renderDesktop` does not capture any variables from its parent scope
render(
<ScreenSizeProvider value={ScreenSize.Desktop}>
<Desktop requestClose={vi.fn<() => void>()} />
Expand All @@ -93,7 +93,7 @@
'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', () => {
Expand Down
25 changes: 25 additions & 0 deletions src/app/features/settings/desktop/Desktop.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;

Expand Down Expand Up @@ -93,6 +96,28 @@ export function Desktop({ requestBack, requestClose }: DesktopProps) {
</SequenceCard>
)}
</Box>
<Box direction="Column" gap="100">
<Text size="L400">Updates</Text>
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
direction="Column"
gap="400"
>
<SettingTile
title="Automatically check for updates"
focusId="auto-update-check"
description="Check GitHub for a new release on launch. Turn off to avoid contacting GitHub."
after={
<Switch
aria-label="auto-update-check"
value={autoUpdateCheck}
onChange={setAutoUpdateCheck}
/>
}
/>
</SequenceCard>
</Box>
</Box>
</PageContent>
</Scroll>
Expand Down
7 changes: 6 additions & 1 deletion src/app/pages/client/DesktopUpdater.tsx
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -37,10 +39,13 @@ async function checkForDesktopUpdate(): Promise<void> {
}

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;
}
13 changes: 13 additions & 0 deletions src/app/state/autoUpdateCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
atomWithLocalStorage,
getLocalStorageItem,
setLocalStorageItem,
} from './utils/atomWithLocalStorage';

const AUTO_UPDATE_CHECK_KEY = 'autoUpdateCheck';

export const autoUpdateCheckAtom = atomWithLocalStorage<boolean>(
AUTO_UPDATE_CHECK_KEY,
(key) => getLocalStorageItem<boolean>(key, true),
(key, value) => setLocalStorageItem(key, value)
);
Loading