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): make in-app update actually install on Linux (#19621)

Arvin Xub92662992295
diff --git a/apps/desktop/resources/locales/zh-CN/menu.json b/apps/desktop/resources/locales/zh-CN/menu.json
index 304118e6397..18f8c8608e1 100644
--- a/apps/desktop/resources/locales/zh-CN/menu.json
+++ b/apps/desktop/resources/locales/zh-CN/menu.json
@@ -4,6 +4,7 @@
"common.downloadingUpdate": "正在下载更新…",
"common.isLatestVersion": "已是最新版本",
"common.restartToUpdate": "重启以完成更新",
+ "common.updateUnsupported": "下载最新版本...",
"context.copyImage": "复制图片",
"context.copyImageAddress": "复制图片地址",
"context.copyLink": "复制链接",
diff --git a/apps/desktop/src/main/core/App.ts b/apps/desktop/src/main/core/App.ts
index f6eb1095870..636a50d1a8c 100644
--- a/apps/desktop/src/main/core/App.ts
+++ b/apps/desktop/src/main/core/App.ts
@@ -81,6 +81,14 @@ export class App {
*/
isQuiting: boolean = false;
+ /**
+ * Set while UpdaterManager is handing an installed update over to
+ * electron-updater. It closes every window first, which on Linux would
+ * otherwise trip the `window-all-closed` quit below and kill the process
+ * before `quitAndInstall()` ever runs.
+ */
+ isInstallingUpdate: boolean = false;
+
get appStoragePath() {
const storagePath = this.storeManager.get('storagePath');
@@ -288,12 +296,7 @@ export class App {
// Set global application exit state and lifecycle listeners immediately.
this.isQuiting = false;
- app.on('window-all-closed', () => {
- if (electronIs.windows() || process.platform === 'linux') {
- logger.info(`All windows closed, quitting application (${process.platform})`);
- app.quit();
- }
- });
+ app.on('window-all-closed', this.handleWindowAllClosed);
app.on('activate', this.onActivate);
@@ -603,6 +606,26 @@ export class App {
});
}
+ /**
+ * Windows and Linux quit once the last window goes away — except while an
+ * update is being installed. `UpdaterManager.installNow()` closes every
+ * window before handing over to `autoUpdater.quitAndInstall()`, so quitting
+ * here would end the process first and the downloaded package would silently
+ * never be applied. That is a Linux-only failure today: macOS does not quit
+ * on `window-all-closed`, and installNow() skips the close loop on Windows.
+ */
+ handleWindowAllClosed = () => {
+ if (this.isInstallingUpdate) {
+ logger.info('All windows closed while installing an update, keeping the process alive');
+ return;
+ }
+
+ if (electronIs.windows() || process.platform === 'linux') {
+ logger.info(`All windows closed, quitting application (${process.platform})`);
+ app.quit();
+ }
+ };
+
private quitReady = false;
private quitCleanup?: Promise<void>;
diff --git a/apps/desktop/src/main/core/__tests__/App.test.ts b/apps/desktop/src/main/core/__tests__/App.test.ts
index 2775f77bb26..82b60134366 100644
--- a/apps/desktop/src/main/core/__tests__/App.test.ts
+++ b/apps/desktop/src/main/core/__tests__/App.test.ts
@@ -280,6 +280,52 @@ describe('App', () => {
});
});
+ describe('handleWindowAllClosed', () => {
+ const originalPlatform = process.platform;
+
+ const setPlatform = (value: string) =>
+ Object.defineProperty(process, 'platform', { configurable: true, value });
+
+ afterEach(() => {
+ Object.defineProperty(process, 'platform', {
+ configurable: true,
+ value: originalPlatform,
+ });
+ });
+
+ it('quits on Linux once the last window is gone', () => {
+ setPlatform('linux');
+ appInstance = new App();
+
+ appInstance.handleWindowAllClosed();
+
+ expect(electronApp.quit).toHaveBeenCalled();
+ });
+
+ // Regression: installNow() closes every window on its way to
+ // autoUpdater.quitAndInstall(). Quitting here would end the process before
+ // electron-updater ever runs the installer, which is exactly why in-app
+ // update never applied on Linux while it worked on Windows. Issue #19564.
+ it('stays alive while an update install is in flight', () => {
+ setPlatform('linux');
+ appInstance = new App();
+ appInstance.isInstallingUpdate = true;
+
+ appInstance.handleWindowAllClosed();
+
+ expect(electronApp.quit).not.toHaveBeenCalled();
+ });
+
+ it('does not quit on macOS', () => {
+ setPlatform('darwin');
+ appInstance = new App();
+
+ appInstance.handleWindowAllClosed();
+
+ expect(electronApp.quit).not.toHaveBeenCalled();
+ });
+ });
+
describe('desktop bootstrap identity', () => {
it('responds through the registered controller without an elided runtime symbol', () => {
appInstance = new App();
diff --git a/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts b/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts
index f84fcfceddc..597a2583e0c 100644
--- a/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts
+++ b/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts
@@ -5,7 +5,7 @@ import type {
UpdaterStage,
UpdaterState,
} from '@lobechat/electron-client-ipc';
-import { app as electronApp } from 'electron';
+import { app as electronApp, BrowserWindow } from 'electron';
import semver from 'semver';
import { isDev, isWindows } from '@/const/env';
@@ -18,6 +18,14 @@ import type { App as AppCore } from '../App';
const logger = createLogger('core:UpdaterManager');
+/**
+ * How long to wait for electron-updater to take the process down after
+ * `quitAndInstall()`. A Linux package install runs `pkexec`/`sudo` through
+ * `spawnSync`, so this timer cannot fire while the installer is still working —
+ * it only fires when the hand-off failed outright.
+ */
+const INSTALL_HANDOFF_TIMEOUT = 60 * 1000;
+
export class UpdaterManager {
private app: AppCore;
private checking: boolean = false;
@@ -149,6 +157,20 @@ export class UpdaterManager {
if (manual) void this.app.coreUpdateManager.checkForUpdates({ manual: true });
if (!this.engine || this.checking || this.downloading) return;
+ // electron-updater has no updater implementation for every Linux
+ // distribution format we ship: snap refreshes through snapd, the `tar.gz`
+ // archive has no installer at all, and AppImageUpdater needs the APPIMAGE
+ // env only the AppImage runtime exports. For those, `checkForUpdates()`
+ // resolves `null` without emitting a single event, which would leave the
+ // UI spinning on "checking" forever. Say so instead.
+ if (!this.engine.isActive()) {
+ logger.warn(
+ 'Updater is inactive for this installation (unsupported distribution format or unpacked build) — in-app update is unavailable',
+ );
+ this.setStage('unsupported');
+ return;
+ }
+
this.checking = true;
this.activeGeneration = this.checkGeneration;
@@ -253,9 +275,12 @@ export class UpdaterManager {
this.captureRestoreRoute();
this.app.isQuiting = true;
+ // Suppress the `window-all-closed` quit in App.ts: on Linux it fires as soon
+ // as the loop below closes the last window and would tear the process down
+ // before the deferred quitAndInstall() runs.
+ this.app.isInstallingUpdate = true;
logger.info('Closing all windows before update installation...');
- const { BrowserWindow, app } = require('electron');
if (!isWindows) {
const allWindows = BrowserWindow.getAllWindows();
allWindows.forEach((window: any) => {
@@ -266,11 +291,25 @@ export class UpdaterManager {
}
logger.info('Releasing single instance lock...');
- app.releaseSingleInstanceLock();
+ electronApp.releaseSingleInstanceLock();
setTimeout(() => {
- logger.info(`Calling ${this.engine?.kind} quitAndInstall...`);
- this.engine?.quitAndInstall();
+ const engine = this.engine;
+ logger.info(`Calling ${engine?.kind} quitAndInstall...`);
+ engine?.quitAndInstall();
+
+ // electron-updater's quitAndInstall() only quits once the installer took
+ // over. If it bailed out (no installer path, package manager missing,
+ // sudo prompt refused) we would be left with a window-less process that
+ // never quits, because window-all-closed is suppressed above. Quit on our
+ // own in that case; after a successful hand-off the process is already
+ // gone. Sparkle owns its own termination and may still be prompting.
+ if (engine?.kind !== 'electron-updater') return;
+ setTimeout(() => {
+ logger.warn('quitAndInstall did not end the process, quitting explicitly');
+ this.app.isInstallingUpdate = false;
+ electronApp.quit();
+ }, INSTALL_HANDOFF_TIMEOUT);
}, 100);
};
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 a110584a511..356526e4268 100644
--- a/apps/desktop/src/main/core/infrastructure/__tests__/UpdaterManager.test.ts
+++ b/apps/desktop/src/main/core/infrastructure/__tests__/UpdaterManager.test.ts
@@ -7,13 +7,13 @@ import type { App as AppCore } from '../../App';
import { UpdaterManager } from '../UpdaterManager';
// Use vi.hoisted to ensure mocks work with require()
-const { mockGetAllWindows, mockLoadSparkleBridge, mockReleaseSingleInstanceLock } = vi.hoisted(
- () => ({
+const { mockGetAllWindows, mockLoadSparkleBridge, mockQuit, mockReleaseSingleInstanceLock } =
+ vi.hoisted(() => ({
mockGetAllWindows: vi.fn().mockReturnValue([]),
mockLoadSparkleBridge: vi.fn(),
+ mockQuit: vi.fn(),
mockReleaseSingleInstanceLock: vi.fn(),
- }),
-);
+ }));
vi.mock('electron-sparkle-updater', () => ({ loadSparkleBridge: mockLoadSparkleBridge }));
@@ -62,6 +62,7 @@ vi.mock('electron-updater', () => {
currentVersion: undefined as any,
downloadUpdate: vi.fn(),
forceDevUpdateConfig: false,
+ isUpdaterActive: vi.fn().mockReturnValue(true),
logger: null as any,
on: vi.fn(),
quitAndInstall: vi.fn(),
@@ -79,6 +80,7 @@ vi.mock('electron', () => ({
getVersion: vi.fn().mockReturnValue('0.0.0'),
isPackaged: true,
on: vi.fn(),
+ quit: mockQuit,
releaseSingleInstanceLock: mockReleaseSingleInstanceLock,
},
}));
@@ -133,6 +135,7 @@ describe('UpdaterManager', () => {
(autoUpdater as any).allowDowngrade = false;
(autoUpdater as any).forceDevUpdateConfig = false;
(autoUpdater as any).currentVersion = undefined;
+ vi.mocked((autoUpdater as any).isUpdaterActive).mockReturnValue(true);
// Capture registered events
registeredEvents = new Map();
@@ -154,6 +157,7 @@ describe('UpdaterManager', () => {
coreUpdateManager: {
checkForUpdates: vi.fn().mockResolvedValue(undefined),
},
+ isInstallingUpdate: false,
isQuiting: false,
menuManager: {
rebuildAppMenu: vi.fn(),
@@ -241,6 +245,17 @@ describe('UpdaterManager', () => {
Object.defineProperty(process, 'platform', { value: originalPlatform });
});
+ it('leaves termination to Sparkle when installing now', async () => {
+ await updaterManager.initialize();
+ (updaterManager as any).updateAvailable = true;
+
+ updaterManager.installNow();
+ await vi.advanceTimersByTimeAsync(100 + 60 * 1000);
+
+ expect(bridge.installUpdateNow).toHaveBeenCalled();
+ expect(mockQuit).not.toHaveBeenCalled();
+ });
+
it('drives canary through Sparkle with the arch-specific appcast', async () => {
vi.mocked(mockApp.storeManager.get).mockReturnValue('canary');
await updaterManager.initialize();
@@ -383,6 +398,32 @@ describe('UpdaterManager', () => {
vi.mocked(autoUpdater.checkForUpdates).mockResolvedValue({} as any);
});
+ // Regression: a snap / tar.gz install (and an AppImage started without its
+ // runtime) makes electron-updater resolve checkForUpdates() with `null` and
+ // emit nothing at all, which used to strand the UI on the `checking`
+ // spinner forever. Issue #19564.
+ it('should report unsupported instead of hanging when the updater is inactive', async () => {
+ vi.mocked((autoUpdater as any).isUpdaterActive).mockReturnValue(false);
+ mockBroadcast.mockClear();
+
+ await updaterManager.checkForUpdates({ manual: true });
+
+ expect(autoUpdater.checkForUpdates).not.toHaveBeenCalled();
+ expect(mockBroadcast).toHaveBeenCalledWith('updaterStateChanged', { stage: 'unsupported' });
+ expect(updaterManager.getUpdaterState().stage).toBe('unsupported');
+ });
+
+ it('should not get stuck on checking after an inactive-updater check', async () => {
+ vi.mocked((autoUpdater as any).isUpdaterActive).mockReturnValue(false);
+
+ await updaterManager.checkForUpdates({ manual: true });
+
+ const stages = mockBroadcast.mock.calls
+ .filter(([event]) => event === 'updaterStateChanged')
+ .map(([, state]) => state.stage);
+ expect(stages).not.toContain('checking');
+ });
+
it('should call autoUpdater.checkForUpdates', async () => {
await updaterManager.checkForUpdates();
@@ -542,16 +583,52 @@ describe('UpdaterManager', () => {
});
describe('installNow', () => {
- // Note: installNow uses require('electron') which is difficult to mock in vitest.
- // These tests are skipped because vi.mock doesn't work with dynamic require().
- // The functionality should be tested in integration tests or E2E tests.
+ beforeEach(async () => {
+ await updaterManager.initialize();
+ (updaterManager as any).updateAvailable = true;
+ });
+
+ // Regression: closing every window makes Electron fire `window-all-closed`,
+ // and App.ts quits the process there on Linux/Windows. That used to kill the
+ // process before the deferred quitAndInstall() ran, so a downloaded update
+ // was never installed on Linux. Issue #19564.
+ it('marks the app as installing before closing any window', () => {
+ const closeOrder: string[] = [];
+ const mockWindow = {
+ close: vi.fn(() =>
+ closeOrder.push(`close:isInstallingUpdate=${mockApp.isInstallingUpdate}`),
+ ),
+ isDestroyed: vi.fn().mockReturnValue(false),
+ };
+ mockGetAllWindows.mockReturnValue([mockWindow]);
+
+ updaterManager.installNow();
+
+ expect(mockApp.isInstallingUpdate).toBe(true);
+ expect(closeOrder).toEqual(['close:isInstallingUpdate=true']);
+ });
+
+ it('quits by itself when quitAndInstall fails to hand off', async () => {
+ updaterManager.installNow();
+
+ await vi.advanceTimersByTimeAsync(100);
+ expect(autoUpdater.quitAndInstall).toHaveBeenCalledWith(true, true);
+ expect(mockQuit).not.toHaveBeenCalled();
+
+ // The failsafe must not fire while a package manager prompt could still
+ // be running, but it has to fire eventually — otherwise the suppressed
+ // window-all-closed quit leaves a window-less zombie process behind.
+ await vi.advanceTimersByTimeAsync(60 * 1000);
+ expect(mockQuit).toHaveBeenCalled();
+ expect(mockApp.isInstallingUpdate).toBe(false);
+ });
- it.skip('should set app.isQuiting to true', () => {
+ it('should set app.isQuiting to true', () => {
updaterManager.installNow();
expect(mockApp.isQuiting).toBe(true);
});
- it.skip('should close all windows', () => {
+ it('should close all windows', () => {
const mockWindow1 = { close: vi.fn(), isDestroyed: vi.fn().mockReturnValue(false) };
const mockWindow2 = { close: vi.fn(), isDestroyed: vi.fn().mockReturnValue(false) };
mockGetAllWindows.mockReturnValue([mockWindow1, mockWindow2]);
@@ -560,19 +637,19 @@ describe('UpdaterManager', () => {
expect(mockWindow2.close).toHaveBeenCalled();
});
- it.skip('should not close destroyed windows', () => {
+ it('should not close destroyed windows', () => {
const mockWindow = { close: vi.fn(), isDestroyed: vi.fn().mockReturnValue(true) };
mockGetAllWindows.mockReturnValue([mockWindow]);
updaterManager.installNow();
expect(mockWindow.close).not.toHaveBeenCalled();
});
- it.skip('should release single instance lock', () => {
+ it('should release single instance lock', () => {
updaterManager.installNow();
expect(mockReleaseSingleInstanceLock).toHaveBeenCalled();
});
- it.skip('should call quitAndInstall with correct parameters after delay', async () => {
+ it('should call quitAndInstall with correct parameters after delay', async () => {
updaterManager.installNow();
expect(autoUpdater.quitAndInstall).not.toHaveBeenCalled();
await vi.advanceTimersByTimeAsync(100);
diff --git a/apps/desktop/src/main/locales/default/menu.ts b/apps/desktop/src/main/locales/default/menu.ts
index f0d90bf240b..fc38231024e 100644
--- a/apps/desktop/src/main/locales/default/menu.ts
+++ b/apps/desktop/src/main/locales/default/menu.ts
@@ -4,6 +4,7 @@ const menu = {
'common.downloadingUpdate': 'Downloading update...',
'common.isLatestVersion': 'Already up to date',
'common.restartToUpdate': 'Restart to update',
+ 'common.updateUnsupported': 'Download latest version...',
'context.copyImage': 'Copy Image',
'context.copyImageAddress': 'Copy Image Address',
'context.copyLink': 'Copy Link',
diff --git a/apps/desktop/src/main/menus/impls/linux.test.ts b/apps/desktop/src/main/menus/impls/linux.test.ts
index 84f4dab17a0..c5e1ecc80b6 100644
--- a/apps/desktop/src/main/menus/impls/linux.test.ts
+++ b/apps/desktop/src/main/menus/impls/linux.test.ts
@@ -1,3 +1,4 @@
+import { DOWNLOAD_URL } from '@lobechat/const/url';
import { app, BrowserWindow, dialog, Menu, shell } from 'electron';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -39,6 +40,8 @@ const createMockApp = () => {
'file.preferences': 'Preferences',
'file.quit': 'Quit',
'common.checkUpdates': 'Check for Updates',
+ 'common.restartToUpdate': 'Restart to update',
+ 'common.updateUnsupported': 'Download latest version...',
'window.close': 'Close',
'window.minimize': 'Minimize',
'window.title': 'Window',
@@ -110,6 +113,8 @@ const createMockApp = () => {
},
updaterManager: {
checkForUpdates: vi.fn(),
+ getUpdaterState: vi.fn(() => ({ stage: 'idle' })),
+ installNow: vi.fn(),
},
storeManager: {
get: vi.fn(),
@@ -265,6 +270,37 @@ describe('LinuxMenu', () => {
expect(mockApp.updaterManager.checkForUpdates).toHaveBeenCalledWith({ manual: true });
});
+ // Regression: the Linux menu used to hard-code "Check for Updates" and never
+ // read the updater stage, so a downloaded update could not be installed from
+ // the menu at all — unlike macOS and Windows. Issue #19564.
+ it('offers restart-to-update once an update is downloaded', () => {
+ mockApp.updaterManager.getUpdaterState = vi.fn(() => ({ stage: 'downloaded' })) as any;
+ linuxMenu.buildAndSetAppMenu();
+
+ const template = (Menu.buildFromTemplate as any).mock.calls.at(-1)[0];
+ const fileMenu = template.find((item: any) => item.label === 'File');
+ const item = fileMenu.submenu.find((entry: any) => entry.label === 'Restart to update');
+
+ expect(item).toBeDefined();
+ item.click();
+ expect(mockApp.updaterManager.installNow).toHaveBeenCalled();
+ });
+
+ it('sends the user to the download page when the install format cannot self-update', () => {
+ mockApp.updaterManager.getUpdaterState = vi.fn(() => ({ stage: 'unsupported' })) as any;
+ linuxMenu.buildAndSetAppMenu();
+
+ const template = (Menu.buildFromTemplate as any).mock.calls.at(-1)[0];
+ const fileMenu = template.find((item: any) => item.label === 'File');
+ const item = fileMenu.submenu.find(
+ (entry: any) => entry.label === 'Download latest version...',
+ );
+
+ expect(item).toBeDefined();
+ item.click();
+ expect(shell.openExternal).toHaveBeenCalledWith(DOWNLOAD_URL.default);
+ });
+
it('should handle visit website click', async () => {
linuxMenu.buildAndSetAppMenu();
diff --git a/apps/desktop/src/main/menus/impls/linux.ts b/apps/desktop/src/main/menus/impls/linux.ts
index 9edba6a7fc0..ea8c20f97a9 100644
--- a/apps/desktop/src/main/menus/impls/linux.ts
+++ b/apps/desktop/src/main/menus/impls/linux.ts
@@ -1,6 +1,6 @@
import path from 'node:path';
-import { GITHUB, OFFICIAL_SITE } from '@lobechat/const/url';
+import { DOWNLOAD_URL, GITHUB, OFFICIAL_SITE } from '@lobechat/const/url';
import type { TrayNavigationSnapshot } from '@lobechat/electron-client-ipc';
import type { MenuItemConstructorOptions } from 'electron';
import { app, clipboard, dialog, Menu, shell } from 'electron';
@@ -116,12 +116,7 @@ export class LinuxMenu extends BaseMenuPlatform implements IMenuPlatform {
},
label: t('file.preferences'),
},
- {
- click: () => {
- this.app.updaterManager.checkForUpdates({ manual: true });
- },
- label: t('common.checkUpdates'),
- },
+ this.getUpdateMenuItem(t),
{ type: 'separator' },
{
accelerator: 'CmdOrCtrl+W',
@@ -279,6 +274,46 @@ export class LinuxMenu extends BaseMenuPlatform implements IMenuPlatform {
return template;
}
+ /**
+ * Mirrors the macOS/Windows menus: without this the Linux menu only ever
+ * offered "Check for updates" and never surfaced "Restart to update", so a
+ * downloaded update could not be installed from the menu bar at all.
+ */
+ private getUpdateMenuItem(t: (key: string, opts?: any) => string): MenuItemConstructorOptions {
+ const { stage } = this.app.updaterManager.getUpdaterState();
+
+ switch (stage) {
+ case 'checking': {
+ return { enabled: false, label: t('common.checkingUpdates') };
+ }
+ case 'downloading': {
+ return { enabled: false, label: t('common.downloadingUpdate') };
+ }
+ case 'downloaded': {
+ return {
+ click: () => this.app.updaterManager.installNow(),
+ label: t('common.restartToUpdate'),
+ };
+ }
+ case 'latest': {
+ return { enabled: false, label: t('common.isLatestVersion') };
+ }
+ // snap / tar.gz / a runtime-less AppImage cannot replace themselves.
+ case 'unsupported': {
+ return {
+ click: () => shell.openExternal(DOWNLOAD_URL.default),
+ label: t('common.updateUnsupported'),
+ };
+ }
+ default: {
+ return {
+ click: () => this.app.updaterManager.checkForUpdates({ manual: true }),
+ label: t('common.checkUpdates'),
+ };
+ }
+ }
+ }
+
private getDefaultContextMenuTemplate(data?: ContextMenuData): MenuItemConstructorOptions[] {
const t = this.app.i18n.ns('menu');
const hasText = Boolean(data?.selectionText?.trim());
diff --git a/apps/desktop/src/main/menus/impls/macOS.ts b/apps/desktop/src/main/menus/impls/macOS.ts
index a392c4b3164..8c8bbb71c89 100644
--- a/apps/desktop/src/main/menus/impls/macOS.ts
+++ b/apps/desktop/src/main/menus/impls/macOS.ts
@@ -1,6 +1,6 @@
import path from 'node:path';
-import { GITHUB, GITHUB_ISSUES, OFFICIAL_SITE } from '@lobechat/const/url';
+import { DOWNLOAD_URL, GITHUB, GITHUB_ISSUES, OFFICIAL_SITE } from '@lobechat/const/url';
import type { TrayNavigationSnapshot } from '@lobechat/electron-client-ipc';
import type { MenuItemConstructorOptions } from 'electron';
import { app, clipboard, Menu, shell } from 'electron';
@@ -462,6 +462,13 @@ export class MacOSMenu extends BaseMenuPlatform implements IMenuPlatform {
case 'latest': {
return { enabled: false, label: t('common.isLatestVersion') };
}
+ // snap / tar.gz / a runtime-less AppImage cannot replace themselves.
+ case 'unsupported': {
+ return {
+ click: () => shell.openExternal(DOWNLOAD_URL.default),
+ label: t('common.updateUnsupported'),
+ };
+ }
default: {
return {
click: () => this.app.updaterManager.checkForUpdates({ manual: true }),
diff --git a/apps/desktop/src/main/menus/impls/windows.ts b/apps/desktop/src/main/menus/impls/windows.ts
index bf3898dedd9..ca5e36c7f0f 100644
--- a/apps/desktop/src/main/menus/impls/windows.ts
+++ b/apps/desktop/src/main/menus/impls/windows.ts
@@ -1,6 +1,6 @@
import path from 'node:path';
-import { GITHUB, OFFICIAL_SITE } from '@lobechat/const/url';
+import { DOWNLOAD_URL, GITHUB, OFFICIAL_SITE } from '@lobechat/const/url';
import type { TrayNavigationSnapshot } from '@lobechat/electron-client-ipc';
import type { MenuItemConstructorOptions } from 'electron';
import { app, clipboard, Menu, shell } from 'electron';
@@ -277,6 +277,13 @@ export class WindowsMenu extends BaseMenuPlatform implements IMenuPlatform {
case 'latest': {
return { enabled: false, label: t('common.isLatestVersion') };
}
+ // snap / tar.gz / a runtime-less AppImage cannot replace themselves.
+ case 'unsupported': {
+ return {
+ click: () => shell.openExternal(DOWNLOAD_URL.default),
+ label: t('common.updateUnsupported'),
+ };
+ }
default: {
return {
click: () => this.app.updaterManager.checkForUpdates({ manual: true }),
diff --git a/apps/desktop/src/main/modules/updater/electronUpdaterEngine.ts b/apps/desktop/src/main/modules/updater/electronUpdaterEngine.ts
index 74059b07eaf..14aa0d265b3 100644
--- a/apps/desktop/src/main/modules/updater/electronUpdaterEngine.ts
+++ b/apps/desktop/src/main/modules/updater/electronUpdaterEngine.ts
@@ -36,6 +36,7 @@ export const electronUpdaterEngine: UpdateEngine = {
installOnQuit: () => {
autoUpdater.autoInstallOnAppQuit = true;
},
+ isActive: () => autoUpdater.isUpdaterActive(),
kind: 'electron-updater',
on: (event, listener) => {
autoUpdater.on(event, listener as (...args: any[]) => void);
diff --git a/apps/desktop/src/main/modules/updater/engine.ts b/apps/desktop/src/main/modules/updater/engine.ts
index a5192a61bbe..5c11bbae575 100644
--- a/apps/desktop/src/main/modules/updater/engine.ts
+++ b/apps/desktop/src/main/modules/updater/engine.ts
@@ -18,6 +18,12 @@ export interface UpdateEngine {
configure: (channel: UpdateChannel) => void;
downloadUpdate: () => Promise<unknown>;
installOnQuit: () => void;
+ /**
+ * Whether this installation can update itself. electron-updater has no
+ * updater for a snap, the plain `tar.gz` archive or an AppImage started
+ * without its runtime, and silently resolves `checkForUpdates()` to `null`.
+ */
+ isActive: () => boolean;
kind: UpdateEngineKind;
on: <K extends keyof UpdateEngineEvents>(
event: K,
diff --git a/apps/desktop/src/main/modules/updater/sparkleEngine.ts b/apps/desktop/src/main/modules/updater/sparkleEngine.ts
index 755154ccb84..64cc4c682fa 100644
--- a/apps/desktop/src/main/modules/updater/sparkleEngine.ts
+++ b/apps/desktop/src/main/modules/updater/sparkleEngine.ts
@@ -115,6 +115,8 @@ export class SparkleEngine extends EventEmitter<UpdateEngineEvents> implements U
installOnQuit = () => this.bridge.installUpdateOnQuit();
+ isActive = () => true;
+
quitAndInstall = () => this.bridge.installUpdateNow();
private handleEvent = (event: SparkleBridgeEvent) => {
diff --git a/locales/en-US/common.json b/locales/en-US/common.json
index 131555a2f43..21bf47567af 100644
--- a/locales/en-US/common.json
+++ b/locales/en-US/common.json
@@ -481,6 +481,8 @@
"unknownError": "Unknown error",
"update": "Update",
"updateAgent": "Update Agent Information",
+ "updateUnsupported.action": "Download Latest Version",
+ "updateUnsupported.desc": "This installation format cannot update itself. Download the latest build to upgrade.",
"upgradeVersion.action": "Upgrade",
"upgradeVersion.hasNew": "Update available",
"upgradeVersion.newVersion": "Update available: {{version}}",
diff --git a/locales/zh-CN/common.json b/locales/zh-CN/common.json
index 4ee0bdb3b55..768113ce284 100644
--- a/locales/zh-CN/common.json
+++ b/locales/zh-CN/common.json
@@ -481,6 +481,8 @@
"unknownError": "未知错误",
"update": "更新",
"updateAgent": "更新助理信息",
+ "updateUnsupported.action": "下载最新版本",
+ "updateUnsupported.desc": "当前安装格式不支持应用内更新,请下载最新版本进行升级。",
"upgradeVersion.action": "升级",
"upgradeVersion.hasNew": "有可用更新",
"upgradeVersion.newVersion": "可用更新版本:{{version}}",
diff --git a/packages/electron-client-ipc/src/types/update.ts b/packages/electron-client-ipc/src/types/update.ts
index b6a07cb1823..1af7bf194a8 100644
--- a/packages/electron-client-ipc/src/types/update.ts
+++ b/packages/electron-client-ipc/src/types/update.ts
@@ -38,7 +38,19 @@ export interface CoreUpdateStatus {
staged: string | null;
}
-export type UpdaterStage = 'idle' | 'checking' | 'downloading' | 'downloaded' | 'latest' | 'error';
+export type UpdaterStage =
+ | 'idle'
+ | 'checking'
+ | 'downloading'
+ | 'downloaded'
+ | 'latest'
+ | 'error'
+ /**
+ * The running installation cannot update itself — a snap (snapd owns the
+ * refresh), the plain `tar.gz` archive, or an AppImage started without its
+ * runtime. The only way forward is downloading a new build manually.
+ */
+ | 'unsupported';
export interface UpdaterState {
errorMessage?: string;
diff --git a/packages/locales/src/default/common.ts b/packages/locales/src/default/common.ts
index 895fcd11e0b..7fb82c6adc8 100644
--- a/packages/locales/src/default/common.ts
+++ b/packages/locales/src/default/common.ts
@@ -58,6 +58,9 @@ export default {
'checkForUpdates': 'Check for Updates',
'downloadingUpdate': 'Downloading {{percent}}%',
'restartToUpdate': 'Restart to Update',
+ 'updateUnsupported.action': 'Download Latest Version',
+ 'updateUnsupported.desc':
+ 'This installation format cannot update itself. Download the latest build to upgrade.',
'close': 'Close',
'cmdk.about': 'About',
'cmdk.aiModeEmptyState': 'Type your question above to start chatting with AI',
diff --git a/src/features/Settings/about/features/Version.tsx b/src/features/Settings/about/features/Version.tsx
index 7ea3c4ecc66..76219c5b699 100644
--- a/src/features/Settings/about/features/Version.tsx
+++ b/src/features/Settings/about/features/Version.tsx
@@ -4,14 +4,14 @@ import {
type UpdaterState,
useWatchBroadcast,
} from '@lobechat/electron-client-ipc';
-import { Block, Flexbox } from '@lobehub/ui';
+import { Block, Flexbox, Tooltip } from '@lobehub/ui';
import { Button, Skeleton, Tag } from '@lobehub/ui/base-ui';
import { createStaticStyles } from 'antd-style';
import { memo, Suspense, use, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { ProductLogo } from '@/components/Branding';
-import { CHANGELOG_URL, MANUAL_UPGRADE_URL, OFFICIAL_SITE } from '@/const/url';
+import { CHANGELOG_URL, DOWNLOAD_URL, MANUAL_UPGRADE_URL, OFFICIAL_SITE } from '@/const/url';
import { CURRENT_VERSION } from '@/const/version';
import { useNewVersion } from '@/features/User/UserPanel/useNewVersion';
import { autoUpdateService } from '@/services/electron/autoUpdate';
@@ -160,6 +160,17 @@ const Version = memo<{ mobile?: boolean }>(({ mobile }) => {
</Button>
);
}
+ // snap / tar.gz / a runtime-less AppImage cannot replace themselves, so the
+ // only honest action is sending the user to a fresh build.
+ case 'unsupported': {
+ return (
+ <Tooltip title={t('updateUnsupported.desc')}>
+ <a href={DOWNLOAD_URL.default} rel="noreferrer" style={{ flex: 1 }} target="_blank">
+ <Button block={mobile}>{t('updateUnsupported.action')}</Button>
+ </a>
+ </Tooltip>
+ );
+ }
default: {
return (
<Button block={mobile} onClick={() => void autoUpdateService.checkUpdate()}>