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
11 changes: 6 additions & 5 deletions src/web-ui/src/app/components/AboutDialog/AboutDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { createLogger } from '@/shared/utils/logger';
import { systemAPI } from '@/infrastructure/api';
import type { CheckForUpdatesResponse } from '@/infrastructure/api/service-api/SystemAPI';
import { isTauriRuntime } from '@/infrastructure/update/tauriEnv';
import { canCheckForAppUpdates, isTauriRuntime } from '@/infrastructure/update/tauriEnv';
import { UpdateAvailableDialog } from '@/infrastructure/update/UpdateAvailableDialog';
import { useUpdateInstallStore } from '@/infrastructure/update/updateInstallStore';
import { formatUpdateInstallError } from '@/infrastructure/update/updateErrorMessage';
Expand Down Expand Up @@ -51,6 +51,7 @@ export const AboutDialog: React.FC<AboutDialogProps> = ({
const aboutInfo = getAboutInfo();
const { version, license } = aboutInfo;
const nativeRuntime = isTauriRuntime();
const updateChecksAvailable = canCheckForAppUpdates();
const displayedVersion = formatDisplayedVersion(
version,
nativeVersion,
Expand Down Expand Up @@ -85,7 +86,7 @@ export const AboutDialog: React.FC<AboutDialogProps> = ({
}, [isOpen, nativeRuntime]);

const handleCheckForUpdates = useCallback(async () => {
if (!isTauriRuntime()) {
if (!canCheckForAppUpdates()) {
return;
}
setManualCheckStatus('idle');
Expand Down Expand Up @@ -169,7 +170,7 @@ export const AboutDialog: React.FC<AboutDialogProps> = ({

{/* Scrollable area */}
<div className="bitfun-about-dialog__scrollable" data-bf-component="about-dialog" data-bf-part="content">
{nativeRuntime ? (
{updateChecksAvailable ? (
<div
className="bitfun-about-dialog__update-card"
data-bf-component="about-dialog"
Expand Down Expand Up @@ -286,9 +287,9 @@ export const AboutDialog: React.FC<AboutDialogProps> = ({
/>
) : null}
</div>
) : (
) : !nativeRuntime ? (
<p className="bitfun-about-dialog__update-hint">{t('update.desktopOnly')}</p>
)}
) : null}
<div className="bitfun-about-dialog__info-section">
<div className="bitfun-about-dialog__info-card" data-bf-component="about-dialog" data-bf-part="infoCard">
<div className="bitfun-about-dialog__info-row" data-bf-component="about-dialog" data-bf-part="infoRow">
Expand Down
34 changes: 32 additions & 2 deletions src/web-ui/src/infrastructure/api/service-api/SystemAPI.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { SystemAPI } from './SystemAPI';

const invokeMock = vi.hoisted(() => vi.fn());
Expand All @@ -9,14 +9,44 @@ vi.mock('./ApiClient', () => ({
},
}));

describe('SystemAPI sleep prevention', () => {
describe('SystemAPI', () => {
let systemAPI: SystemAPI;

beforeEach(() => {
systemAPI = new SystemAPI();
invokeMock.mockReset();
});

afterEach(() => {
vi.unstubAllEnvs();
});

it('does not invoke the updater in development mode', async () => {
vi.stubEnv('DEV', true);

await expect(systemAPI.checkForUpdates()).rejects.toThrow(
'Update checks are disabled in development mode',
);
expect(invokeMock).not.toHaveBeenCalled();
});

it('invokes the updater outside development mode', async () => {
vi.stubEnv('DEV', false);
const response = {
updateAvailable: false,
currentVersion: '1.0.0',
latestVersion: null,
releaseNotes: null,
releaseDate: null,
};
invokeMock.mockResolvedValueOnce(response);

await expect(systemAPI.checkForUpdates()).resolves.toEqual(response);
expect(invokeMock).toHaveBeenCalledWith('check_for_updates', {
request: {},
});
});

it('reads the persisted desktop preference', async () => {
invokeMock.mockResolvedValueOnce(false);

Expand Down
3 changes: 3 additions & 0 deletions src/web-ui/src/infrastructure/api/service-api/SystemAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export class SystemAPI {


async checkForUpdates(): Promise<CheckForUpdatesResponse> {
if (import.meta.env.DEV) {
throw new Error('Update checks are disabled in development mode');
}
try {
return await api.invoke('check_for_updates', {
request: {}
Expand Down
4 changes: 2 additions & 2 deletions src/web-ui/src/infrastructure/update/DailyAppUpdateGate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { configManager } from '@/infrastructure/config/services/ConfigManager';
import { createLogger } from '@/shared/utils/logger';
import { scheduleAfterStartupSignal } from '@/shared/utils/startupTaskScheduling';
import type { CheckForUpdatesResponse } from '@/infrastructure/api/service-api/SystemAPI';
import { isTauriRuntime } from './tauriEnv';
import { canCheckForAppUpdates, isTauriRuntime } from './tauriEnv';
import {
recordDailyPromptDismissed,
recordSkipThisVersion,
Expand Down Expand Up @@ -32,7 +32,7 @@ export function DailyAppUpdateGate(): ReactElement | null {
const clearUpdateInstalled = useUpdateInstallStore(state => state.clearInstalled);

useEffect(() => {
if (!isTauriRuntime()) {
if (!canCheckForAppUpdates()) {
return;
}
let cancelled = false;
Expand Down
24 changes: 24 additions & 0 deletions src/web-ui/src/infrastructure/update/tauriEnv.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { afterEach, describe, expect, it, vi } from 'vitest';

import { canCheckForAppUpdates } from './tauriEnv';

describe('app update runtime availability', () => {
afterEach(() => {
vi.unstubAllEnvs();
vi.unstubAllGlobals();
});

it('disables update checks in a Tauri development runtime', () => {
vi.stubEnv('DEV', true);
vi.stubGlobal('window', { __TAURI__: {} });

expect(canCheckForAppUpdates()).toBe(false);
});

it('enables update checks in a packaged Tauri runtime', () => {
vi.stubEnv('DEV', false);
vi.stubGlobal('window', { __TAURI__: {} });

expect(canCheckForAppUpdates()).toBe(true);
});
});
5 changes: 5 additions & 0 deletions src/web-ui/src/infrastructure/update/tauriEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
export function isTauriRuntime(): boolean {
return typeof window !== 'undefined' && '__TAURI__' in window;
}

/** App update checks are available only in packaged desktop builds. */
export function canCheckForAppUpdates(): boolean {
return isTauriRuntime() && !import.meta.env.DEV;
}