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
3 changes: 3 additions & 0 deletions scripts/tauri.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ async function main() {
logger.info('Building without the auto-updater (--no-updater)');
}

// The frontend is built before Cargo, so mirror the updater feature into Vite.
process.env.VITE_DESKTOP_UPDATER_ENABLED = String(!noUpdater);

const features = noUpdater ? platform : `${platform},updater`;
const args = [cmd, '--features', features, ...tauriArgs];
if (!tauriArgs.includes('--')) {
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/tauri/DesktopUpdatePill.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useAtom, useAtomValue } from 'jotai';
import { hasCustomDesktopTitlebar } from '$utils/tauriTitlebar';
import { isDesktopUpdaterEnabled } from '$utils/platform';
import { useDesktopSetting } from '$state/hooks/desktopSettings';
import { updatePhaseAtom, updateBannerVisibleAtom } from '$state/desktopUpdate';
import type { UpdatePhase } from '$state/desktopUpdate';
Expand All @@ -24,7 +25,7 @@ export function DesktopUpdatePill() {
const [useCustomTitleBar] = useDesktopSetting('useCustomTitleBar');
const status = !bannerVisible ? phaseToStatusView(phase) : null;

if (!hasCustomDesktopTitlebar(useCustomTitleBar)) return null;
if (!isDesktopUpdaterEnabled() || !hasCustomDesktopTitlebar(useCustomTitleBar)) return null;

return (
<SyncConnectionStatusTitlebar
Expand Down
4 changes: 2 additions & 2 deletions src/app/features/settings/about/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useMatrixClient } from '$hooks/useMatrixClient';
import { Method } from '$types/matrix-sdk';
import { useOpenShallowRoute } from '$pages/client/useShallowRoute';
import { getBugReportPath } from '$pages/pathUtils';
import { isDesktopTauri } from '$utils/platform';
import { isDesktopTauri, isDesktopUpdaterEnabled } from '$utils/platform';
import {
updatePhaseAtom,
updateBannerVisibleAtom,
Expand Down Expand Up @@ -299,7 +299,7 @@ export function About({ requestBack, requestClose }: Readonly<AboutProps>) {
</Box>
<Box direction="Column" gap="100">
<Text size="L400">Options</Text>
{isDesktopTauri() && (
{isDesktopTauri() && isDesktopUpdaterEnabled() && (
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
Expand Down
25 changes: 23 additions & 2 deletions src/app/pages/client/DesktopUpdater.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import { DesktopUpdatePill } from '$components/tauri/DesktopUpdatePill';
import { getDebugLogger } from '$utils/debugLogger';
import { DesktopUpdater } from './DesktopUpdater';

const { checkFn } = vi.hoisted(() => ({ checkFn: vi.fn<() => Promise<unknown>>() }));
const { checkFn, updaterEnabled } = vi.hoisted(() => ({
checkFn: vi.fn<() => Promise<unknown>>(),
updaterEnabled: vi.fn<() => boolean>(),
}));

vi.mock('@tauri-apps/plugin-updater', () => ({ check: checkFn }));

vi.mock('$utils/platform', async (importOriginal) => {
const mod = (await importOriginal()) as Record<string, unknown>;
return { ...mod, isDesktopTauri: () => true };
return { ...mod, isDesktopTauri: () => true, isDesktopUpdaterEnabled: updaterEnabled };
});

vi.mock('$state/hooks/desktopSettings', async (importOriginal) => ({
Expand Down Expand Up @@ -73,13 +76,31 @@ function makeUpdate(version: string) {

beforeEach(() => {
localStorage.clear();
updaterEnabled.mockReturnValue(true);
});

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

describe('DesktopUpdater', () => {
it('does not check for or display updates when the updater is disabled at build time', async () => {
updaterEnabled.mockReturnValue(false);
localStorage.setItem('sable_fake_desktop_update', '1');

render(
<Provider>
<DesktopUpdatePill />
<DesktopUpdater />
<BannersProbe />
</Provider>
);

await waitFor(() => expect(checkFn).not.toHaveBeenCalled());
expect(screen.queryByRole('button', { name: 'Update Available' })).not.toBeInTheDocument();
expect(screen.queryByTestId('banner-desktop-update-ready')).not.toBeInTheDocument();
});

it('reopens the update banner from the pill after dismissing it', async () => {
localStorage.setItem('sable_fake_desktop_update', '1');

Expand Down
4 changes: 3 additions & 1 deletion src/app/pages/client/DesktopUpdater.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import type { Update } from '@tauri-apps/plugin-updater';
import { isDesktopTauri } from '$utils/platform';
import { isDesktopTauri, isDesktopUpdaterEnabled } from '$utils/platform';
import { autoUpdateCheckAtom } from '$state/autoUpdateCheck';
import { createLogger } from '$utils/debug';
import { getDebugLogger } from '$utils/debugLogger';
Expand Down Expand Up @@ -61,6 +61,7 @@ export function DesktopUpdater() {
}, []);

useEffect(() => {
if (!isDesktopUpdaterEnabled()) return undefined;
if (!isDesktopTauri()) return undefined;
if (triggerCount === 0 && !autoUpdateCheck && !fakeDesktopUpdate()) return undefined;

Expand Down Expand Up @@ -223,6 +224,7 @@ export function DesktopUpdater() {
}, [setBannerVisible]);

const bannerData = useMemo<GlobalBanner | null>(() => {
if (!isDesktopUpdaterEnabled()) return null;
if (!bannerVisible || !updateInfo || dismissed) return null;

if (isInstalled) {
Expand Down
4 changes: 4 additions & 0 deletions src/app/utils/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export function isDesktopTauri(): boolean {
return getDesktopTauriPlatform() !== undefined;
}

export function isDesktopUpdaterEnabled(): boolean {
return DESKTOP_UPDATER_ENABLED;
}

export function isMobileTauri(): boolean {
const tauriOS = getTauriOS();
return tauriOS === 'ios' || tauriOS === 'android';
Expand Down
1 change: 1 addition & 0 deletions src/ext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ declare const SABLE_BUILD_FLAVOR: string;
declare const APP_VERSION: string;
declare const BUILD_HASH: string;
declare const IS_RELEASE_TAG: boolean;
declare const DESKTOP_UPDATER_ENABLED: boolean;

declare module 'browser-encrypt-attachment' {
export interface EncryptedAttachmentInfo {
Expand Down
2 changes: 2 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const tauriDevHost = process.env.TAURI_DEV_HOST;
const isTauriBuild = Boolean(process.env.TAURI_ENV_PLATFORM);
const isTauriDebug = process.env.TAURI_ENV_DEBUG === 'true';
const tauriBuildMinify = !isTauriDebug ? 'esbuild' : false;
const desktopUpdaterEnabled = process.env.VITE_DESKTOP_UPDATER_ENABLED !== 'false';
const sentryUploadEnabled = Boolean(
process.env.SENTRY_AUTH_TOKEN && process.env.SENTRY_ORG && process.env.SENTRY_PROJECT
);
Expand Down Expand Up @@ -151,6 +152,7 @@ export default defineConfig(({ command }) => {
IS_RELEASE_TAG: JSON.stringify(isReleaseTag),
SABLE_PRODUCT_NAME: JSON.stringify(baseProductName),
SABLE_BUILD_FLAVOR: JSON.stringify(buildFlavor),
DESKTOP_UPDATER_ENABLED: JSON.stringify(desktopUpdaterEnabled),
},
resolve: {
alias: {
Expand Down
Loading