diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index ccfa7387a..dedbb7740 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -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. diff --git a/src/main/menu.test.ts b/src/main/menu.test.ts index 8d341f2b7..d2e3dc6e3 100644 --- a/src/main/menu.test.ts +++ b/src/main/menu.test.ts @@ -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); }); }); diff --git a/src/main/menu.ts b/src/main/menu.ts index 49b7032c8..09055b43d 100644 --- a/src/main/menu.ts +++ b/src/main/menu.ts @@ -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; @@ -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, }); @@ -98,7 +98,7 @@ export default class MenuBuilder { { type: 'separator' }, this.checkForUpdatesMenuItem, this.noUpdateAvailableMenuItem, - this.updateAvailableMenuItem, + this.downloadingUpdateMenuItem, this.updateReadyForInstallMenuItem, { type: 'separator' }, { @@ -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(); } diff --git a/src/main/updater.test.ts b/src/main/updater.test.ts index 054786f1e..953c3f976 100644 --- a/src/main/updater.test.ts +++ b/src/main/updater.test.ts @@ -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(); } @@ -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); }); @@ -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); }); @@ -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%')); }); @@ -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); }); diff --git a/src/main/updater.ts b/src/main/updater.ts index 2b39b90aa..c38a059f2 100644 --- a/src/main/updater.ts +++ b/src/main/updater.ts @@ -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) => { @@ -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) { @@ -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 @@ -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