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 ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Subscription is separate from side effects, but it multiplies the same way: ever

Updates are a main-process concern (`src/main/updater.ts`), driven by `electron-updater` events and surfaced through the tray/menu and a native ready dialog.

- `update-available` updates the tooltip and menu; it does not clear the dialog guard.
- `update-available` updates the tooltip and shows **Downloading update…** in the menu; it does not clear the dialog guard. Download percentages are shown only in the tooltip.
- `update-downloaded` marks the menu's **Restart to install update** entry visible and, when notifications are enabled, shows the ready dialog once per downloaded version.
- The dialog offers **Restart**, **Later**, and **Release notes** when the downloaded update has release information. Release notes opens the matching GitHub release page.
- **Later** dismisses only the dialog. The menu entry remains the install path, and a later check for the same downloaded version does not prompt again. A different version prompts normally; `update-cancelled` clears the guard. The guard is process-local.
Expand Down
14 changes: 7 additions & 7 deletions src/main/menu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,28 +153,28 @@ describe('main/menu.ts', () => {
});
});

describe('updateAvailableMenuItem', () => {
describe('downloadingUpdateMenuItem', () => {
it('default menu configuration', () => {
const config = getMenuItemConfigByLabel('An update is available');
const config = getMenuItemConfigByLabel('Downloading update…');

expect(config).toBeDefined();
expect(config?.label).toBe('An update is available');
expect(config?.label).toBe('Downloading update…');
expect(config?.enabled).toBe(false);
expect(config?.visible).toBe(false);
});

it('shows menu item', () => {
menuBuilder.setUpdateAvailableMenuVisibility(true);
menuBuilder.setDownloadingUpdateMenuVisibility(true);

// oxlint-disable-next-line dot-notation -- This is a test
expect(menuBuilder['updateAvailableMenuItem'].visible).toBe(true);
expect(menuBuilder['downloadingUpdateMenuItem'].visible).toBe(true);
});

it('hides menu item', () => {
menuBuilder.setUpdateAvailableMenuVisibility(false);
menuBuilder.setDownloadingUpdateMenuVisibility(false);

// oxlint-disable-next-line dot-notation -- This is a test
expect(menuBuilder['updateAvailableMenuItem'].visible).toBe(false);
expect(menuBuilder['downloadingUpdateMenuItem'].visible).toBe(false);
});
});

Expand Down
14 changes: 7 additions & 7 deletions src/main/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { openLogsDirectory, takeScreenshot } from './utils';
export default class MenuBuilder {
private readonly checkForUpdatesMenuItem: MenuItem;
private readonly noUpdateAvailableMenuItem: MenuItem;
private readonly updateAvailableMenuItem: MenuItem;
private readonly downloadingUpdateMenuItem: MenuItem;
private readonly updateReadyForInstallMenuItem: MenuItem;
private readonly showWindowMenuItem: MenuItem;
private readonly hideWindowMenuItem: MenuItem;
Expand Down Expand Up @@ -52,8 +52,8 @@ export default class MenuBuilder {
visible: false,
});

this.updateAvailableMenuItem = new MenuItem({
label: 'An update is available',
this.downloadingUpdateMenuItem = new MenuItem({
label: 'Downloading update…',
enabled: false,
visible: false,
});
Expand Down Expand Up @@ -98,7 +98,7 @@ export default class MenuBuilder {
{ type: 'separator' },
this.checkForUpdatesMenuItem,
this.noUpdateAvailableMenuItem,
this.updateAvailableMenuItem,
this.downloadingUpdateMenuItem,
this.updateReadyForInstallMenuItem,
{ type: 'separator' },
{
Expand Down Expand Up @@ -227,12 +227,12 @@ export default class MenuBuilder {
}

/**
* Show or hide the "An update is available" status menu item.
* Show or hide the "Downloading update…" status menu item.
*
* @param isVisible - Whether the item should be visible.
*/
setUpdateAvailableMenuVisibility(isVisible: boolean) {
this.updateAvailableMenuItem.visible = isVisible;
setDownloadingUpdateMenuVisibility(isVisible: boolean) {
this.downloadingUpdateMenuItem.visible = isVisible;
this.refreshMenu();
}

Expand Down
15 changes: 9 additions & 6 deletions src/main/updater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('main/updater.ts', () => {
public override setAutomaticUpdatesEnabled = vi.fn();
public override setCheckForUpdatesMenuEnabled = vi.fn();
public override setNoUpdateAvailableMenuVisibility = vi.fn();
public override setUpdateAvailableMenuVisibility = vi.fn();
public override setDownloadingUpdateMenuVisibility = vi.fn();
public override setUpdateReadyForInstallMenuVisibility = vi.fn();
}

Expand Down Expand Up @@ -225,7 +225,7 @@ describe('main/updater.ts', () => {
}),
);
expect(autoUpdater.quitAndInstall).not.toHaveBeenCalled();
expect(menuBuilder.setUpdateAvailableMenuVisibility).toHaveBeenCalledWith(false);
expect(menuBuilder.setDownloadingUpdateMenuVisibility).toHaveBeenCalledWith(false);
expect(menuBuilder.setUpdateReadyForInstallMenuVisibility).toHaveBeenCalledWith(true);
});

Expand Down Expand Up @@ -255,7 +255,7 @@ describe('main/updater.ts', () => {

expect(dialog.showMessageBox).not.toHaveBeenCalled();
expect(notify).not.toHaveBeenCalled();
expect(menuBuilder.setUpdateAvailableMenuVisibility).toHaveBeenCalledWith(false);
expect(menuBuilder.setDownloadingUpdateMenuVisibility).toHaveBeenCalledWith(false);
expect(menuBuilder.setUpdateReadyForInstallMenuVisibility).toHaveBeenCalledWith(true);
});

Expand Down Expand Up @@ -513,17 +513,20 @@ describe('main/updater.ts', () => {

emit('update-available', { version: '1.2.3' });

expect(menuBuilder.setUpdateAvailableMenuVisibility).toHaveBeenCalledWith(true);
expect(menuBuilder.setUpdateReadyForInstallMenuVisibility).toHaveBeenLastCalledWith(false);
expect(menuBuilder.setDownloadingUpdateMenuVisibility).toHaveBeenLastCalledWith(true);
expect(menubar.tray.setToolTip).toHaveBeenCalledWith(
expect.stringContaining('A new update is available'),
);
});

it('handles download-progress', async () => {
it('shows download progress only in the tooltip', async () => {
await updater.setAutomaticUpdatesEnabled(true);

emit('download-progress', { percent: 12.3456 });

expect(menuBuilder.setDownloadingUpdateMenuVisibility).not.toHaveBeenCalled();

expect(menubar.tray.setToolTip).toHaveBeenCalledWith(expect.stringContaining('12.35%'));
});

Expand All @@ -534,7 +537,7 @@ describe('main/updater.ts', () => {

expect(menuBuilder.setCheckForUpdatesMenuEnabled).toHaveBeenCalledWith(true);
expect(menuBuilder.setNoUpdateAvailableMenuVisibility).toHaveBeenCalledWith(true);
expect(menuBuilder.setUpdateAvailableMenuVisibility).toHaveBeenCalledWith(false);
expect(menuBuilder.setDownloadingUpdateMenuVisibility).toHaveBeenCalledWith(false);
expect(menuBuilder.setUpdateReadyForInstallMenuVisibility).toHaveBeenCalledWith(false);
});

Expand Down
9 changes: 5 additions & 4 deletions src/main/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ export default class AppUpdater {
// different version will not match `lastPromptedVersion` and prompts
// normally. Only a cancelled download clears the guard.
this.setTooltipWithStatus('A new update is available');
this.menuBuilder.setUpdateAvailableMenuVisibility(true);
this.menuBuilder.setUpdateReadyForInstallMenuVisibility(false);
this.menuBuilder.setDownloadingUpdateMenuVisibility(true);
});

autoUpdater.on('download-progress', (progressObj) => {
Expand All @@ -142,7 +143,7 @@ export default class AppUpdater {
this.downloaded = true;
logInfo('auto updater', 'Update downloaded');
this.setTooltipWithStatus('A new update is ready to install');
this.menuBuilder.setUpdateAvailableMenuVisibility(false);
this.menuBuilder.setDownloadingUpdateMenuVisibility(false);
this.menuBuilder.setUpdateReadyForInstallMenuVisibility(true);
// The guard in showUpdateReadyDialog also keeps a re-check of the same version quiet.
if (this.notificationsEnabled && event.version !== this.lastPromptedVersion) {
Expand All @@ -161,7 +162,7 @@ export default class AppUpdater {
logInfo('auto updater', 'Update not available');
this.menuBuilder.setCheckForUpdatesMenuEnabled(true);
this.menuBuilder.setNoUpdateAvailableMenuVisibility(true);
this.menuBuilder.setUpdateAvailableMenuVisibility(false);
this.menuBuilder.setDownloadingUpdateMenuVisibility(false);
this.menuBuilder.setUpdateReadyForInstallMenuVisibility(false);

// Auto-hide the "no updates available" message
Expand Down Expand Up @@ -284,7 +285,7 @@ export default class AppUpdater {
this.menubar.tray.setToolTip(APPLICATION.NAME);
this.menuBuilder.setCheckForUpdatesMenuEnabled(true);
this.menuBuilder.setNoUpdateAvailableMenuVisibility(false);
this.menuBuilder.setUpdateAvailableMenuVisibility(false);
this.menuBuilder.setDownloadingUpdateMenuVisibility(false);
this.menuBuilder.setUpdateReadyForInstallMenuVisibility(false);

// Clear any pending timeout
Expand Down
Loading