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
60 changes: 60 additions & 0 deletions src/main/updater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,66 @@ describe('main/updater.ts', () => {
).toHaveBeenCalledWith(false);
});

it('auto-hides "No updates available" after configured timeout', async () => {
jest.useFakeTimers();
try {
await updater.start();
(
menuBuilder.setNoUpdateAvailableMenuVisibility as jest.Mock
).mockClear();

emit('update-not-available');
// Immediately shows the message
expect(
menuBuilder.setNoUpdateAvailableMenuVisibility,
).toHaveBeenCalledWith(true);

// Then hides it after the configured timeout
jest.advanceTimersByTime(APPLICATION.UPDATE_NOT_AVAILABLE_DISPLAY_MS);
expect(
menuBuilder.setNoUpdateAvailableMenuVisibility,
).toHaveBeenLastCalledWith(false);
} finally {
jest.useRealTimers();
}
});

it('clears pending hide timer when a new check starts', async () => {
jest.useFakeTimers();
try {
await updater.start();
(
menuBuilder.setNoUpdateAvailableMenuVisibility as jest.Mock
).mockClear();

emit('update-not-available');
// Message shown
expect(
menuBuilder.setNoUpdateAvailableMenuVisibility,
).toHaveBeenCalledWith(true);

// New check should hide immediately and clear pending timeout
emit('checking-for-update');
expect(
menuBuilder.setNoUpdateAvailableMenuVisibility,
).toHaveBeenLastCalledWith(false);

const callsBefore = (
menuBuilder.setNoUpdateAvailableMenuVisibility as jest.Mock
).mock.calls.length;
jest.advanceTimersByTime(
APPLICATION.UPDATE_NOT_AVAILABLE_DISPLAY_MS * 2,
);
// No additional hide call due to cleared timeout
expect(
(menuBuilder.setNoUpdateAvailableMenuVisibility as jest.Mock).mock
.calls.length,
).toBe(callsBefore);
} finally {
jest.useRealTimers();
}
});

it('handles update-cancelled (reset state)', async () => {
await updater.start();
emit('update-cancelled');
Expand Down
20 changes: 20 additions & 0 deletions src/main/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class AppUpdater {
private readonly menubar: Menubar;
private readonly menuBuilder: MenuBuilder;
private started = false;
private noUpdateMessageTimeout?: NodeJS.Timeout;

constructor(menubar: Menubar, menuBuilder: MenuBuilder) {
this.menubar = menubar;
Expand Down Expand Up @@ -56,6 +57,9 @@ export default class AppUpdater {
logInfo('auto updater', 'Checking for update');
this.menuBuilder.setCheckForUpdatesMenuEnabled(false);
this.menuBuilder.setNoUpdateAvailableMenuVisibility(false);

// Clear any existing timeout when starting a new check
this.clearNoUpdateTimeout();
});

autoUpdater.on('update-available', () => {
Expand Down Expand Up @@ -84,6 +88,12 @@ export default class AppUpdater {
this.menuBuilder.setNoUpdateAvailableMenuVisibility(true);
this.menuBuilder.setUpdateAvailableMenuVisibility(false);
this.menuBuilder.setUpdateReadyForInstallMenuVisibility(false);

// Auto-hide the "no updates available" message
this.clearNoUpdateTimeout();
this.noUpdateMessageTimeout = setTimeout(() => {
this.menuBuilder.setNoUpdateAvailableMenuVisibility(false);
}, APPLICATION.UPDATE_NOT_AVAILABLE_DISPLAY_MS);
});

autoUpdater.on('update-cancelled', () => {
Expand Down Expand Up @@ -121,12 +131,22 @@ export default class AppUpdater {
this.menubar.tray.setToolTip(`${APPLICATION.NAME}\n${status}`);
}

private clearNoUpdateTimeout() {
if (this.noUpdateMessageTimeout) {
clearTimeout(this.noUpdateMessageTimeout);
this.noUpdateMessageTimeout = undefined;
}
}

private resetState() {
this.menubar.tray.setToolTip(APPLICATION.NAME);
this.menuBuilder.setCheckForUpdatesMenuEnabled(true);
this.menuBuilder.setNoUpdateAvailableMenuVisibility(false);
this.menuBuilder.setUpdateAvailableMenuVisibility(false);
this.menuBuilder.setUpdateReadyForInstallMenuVisibility(false);

// Clear any pending timeout
this.clearNoUpdateTimeout();
}

private showUpdateReadyDialog(releaseName: string) {
Expand Down
2 changes: 2 additions & 0 deletions src/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ export const APPLICATION = {
NOTIFICATION_SOUND: 'clearly.mp3',

UPDATE_CHECK_INTERVAL_MS: 24 * 60 * 60 * 1000, // 24 hours

UPDATE_NOT_AVAILABLE_DISPLAY_MS: 60 * 1000, // 60 seconds
};
Loading