fix(updater): address final review feedback

This commit is contained in:
4gray committed 2026-06-28 18:26:49 +02:00
1 parent f1fc5ec7b2
commit 3cc46c492b
4 files changed
+59 -1

No files matched your search

@@ -145,6 +145,35 @@ describe('AppUpdateService', () => {
);
});
it('deduplicates concurrent update checks', async () => {
const { service, updater } = createService();
let resolveCheck: ((value: unknown) => void) | undefined;
updater.checkForUpdates.mockImplementationOnce(
() =>
new Promise((resolve) => {
resolveCheck = resolve;
})
);
const firstCheck = service.checkForUpdates();
const secondCheck = service.checkForUpdates();
expect(updater.checkForUpdates).toHaveBeenCalledTimes(1);
expect(service.getStatus().status).toBe(
ELECTRON_BRIDGE_APP_UPDATE_STATUSES.Checking
);
resolveCheck?.(null);
await expect(Promise.all([firstCheck, secondCheck])).resolves.toEqual([
service.getStatus(),
service.getStatus(),
]);
await service.checkForUpdates();
expect(updater.checkForUpdates).toHaveBeenCalledTimes(2);
});
it('checks packaged non-AppImage Linux builds through GitHub manual fallback', async () => {
const fetcher = createReleaseFetcher();
const { service, updater } = createService({
@@ -226,6 +226,8 @@ export class AppUpdateService {
private readonly releases: CachedGitHubRelease[] = [];
private loadedReleasePages = 0;
private loadedAllReleases = false;
private checkForUpdatesPromise: Promise<ElectronBridgeAppUpdateStatus> | null =
null;
private status: ElectronBridgeAppUpdateStatus;
constructor(private readonly options: AppUpdateServiceOptions) {
@@ -256,6 +258,18 @@ export class AppUpdateService {
}
async checkForUpdates(): Promise<ElectronBridgeAppUpdateStatus> {
if (this.checkForUpdatesPromise) {
return this.checkForUpdatesPromise;
}
this.checkForUpdatesPromise = this.runCheckForUpdates().finally(() => {
this.checkForUpdatesPromise = null;
});
return this.checkForUpdatesPromise;
}
private async runCheckForUpdates(): Promise<ElectronBridgeAppUpdateStatus> {
if (!this.isPackaged) {
this.setStatus({
status: ELECTRON_BRIDGE_APP_UPDATE_STATUSES.Unsupported,
@@ -98,4 +98,19 @@ describe('SettingsAboutSectionComponent app updates', () => {
expect(getButton(fixture, 'app-update-open-release')).toBeTruthy();
expect(openManual).toHaveBeenCalledTimes(1);
});
it('uses a neutral status label before unsupported packages have checked GitHub releases', () => {
configureComponent(fixture, {
currentVersion: '0.22.0',
manualDownloadUrl:
'https://github.com/4gray/iptvnator/releases/latest',
status: ELECTRON_BRIDGE_APP_UPDATE_STATUSES.Unsupported,
supportedSelfUpdate: false,
});
expect(fixture.componentInstance.appUpdateStatusLabelKey()).toBe(
'SETTINGS.APP_UPDATE_IDLE'
);
expect(getButton(fixture, 'app-update-open-release')).toBeTruthy();
});
});
@@ -97,7 +97,7 @@ export class SettingsAboutSectionComponent {
case ELECTRON_BRIDGE_APP_UPDATE_STATUSES.Downloaded:
return 'SETTINGS.APP_UPDATE_DOWNLOADED';
case ELECTRON_BRIDGE_APP_UPDATE_STATUSES.Unsupported:
return 'SETTINGS.APP_UPDATE_MANUAL_AVAILABLE';
return 'SETTINGS.APP_UPDATE_IDLE';
case ELECTRON_BRIDGE_APP_UPDATE_STATUSES.Error:
return 'SETTINGS.APP_UPDATE_ERROR';
default: