fix: show desktop update errors (#1601)

<!-- Please read
https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before
submitting your pull request -->

### Description

<!-- Please include a summary of the change. Please also include
relevant motivation and context. List any dependencies that are required
for this change. -->

Fixes #

#### Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

### Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings

### AI disclosure:

- [ ] Partially AI assisted (clarify which code was AI assisted and
briefly explain what it does).
- [ ] Fully AI generated (explain what all the generated code does in
moderate detail).
<!-- Write any explanation required here, but do not generate the
explanation using AI!! You must prove you understand what the code in
this PR does. -->
This commit is contained in:
7w1 authored and GitHub committed 2026-08-07 19:53:17 +00:00
commit a755d8f14a
2 files changed
+50 -10

No files matched your search

+12 -3
View File
@@ -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 { getDebugLogger } from '$utils/debugLogger';
import { DesktopUpdater } from './DesktopUpdater';
@@ -33,6 +33,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>
@@ -56,6 +57,11 @@ function CheckNowButton() {
);
}
function UpdatePhaseProbe() {
const phase = useAtomValue(updatePhaseAtom);
return <output data-testid="update-phase">{phase.type}</output>;
}
function makeUpdate(version: string) {
return {
version,
@@ -168,6 +174,7 @@ describe('DesktopUpdater', () => {
<DesktopUpdatePill />
<DesktopUpdater />
<BannersProbe />
<UpdatePhaseProbe />
</Provider>
);
@@ -178,7 +185,7 @@ 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(debugLog).toHaveBeenCalledWith(
'error',
@@ -186,8 +193,10 @@ describe('DesktopUpdater', () => {
'DesktopUpdater',
'Failed to install update: permission denied'
);
expect(screen.getByText('permission denied')).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');
});
+38 -7
View File
@@ -20,15 +20,21 @@ import {
const log = createLogger('DesktopUpdater');
const UPDATE_POLL_INTERVAL_MS = 300_000; // 5 minutes
const getUpdaterErrorMessage = (error: unknown): string =>
error instanceof Error
? error.message
: typeof error === 'object' && error !== null && 'message' in error
? String(error.message)
: String(error);
const logUpdaterError = (message: string, error: unknown): void => {
log.error(message, error);
const detail =
error instanceof Error
? error.message
: typeof error === 'object' && error !== null && 'message' in error
? String(error.message)
: String(error);
getDebugLogger().log('error', 'network', 'DesktopUpdater', `${message}: ${detail}`);
getDebugLogger().log(
'error',
'network',
'DesktopUpdater',
`${message}: ${getUpdaterErrorMessage(error)}`
);
};
export function DesktopUpdater() {
@@ -41,6 +47,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);
@@ -157,6 +164,7 @@ export function DesktopUpdater() {
if (!updateInfo || installStartedRef.current) return;
installStartedRef.current = true;
try {
setInstallError(null);
setIsDownloading(true);
setPhase({ type: 'downloading', progress: 0 });
@@ -192,8 +200,10 @@ export function DesktopUpdater() {
closePendingUpdate(updateInfo);
} catch (err) {
logUpdaterError('Failed to install update', err);
setInstallError(getUpdaterErrorMessage(err));
setIsDownloading(false);
setIsInstalling(false);
setPhase({ type: 'ready', version: updateInfo.version });
installStartedRef.current = false;
}
}, [closePendingUpdate, updateInfo, setPhase]);
@@ -235,6 +245,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,
@@ -263,6 +293,7 @@ export function DesktopUpdater() {
isDownloading,
isInstalled,
isInstalling,
installError,
handleInstall,
handleRestart,
handleDismiss,