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

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

menuBuilder.setNoUpdateAvailableMenuVisibility.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.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.mock.calls.length;
jest.advanceTimersByTime(
APPLICATION.UPDATE_NOT_AVAILABLE_DISPLAY_MS * 2,
);
// No additional hide call due to cleared timeout
expect(
menuBuilder.setNoUpdateAvailableMenuVisibility.mock.calls.length,
).toBe(callsBefore);
} finally {
jest.useRealTimers();
}
});

it('handles update-cancelled (reset state)', async () => {
await updater.start();
emit('update-cancelled');
Expand Down
17 changes: 17 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,6 +131,13 @@ 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);
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: 'notification.wav',

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

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