Skip to content
Open
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
15 changes: 12 additions & 3 deletions src/app/pages/client/DesktopUpdater.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { useAtomValue, useSetAtom, Provider } from 'jotai';
import { globalBannersAtom } from '$state/globalBanners';
import { triggerUpdateCheckAtom } from '$state/desktopUpdate';
import { triggerUpdateCheckAtom, updatePhaseAtom } from '$state/desktopUpdate';
import { DesktopUpdatePill } from '$components/tauri/DesktopUpdatePill';
import { DesktopUpdater } from './DesktopUpdater';

Expand Down Expand Up @@ -32,6 +32,7 @@ function BannersProbe() {
{banners.map((b) => (
<section key={b.id} data-testid={`banner-${b.id}`}>
<span>{b.title}</span>
<span>{b.description}</span>
<button type="button" onClick={b.primaryAction.onClick}>
{b.primaryAction.label}
</button>
Expand All @@ -55,6 +56,11 @@ function CheckNowButton() {
);
}

function UpdatePhaseProbe() {
const phase = useAtomValue(updatePhaseAtom);
return <output data-testid="update-phase">{phase.type}</output>;
}

function makeUpdate(version: string) {
return {
version,
Expand Down Expand Up @@ -166,6 +172,7 @@ describe('DesktopUpdater', () => {
<DesktopUpdatePill />
<DesktopUpdater />
<BannersProbe />
<UpdatePhaseProbe />
</Provider>
);

Expand All @@ -176,10 +183,12 @@ describe('DesktopUpdater', () => {
fireEvent.click(screen.getByRole('button', { name: 'Download & Install' }));
await waitFor(() => expect(update.downloadAndInstall).toHaveBeenCalledTimes(1));
await waitFor(() => {
expect(screen.getByRole('button', { name: 'Download & Install' })).toBeInTheDocument();
expect(screen.getByText('Update Failed')).toBeInTheDocument();
});
expect(screen.getByText('eacces')).toBeInTheDocument();
expect(screen.getByTestId('update-phase')).toHaveTextContent('ready');

fireEvent.click(screen.getByRole('button', { name: 'Download & Install' }));
fireEvent.click(screen.getByRole('button', { name: 'Retry' }));
await waitFor(() => expect(update.downloadAndInstall).toHaveBeenCalledTimes(2));
await screen.findByTestId('banner-desktop-update-restart');
});
Expand Down
25 changes: 25 additions & 0 deletions src/app/pages/client/DesktopUpdater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function DesktopUpdater() {
const [isDownloading, setIsDownloading] = useState(false);
const [isInstalled, setIsInstalled] = useState(false);
const [isInstalling, setIsInstalling] = useState(false);
const [installError, setInstallError] = useState<string | null>(null);
const [dismissed, setDismissed] = useState(false);
const [useCustomTitleBar] = useDesktopSetting('useCustomTitleBar');
const hasUpdateRef = useRef(false);
Expand Down Expand Up @@ -145,6 +146,7 @@ export function DesktopUpdater() {
if (!updateInfo || installStartedRef.current) return;
installStartedRef.current = true;
try {
setInstallError(null);
setIsDownloading(true);
setPhase({ type: 'downloading', progress: 0 });

Expand Down Expand Up @@ -180,8 +182,10 @@ export function DesktopUpdater() {
closePendingUpdate(updateInfo);
} catch (err) {
log.error('Failed to install update', err);
setInstallError(err instanceof Error ? err.message : String(err));
setIsDownloading(false);
setIsInstalling(false);
setPhase({ type: 'ready', version: updateInfo.version });
installStartedRef.current = false;
}
}, [closePendingUpdate, updateInfo, setPhase]);
Expand Down Expand Up @@ -223,6 +227,26 @@ export function DesktopUpdater() {
};
}

if (installError) {
return {
id: 'desktop-update-ready',
priority: 200,
icon: ArrowUp,
title: 'Update Failed',
description: installError,
primaryAction: {
label: 'Retry',
variant: 'Primary',
onClick: handleInstall,
},
secondaryAction: {
label: 'Later',
variant: 'Secondary',
onClick: handleDismiss,
},
};
}

return {
id: 'desktop-update-ready',
priority: 200,
Expand Down Expand Up @@ -251,6 +275,7 @@ export function DesktopUpdater() {
isDownloading,
isInstalled,
isInstalling,
installError,
handleInstall,
handleRestart,
handleDismiss,
Expand Down
Loading