Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(desktop): check core OTA on manual update checks (#20157)

Inneid3c91f1a8394
diff --git a/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts b/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts
index 8b6800c8b1f..bf58d6a755c 100644
--- a/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts
+++ b/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts
@@ -177,6 +177,7 @@ export class UpdaterManager {
* Check for updates
*/
public checkForUpdates = async ({ manual = false }: { manual?: boolean } = {}) => {
+ if (manual) void this.app.coreUpdateManager.checkForUpdates({ manual: true });
if (this.checking || this.downloading) return;
this.checking = true;
diff --git a/apps/desktop/src/main/core/infrastructure/__tests__/UpdaterManager.test.ts b/apps/desktop/src/main/core/infrastructure/__tests__/UpdaterManager.test.ts
index 876c00a94c8..c2c8ca570e4 100644
--- a/apps/desktop/src/main/core/infrastructure/__tests__/UpdaterManager.test.ts
+++ b/apps/desktop/src/main/core/infrastructure/__tests__/UpdaterManager.test.ts
@@ -124,6 +124,9 @@ describe('UpdaterManager', () => {
broadcast: mockBroadcast,
}),
},
+ coreUpdateManager: {
+ checkForUpdates: vi.fn().mockResolvedValue(undefined),
+ },
isQuiting: false,
menuManager: {
rebuildAppMenu: vi.fn(),
@@ -215,6 +218,18 @@ describe('UpdaterManager', () => {
expect(autoUpdater.checkForUpdates).toHaveBeenCalled();
});
+ it('should also check core OTA on a manual check', async () => {
+ await updaterManager.checkForUpdates({ manual: true });
+
+ expect(mockApp.coreUpdateManager.checkForUpdates).toHaveBeenCalledWith({ manual: true });
+ });
+
+ it('should leave core OTA to its own schedule on an auto check', async () => {
+ await updaterManager.checkForUpdates();
+
+ expect(mockApp.coreUpdateManager.checkForUpdates).not.toHaveBeenCalled();
+ });
+
it('should broadcast updaterStateChanged with checking stage when checking', async () => {
await updaterManager.checkForUpdates({ manual: true });
diff --git a/apps/desktop/src/main/core/infrastructure/coreOta/CoreUpdateManager.ts b/apps/desktop/src/main/core/infrastructure/coreOta/CoreUpdateManager.ts
index d86767750c2..ba1f5d9ee79 100644
--- a/apps/desktop/src/main/core/infrastructure/coreOta/CoreUpdateManager.ts
+++ b/apps/desktop/src/main/core/infrastructure/coreOta/CoreUpdateManager.ts
@@ -289,7 +289,8 @@ export class CoreUpdateManager {
staged: this.staged?.version ?? null,
});
- checkForUpdates = () => {
+ checkForUpdates = ({ manual = false }: { manual?: boolean } = {}) => {
+ if (manual && this.staged) this.announceStaged();
this.checkTask = this.checkTask.catch(() => {}).then(() => this.runCheck());
return this.checkTask;
};
@@ -340,10 +341,7 @@ export class CoreUpdateManager {
: { staged: version },
);
this.lastError = null;
- this.app.browserManager.broadcastToAllWindows('updateReady', {
- kind: applyMode === 'relaunch' ? 'core-relaunch' : 'core-reload',
- version,
- });
+ this.announceStaged();
this.gc();
if (applyMode === 'reload') this.handleWindowBlur();
outcome = 'staged';
@@ -364,6 +362,15 @@ export class CoreUpdateManager {
}
}
+ private announceStaged() {
+ if (!this.staged) return;
+ const { applyMode, version } = this.staged;
+ this.app.browserManager.broadcastToAllWindows('updateReady', {
+ kind: applyMode === 'relaunch' ? 'core-relaunch' : 'core-reload',
+ version,
+ });
+ }
+
private async fetchRemote(feedUrl: string, generation: number): Promise<CoreManifest | null> {
const res = await this.fetchImpl(`${feedUrl}/latest.json`, { cache: 'no-store' });
if (res.status === 404) throw new SkipCheck('feed-not-found');
diff --git a/apps/desktop/src/main/core/infrastructure/coreOta/__tests__/CoreUpdateManager.int.test.ts b/apps/desktop/src/main/core/infrastructure/coreOta/__tests__/CoreUpdateManager.int.test.ts
index 4f042235740..8f4e25a73ac 100644
--- a/apps/desktop/src/main/core/infrastructure/coreOta/__tests__/CoreUpdateManager.int.test.ts
+++ b/apps/desktop/src/main/core/infrastructure/coreOta/__tests__/CoreUpdateManager.int.test.ts
@@ -487,6 +487,22 @@ describe('CoreUpdateManager checkForUpdates', () => {
expect(reload).toHaveBeenCalledTimes(1);
});
+ it('re-announces an already staged core on a manual check', async () => {
+ serveLatest(rendererOnly('1.0.1', 1));
+ const { app, manager } = await loadManager();
+ await manager.checkForUpdates();
+ vi.mocked(app.browserManager.broadcastToAllWindows).mockClear();
+
+ await manager.checkForUpdates();
+ expect(app.browserManager.broadcastToAllWindows).not.toHaveBeenCalled();
+
+ await manager.checkForUpdates({ manual: true });
+ expect(app.browserManager.broadcastToAllWindows).toHaveBeenCalledWith('updateReady', {
+ kind: 'core-reload',
+ version: '1.0.1',
+ });
+ });
+
it('stages a main-process change as core-relaunch and switches pointer immediately', async () => {
serveLatest(mainChanged('1.0.1', 1));
const { app, manager } = await loadManager();