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): surface staged core OTA update instead of reporting up to date (#23018)

Mocha40a34cc3bb25
diff --git a/apps/desktop/src/main/menus/impls/linux.test.ts b/apps/desktop/src/main/menus/impls/linux.test.ts
index bf525ea8980..b4a2318abad 100644
--- a/apps/desktop/src/main/menus/impls/linux.test.ts
+++ b/apps/desktop/src/main/menus/impls/linux.test.ts
@@ -322,6 +322,38 @@ describe('LinuxMenu', () => {
expect(mockApp.updaterManager.installNow).toHaveBeenCalled();
});
+ // The shell updater only knows full releases: a downloaded core OTA update
+ // must not be hidden behind "already latest" right after a shell check.
+ it('does not claim the latest version while a core update is staged', () => {
+ mockApp.updaterManager.getUpdaterState = vi.fn(() => ({ stage: 'latest' })) as any;
+ (mockApp as any).coreUpdateManager = {
+ getStatus: vi.fn(() => ({ staged: '2.3.4-canary.1-core.45' })),
+ };
+ 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 === 'Check for Updates');
+
+ expect(item).toBeDefined();
+ expect(item.enabled).not.toBe(false);
+ item.click();
+ expect(mockApp.updaterManager.checkForUpdates).toHaveBeenCalledWith({ manual: true });
+ });
+
+ it('reports the latest version when no core update is staged', () => {
+ mockApp.updaterManager.getUpdaterState = vi.fn(() => ({ stage: 'latest' })) as any;
+ (mockApp as any).coreUpdateManager = { getStatus: vi.fn(() => ({ staged: null })) };
+ linuxMenu.buildAndSetAppMenu();
+
+ const template = (Menu.buildFromTemplate as any).mock.calls.at(-1)[0];
+ const fileMenu = template.find((item: any) => item.label === 'File');
+
+ expect(fileMenu.submenu.find((entry: any) => entry.label === 'Check for Updates')).toBe(
+ undefined,
+ );
+ });
+
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();
diff --git a/apps/desktop/src/main/menus/impls/linux.ts b/apps/desktop/src/main/menus/impls/linux.ts
index 80046afdabb..37935251674 100644
--- a/apps/desktop/src/main/menus/impls/linux.ts
+++ b/apps/desktop/src/main/menus/impls/linux.ts
@@ -285,7 +285,14 @@ export class LinuxMenu extends BaseMenuPlatform implements IMenuPlatform {
* 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();
+ const { stage: shellStage } = this.app.updaterManager.getUpdaterState();
+ // The shell updater only knows full releases; with a core OTA update already
+ // staged, offer the check again (it re-announces the staged update) instead
+ // of claiming the latest version.
+ const stage =
+ shellStage === 'latest' && this.app.coreUpdateManager.getStatus().staged
+ ? 'idle'
+ : shellStage;
switch (stage) {
case 'checking': {
diff --git a/apps/desktop/src/main/menus/impls/macOS.ts b/apps/desktop/src/main/menus/impls/macOS.ts
index 3fc00c2e40c..3509916bf41 100644
--- a/apps/desktop/src/main/menus/impls/macOS.ts
+++ b/apps/desktop/src/main/menus/impls/macOS.ts
@@ -455,7 +455,14 @@ export class MacOSMenu extends BaseMenuPlatform implements IMenuPlatform {
}
private getUpdateMenuItem(t: (key: string, opts?: any) => string): MenuItemConstructorOptions {
- const { stage } = this.app.updaterManager.getUpdaterState();
+ const { stage: shellStage } = this.app.updaterManager.getUpdaterState();
+ // The shell updater only knows full releases; with a core OTA update already
+ // staged, offer the check again (it re-announces the staged update) instead
+ // of claiming the latest version.
+ const stage =
+ shellStage === 'latest' && this.app.coreUpdateManager.getStatus().staged
+ ? 'idle'
+ : shellStage;
switch (stage) {
case 'checking': {
diff --git a/apps/desktop/src/main/menus/impls/windows.ts b/apps/desktop/src/main/menus/impls/windows.ts
index fcd8bc2aa88..166c74574c0 100644
--- a/apps/desktop/src/main/menus/impls/windows.ts
+++ b/apps/desktop/src/main/menus/impls/windows.ts
@@ -266,7 +266,14 @@ export class WindowsMenu extends BaseMenuPlatform implements IMenuPlatform {
}
private getUpdateMenuItem(t: (key: string, opts?: any) => string): MenuItemConstructorOptions {
- const { stage } = this.app.updaterManager.getUpdaterState();
+ const { stage: shellStage } = this.app.updaterManager.getUpdaterState();
+ // The shell updater only knows full releases; with a core OTA update already
+ // staged, offer the check again (it re-announces the staged update) instead
+ // of claiming the latest version.
+ const stage =
+ shellStage === 'latest' && this.app.coreUpdateManager.getStatus().staged
+ ? 'idle'
+ : shellStage;
switch (stage) {
case 'checking': {
diff --git a/src/features/Electron/updater/useStagedCoreUpdate.test.ts b/src/features/Electron/updater/useStagedCoreUpdate.test.ts
new file mode 100644
index 00000000000..33362343187
--- /dev/null
+++ b/src/features/Electron/updater/useStagedCoreUpdate.test.ts
@@ -0,0 +1,106 @@
+import type { CoreUpdateStatus } from '@lobechat/electron-client-ipc';
+import { act, renderHook, waitFor } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { useStagedCoreUpdate } from './useStagedCoreUpdate';
+
+const handlers = new Map<string, (data: any) => void>();
+
+vi.mock('@lobechat/electron-client-ipc', () => ({
+ useWatchBroadcast: (event: string, handler: (data: any) => void) => {
+ handlers.set(event, handler);
+ },
+}));
+
+const getStatus = vi.fn<() => Promise<CoreUpdateStatus>>();
+
+vi.mock('@/services/electron/rendererOta', () => ({
+ rendererOtaService: { getStatus: () => getStatus() },
+}));
+
+const status = (patch: Partial<CoreUpdateStatus>): CoreUpdateStatus => ({
+ applyMode: null,
+ current: null,
+ disabledReasons: [],
+ enabled: true,
+ lastCheckAt: null,
+ lastError: null,
+ needsFullRelease: false,
+ running: '2.3.4-canary.1-core.38',
+ staged: null,
+ ...patch,
+});
+
+const emit = (event: string, data?: unknown) => act(() => handlers.get(event)?.(data));
+
+beforeEach(() => {
+ handlers.clear();
+ getStatus.mockReset();
+});
+
+describe('useStagedCoreUpdate', () => {
+ it('reports a core update staged before the page mounted', async () => {
+ getStatus.mockResolvedValue(
+ status({ applyMode: 'relaunch', staged: '2.3.4-canary.1-core.45' }),
+ );
+
+ const { result } = renderHook(() => useStagedCoreUpdate(true));
+
+ await waitFor(() =>
+ expect(result.current).toEqual({ applyMode: 'relaunch', version: '2.3.4-canary.1-core.45' }),
+ );
+ });
+
+ it('picks up a core update staged while the page is open, ignoring full app updates', async () => {
+ getStatus.mockResolvedValue(status({}));
+ const { result } = renderHook(() => useStagedCoreUpdate(true));
+ await waitFor(() => expect(getStatus).toHaveBeenCalled());
+
+ emit('updateReady', { kind: 'app', version: '2.3.5' });
+ expect(result.current).toBeNull();
+
+ emit('updateReady', { kind: 'core-reload', version: '2.3.4-canary.1-core.46' });
+ expect(result.current).toEqual({ applyMode: 'reload', version: '2.3.4-canary.1-core.46' });
+ });
+
+ it('keeps a broadcast update when an older status read resolves afterwards', async () => {
+ let resolveStatus!: (value: CoreUpdateStatus) => void;
+ getStatus.mockReturnValue(new Promise((resolve) => (resolveStatus = resolve)));
+ const { result } = renderHook(() => useStagedCoreUpdate(true));
+
+ emit('updateReady', { kind: 'core-relaunch', version: '2.3.4-canary.1-core.45' });
+ await act(async () => resolveStatus(status({})));
+
+ expect(result.current).toEqual({ applyMode: 'relaunch', version: '2.3.4-canary.1-core.45' });
+ });
+
+ it('clears the staged update once that version is applied', async () => {
+ getStatus.mockResolvedValue(status({ applyMode: 'reload', staged: '2.3.4-canary.1-core.45' }));
+ const { result } = renderHook(() => useStagedCoreUpdate(true));
+ await waitFor(() => expect(result.current).not.toBeNull());
+
+ emit('coreUpdateApplied', '2.3.4-canary.1-core.44');
+ expect(result.current).not.toBeNull();
+
+ emit('coreUpdateApplied', '2.3.4-canary.1-core.45');
+ expect(result.current).toBeNull();
+ });
+
+ it('drops the staged update when the update channel changes', async () => {
+ getStatus.mockResolvedValue(
+ status({ applyMode: 'relaunch', staged: '2.3.4-canary.1-core.45' }),
+ );
+ const { result } = renderHook(() => useStagedCoreUpdate(true));
+ await waitFor(() => expect(result.current).not.toBeNull());
+
+ emit('updateChannelChanged', 'stable');
+ expect(result.current).toBeNull();
+ });
+
+ it('does not query core OTA status outside the desktop app', () => {
+ const { result } = renderHook(() => useStagedCoreUpdate(false));
+
+ expect(getStatus).not.toHaveBeenCalled();
+ expect(result.current).toBeNull();
+ });
+});
diff --git a/src/features/Electron/updater/useStagedCoreUpdate.ts b/src/features/Electron/updater/useStagedCoreUpdate.ts
new file mode 100644
index 00000000000..9496600e443
--- /dev/null
+++ b/src/features/Electron/updater/useStagedCoreUpdate.ts
@@ -0,0 +1,60 @@
+import { useWatchBroadcast } from '@lobechat/electron-client-ipc';
+import { useEffect, useRef, useState } from 'react';
+
+import { rendererOtaService } from '@/services/electron/rendererOta';
+
+export interface StagedCoreUpdate {
+ applyMode: 'reload' | 'relaunch';
+ version: string;
+}
+
+/**
+ * Tracks the core (OTA) update that is downloaded and waiting to be applied.
+ * The shell updater only knows about full app releases, so anything that
+ * reports "up to date" from it must also consult this state.
+ */
+export const useStagedCoreUpdate = (enabled: boolean): StagedCoreUpdate | null => {
+ const [staged, setStaged] = useState<StagedCoreUpdate | null>(null);
+ // A broadcast is newer than an in-flight status read; never let the read overwrite it.
+ const receivedEvent = useRef(false);
+
+ useEffect(() => {
+ if (!enabled) return;
+ let active = true;
+ rendererOtaService
+ .getStatus()
+ .then((status) => {
+ if (!active || receivedEvent.current) return;
+ setStaged(
+ status.staged && status.applyMode
+ ? { applyMode: status.applyMode, version: status.staged }
+ : null,
+ );
+ })
+ .catch(console.error);
+ return () => {
+ active = false;
+ };
+ }, [enabled]);
+
+ useWatchBroadcast('updateReady', (info) => {
+ if (info.kind !== 'core-reload' && info.kind !== 'core-relaunch') return;
+ receivedEvent.current = true;
+ setStaged({
+ applyMode: info.kind === 'core-relaunch' ? 'relaunch' : 'reload',
+ version: info.version,
+ });
+ });
+
+ useWatchBroadcast('coreUpdateApplied', (version) => {
+ receivedEvent.current = true;
+ setStaged((current) => (current?.version === version ? null : current));
+ });
+
+ useWatchBroadcast('updateChannelChanged', () => {
+ receivedEvent.current = true;
+ setStaged(null);
+ });
+
+ return staged;
+};
diff --git a/src/features/Settings/about/features/Version.test.tsx b/src/features/Settings/about/features/Version.test.tsx
new file mode 100644
index 00000000000..a38e2e2e9a3
--- /dev/null
+++ b/src/features/Settings/about/features/Version.test.tsx
@@ -0,0 +1,97 @@
+import type { CoreUpdateStatus, UpdaterState } from '@lobechat/electron-client-ipc';
+import { fireEvent, render, screen } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import Version from './Version';
+
+const autoUpdateService = vi.hoisted(() => ({
+ checkUpdate: vi.fn(),
+ getBuildChannel: vi.fn(),
+ getUpdaterState: vi.fn(),
+ installNow: vi.fn(),
+}));
+const rendererOtaService = vi.hoisted(() => ({
+ applyNow: vi.fn(),
+ getStatus: vi.fn(),
+}));
+
+vi.mock('@lobechat/electron-client-ipc', () => ({
+ getElectronIpc: () => ({}),
+ useWatchBroadcast: () => {},
+}));
+vi.mock('@/services/electron/autoUpdate', () => ({ autoUpdateService }));
+vi.mock('@/services/electron/rendererOta', () => ({ rendererOtaService }));
+vi.mock('@/components/Branding', () => ({ ProductLogo: () => null }));
+vi.mock('@/features/User/UserPanel/useNewVersion', () => ({ useNewVersion: () => false }));
+vi.mock('@/store/global', () => ({
+ useGlobalStore: (selector: (s: unknown) => unknown) =>
+ selector({
+ latestVersion: undefined,
+ serverVersion: undefined,
+ useCheckLatestVersion: () => ({}),
+ useCheckServerVersion: () => {},
+ }),
+}));
+vi.mock('@/store/serverConfig', () => ({
+ featureFlagsSelectors: () => ({ enableCheckUpdates: false }),
+ useServerConfigStore: (selector: (s: unknown) => unknown) =>
+ selector({ canAccessDevDock: false }),
+}));
+
+const coreStatus = (patch: Partial<CoreUpdateStatus> = {}): CoreUpdateStatus => ({
+ applyMode: null,
+ current: '2.3.4-canary.1-core.38',
+ disabledReasons: [],
+ enabled: true,
+ lastCheckAt: null,
+ lastError: null,
+ needsFullRelease: false,
+ running: '2.3.4-canary.1-core.38',
+ staged: null,
+ ...patch,
+});
+
+const setup = (shell: UpdaterState, core: CoreUpdateStatus) => {
+ autoUpdateService.getUpdaterState.mockResolvedValue(shell);
+ autoUpdateService.getBuildChannel.mockResolvedValue('canary');
+ rendererOtaService.getStatus.mockResolvedValue(core);
+ rendererOtaService.applyNow.mockResolvedValue(true);
+ render(<Version />);
+};
+
+beforeEach(() => {
+ vi.clearAllMocks();
+});
+
+describe('About › Version update action (desktop)', () => {
+ it('offers to apply a staged core update instead of claiming the app is up to date', async () => {
+ setup(
+ { stage: 'latest' },
+ coreStatus({ applyMode: 'relaunch', staged: '2.3.4-canary.1-core.45' }),
+ );
+
+ fireEvent.click(await screen.findByRole('button', { name: 'restartToUpdate' }));
+
+ expect(screen.queryByText('alreadyUpToDate')).toBeNull();
+ expect(rendererOtaService.applyNow).toHaveBeenCalledTimes(1);
+ expect(autoUpdateService.installNow).not.toHaveBeenCalled();
+ });
+
+ it('still reports up to date when neither the shell nor the core has an update', async () => {
+ setup({ stage: 'latest' }, coreStatus());
+
+ expect(await screen.findByRole('button', { name: 'alreadyUpToDate' })).toBeDisabled();
+ });
+
+ it('lets a downloaded full app release take precedence over a staged core update', async () => {
+ setup(
+ { stage: 'downloaded' },
+ coreStatus({ applyMode: 'relaunch', staged: '2.3.4-canary.1-core.45' }),
+ );
+
+ fireEvent.click(await screen.findByRole('button', { name: 'restartToUpdate' }));
+
+ expect(autoUpdateService.installNow).toHaveBeenCalledTimes(1);
+ expect(rendererOtaService.applyNow).not.toHaveBeenCalled();
+ });
+});
diff --git a/src/features/Settings/about/features/Version.tsx b/src/features/Settings/about/features/Version.tsx
index dc7f07d1d56..6deb30645e1 100644
--- a/src/features/Settings/about/features/Version.tsx
+++ b/src/features/Settings/about/features/Version.tsx
@@ -4,7 +4,7 @@ import {
type UpdaterState,
useWatchBroadcast,
} from '@lobechat/electron-client-ipc';
-import { Block, Button, Flexbox, Tag, Tooltip } from '@lobehub/ui';
+import { Block, Button, Flexbox, Tag, toast, Tooltip } from '@lobehub/ui';
import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
import * as stylex from '@stylexjs/stylex';
import { memo, useEffect, useMemo, useRef, useState } from 'react';
@@ -13,6 +13,9 @@ import { useTranslation } from 'react-i18next';
import { ProductLogo } from '@/components/Branding';
import { CHANGELOG_URL, DOWNLOAD_URL, MANUAL_UPGRADE_URL, OFFICIAL_SITE } from '@/const/url';
import { CURRENT_VERSION } from '@/const/version';
+import { applyCoreUpdate } from '@/features/Electron/updater/applyCoreUpdate';
+import { formatCoreVersion } from '@/features/Electron/updater/coreVersion';
+import { useStagedCoreUpdate } from '@/features/Electron/updater/useStagedCoreUpdate';
import { useNewVersion } from '@/features/User/UserPanel/useNewVersion';
import { autoUpdateService } from '@/services/electron/autoUpdate';
import { rendererOtaService } from '@/services/electron/rendererOta';
@@ -60,7 +63,7 @@ const Version = memo<{ mobile?: boolean }>(({ mobile }) => {
s.useCheckServerVersion,
s.useCheckLatestVersion,
]);
- const { t } = useTranslation(['common', 'setting']);
+ const { t } = useTranslation(['common', 'setting', 'electron']);
useCheckServerVersion();
@@ -81,6 +84,8 @@ const Version = memo<{ mobile?: boolean }>(({ mobile }) => {
const [updaterState, setUpdaterState] = useState<UpdaterState>({ stage: 'idle' });
const [buildChannel, setBuildChannel] = useState<string | null>(null);
+ const stagedCoreUpdate = useStagedCoreUpdate(isDesktop);
+ const [isApplyingCoreUpdate, setIsApplyingCoreUpdate] = useState(false);
useEffect(() => {
if (!isDesktop) return;
@@ -96,6 +101,17 @@ const Version = memo<{ mobile?: boolean }>(({ mobile }) => {
setUpdaterState(state);
});
+ useWatchBroadcast('coreUpdateDeferred', () => setIsApplyingCoreUpdate(false));
+
+ const applyStagedCoreUpdate = async () => {
+ setIsApplyingCoreUpdate(true);
+ // On success the app relaunches or the window reloads, so keep the loading state.
+ const applied = await applyCoreUpdate(() =>
+ toast.error(t('updater.rendererUpdateError', { ns: 'electron' })),
+ );
+ if (!applied) setIsApplyingCoreUpdate(false);
+ };
+
const devDockGestureEnabled = import.meta.env.PROD && canAccessDevDock;
const handleVersionClick = () => {
@@ -130,6 +146,30 @@ const Version = memo<{ mobile?: boolean }>(({ mobile }) => {
const { stage, progress } = updaterState;
+ // The shell updater only knows full app releases: once it settles on
+ // "up to date" (or fails, or cannot self-update), a downloaded core OTA
+ // update is still pending and must not be hidden behind "Already Up to Date".
+ // An in-flight or downloaded app release still takes precedence.
+ if (
+ stagedCoreUpdate &&
+ stage !== 'checking' &&
+ stage !== 'downloading' &&
+ stage !== 'downloaded'
+ ) {
+ return (
+ <Button
+ block={mobile}
+ loading={isApplyingCoreUpdate}
+ type="primary"
+ onClick={() => void applyStagedCoreUpdate()}
+ >
+ {stagedCoreUpdate.applyMode === 'relaunch'
+ ? t('restartToUpdate')
+ : t('updater.upgradeNow', { ns: 'electron' })}
+ </Button>
+ );
+ }
+
switch (stage) {
case 'checking': {
return (
@@ -229,6 +269,13 @@ const Version = memo<{ mobile?: boolean }>(({ mobile }) => {
{t('upgradeVersion.newVersion', { version: `v${latestVersion}` })}
</Tag>
)}
+ {stagedCoreUpdate && (
+ <Tag color={'info'}>
+ {t('upgradeVersion.newVersion', {
+ version: formatCoreVersion(stagedCoreUpdate.version),
+ })}
+ </Tag>
+ )}
</Flexbox>
</Flexbox>
</Flexbox>