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): stop update prompt from resurfacing after install-later, polish card (#16317)

Innei4f0dbfb91459
diff --git a/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts b/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts
index 053b89e4200..c05c350d743 100644
--- a/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts
+++ b/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts
@@ -8,6 +8,7 @@ import type {
import { app as electronApp } from 'electron';
import log from 'electron-log';
import { autoUpdater } from 'electron-updater';
+import semver from 'semver';
import { isDev, isWindows } from '@/const/env';
import { getDesktopEnv } from '@/env';
@@ -33,6 +34,14 @@ export class UpdaterManager {
private activeGeneration: number = 0;
/** Whether a recheck is needed after the current check completes */
private pendingRecheck: boolean = false;
+ /**
+ * Version the user acknowledged with "install later" in the current process.
+ * While set, equal-version update-available/downloaded events are processed
+ * for menu state but never re-broadcast to the renderer, so the prompt does
+ * not reappear within the session. Cleared when a strictly newer version
+ * arrives (or on channel switch).
+ */
+ private installLaterVersion: string | null = null;
private stage: UpdaterStage = 'idle';
private latestUpdateInfo: UpdateInfo | null = null;
@@ -149,6 +158,8 @@ export class UpdaterManager {
autoUpdater.allowPrerelease = channel !== 'stable';
this.configureUpdateProvider();
+ this.installLaterVersion = null;
+
this.mainWindow.broadcast('updateChannelChanged', channel);
// Invalidate any in-flight check and schedule a recheck
@@ -292,6 +303,10 @@ export class UpdaterManager {
logger.info('Update will be installed on next restart');
autoUpdater.autoInstallOnAppQuit = true;
+ if (this.latestUpdateInfo?.version) {
+ this.installLaterVersion = this.latestUpdateInfo.version;
+ logger.info(`Suppressing further prompts for version ${this.installLaterVersion}`);
+ }
this.mainWindow.broadcast('updateWillInstallLater');
};
@@ -442,8 +457,17 @@ export class UpdaterManager {
if (this.isStaleCheck()) return;
+ this.maybeClearInstallLaterGuard(info.version);
+
this.updateAvailable = true;
+ if (this.installLaterVersion) {
+ logger.info(
+ `Skipping auto-download β€” install-later acknowledged for v${this.installLaterVersion}, incoming v${info.version}`,
+ );
+ return;
+ }
+
// Always auto-download
logger.info('Update found, starting download automatically...');
this.setStage('downloading', { updateInfo: info });
@@ -497,13 +521,42 @@ export class UpdaterManager {
autoUpdater.on('update-downloaded', (info) => {
logger.info(`Update downloaded: ${info.version}`);
this.downloading = false;
+
+ this.maybeClearInstallLaterGuard(info.version);
+
this.setStage('downloaded', { updateInfo: info });
+
+ if (this.installLaterVersion) {
+ logger.info(
+ `Not re-broadcasting updateDownloaded β€” install-later acknowledged for v${this.installLaterVersion}, incoming v${info.version}`,
+ );
+ return;
+ }
+
this.mainWindow.broadcast('updateDownloaded', info);
});
logger.debug('Updater events registered');
}
+ /**
+ * Clear the install-later guard when a strictly newer version arrives.
+ * Equal or older versions keep the guard so the prompt stays suppressed.
+ */
+ private maybeClearInstallLaterGuard(incomingVersion: string | undefined) {
+ if (!this.installLaterVersion || !incomingVersion) return;
+ try {
+ if (semver.gt(incomingVersion, this.installLaterVersion)) {
+ logger.info(
+ `Clearing install-later guard (was v${this.installLaterVersion}, incoming v${incomingVersion})`,
+ );
+ this.installLaterVersion = null;
+ }
+ } catch (error) {
+ logger.warn('Failed to compare versions for install-later guard:', error);
+ }
+ }
+
/** Check if the current active check has been superseded by a channel switch */
private isStaleCheck(): boolean {
if (this.activeGeneration !== this.checkGeneration) {
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 8ee116db48a..2c86b8049d8 100644
--- a/apps/desktop/src/main/core/infrastructure/__tests__/UpdaterManager.test.ts
+++ b/apps/desktop/src/main/core/infrastructure/__tests__/UpdaterManager.test.ts
@@ -420,6 +420,92 @@ describe('UpdaterManager', () => {
});
});
+ describe('install-later session guard', () => {
+ beforeEach(async () => {
+ await updaterManager.initialize();
+ vi.mocked(autoUpdater.downloadUpdate).mockResolvedValue([] as any);
+ });
+
+ const fireDownloaded = (version: string) => {
+ registeredEvents.get('update-downloaded')?.({ version });
+ };
+ const fireAvailable = (version: string) => {
+ registeredEvents.get('update-available')?.({ version });
+ };
+
+ it('suppresses re-broadcast of updateDownloaded for the install-later version', () => {
+ fireDownloaded('2.2.6');
+ expect(mockBroadcast).toHaveBeenCalledWith(
+ 'updateDownloaded',
+ expect.objectContaining({ version: '2.2.6' }),
+ );
+
+ updaterManager.installLater();
+
+ mockBroadcast.mockClear();
+ fireDownloaded('2.2.6');
+
+ expect(mockBroadcast).not.toHaveBeenCalledWith('updateDownloaded', expect.anything());
+ expect(mockBroadcast).toHaveBeenCalledWith(
+ 'updaterStateChanged',
+ expect.objectContaining({ stage: 'downloaded' }),
+ );
+ });
+
+ it('skips auto-download on update-available for the install-later version', () => {
+ fireDownloaded('2.2.6');
+ updaterManager.installLater();
+
+ vi.mocked(autoUpdater.downloadUpdate).mockClear();
+
+ fireAvailable('2.2.6');
+
+ expect(autoUpdater.downloadUpdate).not.toHaveBeenCalled();
+ });
+
+ it('clears the guard and re-broadcasts when a newer version arrives', () => {
+ fireDownloaded('2.2.6');
+ updaterManager.installLater();
+ mockBroadcast.mockClear();
+
+ fireAvailable('2.2.7');
+ fireDownloaded('2.2.7');
+
+ expect(mockBroadcast).toHaveBeenCalledWith(
+ 'updateDownloaded',
+ expect.objectContaining({ version: '2.2.7' }),
+ );
+ });
+
+ it('keeps the guard when an older version arrives', () => {
+ fireDownloaded('2.2.6');
+ updaterManager.installLater();
+ mockBroadcast.mockClear();
+
+ fireDownloaded('2.2.5');
+
+ expect(mockBroadcast).not.toHaveBeenCalledWith(
+ 'updateDownloaded',
+ expect.objectContaining({ version: '2.2.5' }),
+ );
+ });
+
+ it('clears the guard on channel switch', () => {
+ fireDownloaded('2.2.6');
+ updaterManager.installLater();
+
+ updaterManager.switchChannel('canary');
+
+ mockBroadcast.mockClear();
+ fireDownloaded('2.2.6');
+
+ expect(mockBroadcast).toHaveBeenCalledWith(
+ 'updateDownloaded',
+ expect.objectContaining({ version: '2.2.6' }),
+ );
+ });
+ });
+
describe('event handlers', () => {
beforeEach(async () => {
await updaterManager.initialize();
diff --git a/src/features/Electron/updater/UpdateNotification.tsx b/src/features/Electron/updater/UpdateNotification.tsx
index 455b132f6a8..482b8a1d79d 100644
--- a/src/features/Electron/updater/UpdateNotification.tsx
+++ b/src/features/Electron/updater/UpdateNotification.tsx
@@ -1,191 +1,268 @@
-import { type UpdateInfo } from '@lobechat/electron-client-ipc';
-import { useWatchBroadcast } from '@lobechat/electron-client-ipc';
-import { Button, Flexbox, Icon, Markdown } from '@lobehub/ui';
-import { Button as BaseButton, createModal, useModalContext } from '@lobehub/ui/base-ui';
-import { createStaticStyles, cssVar } from 'antd-style';
-import { t } from 'i18next';
-import { CircleFadingArrowUp } from 'lucide-react';
-import React, { memo, useState } from 'react';
+'use client';
+
+import { type UpdateInfo, useWatchBroadcast } from '@lobechat/electron-client-ipc';
+import { Icon } from '@lobehub/ui';
+import { Button as BaseButton } from '@lobehub/ui/base-ui';
+import { createStaticStyles } from 'antd-style';
+import { CheckCircle2, CircleFadingArrowUp, X } from 'lucide-react';
+import { AnimatePresence, m } from 'motion/react';
+import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { usePlatform } from '@/hooks/usePlatform';
import { autoUpdateService } from '@/services/electron/autoUpdate';
+const MAC_CARD_RADIUS = 10;
+const DEFAULT_CARD_RADIUS = 8;
+const ENTER_EXIT_EASE = [0.16, 1, 0.3, 1] as const;
+
+type ViewState = 'prompt' | 'confirming' | null;
+
const styles = createStaticStyles(({ css, cssVar }) => ({
+ card: css`
+ pointer-events: auto;
+
+ overflow: hidden;
+
+ min-width: 360px;
+
+ color: ${cssVar.colorText};
+
+ background: color-mix(in srgb, ${cssVar.colorBgElevated} 85%, transparent);
+ backdrop-filter: blur(20px) saturate(1.5);
+ box-shadow: ${cssVar.boxShadowSecondary};
+ `,
+ closeButton: css`
+ cursor: pointer;
+
+ display: inline-flex;
+ flex-shrink: 0;
+ align-items: center;
+ justify-content: center;
+
+ width: 24px;
+ height: 24px;
+ border: 0;
+ border-radius: 6px;
+
+ color: ${cssVar.colorTextTertiary};
+
+ background: transparent;
+
+ transition:
+ background 120ms ease,
+ color 120ms ease;
+
+ &:hover {
+ color: ${cssVar.colorText};
+ background: ${cssVar.colorFillTertiary};
+ }
+ `,
container: css`
+ pointer-events: none;
+
position: fixed;
z-index: 1000;
inset-block-end: 16px;
inset-inline-start: 16px;
`,
+ confirmRow: css`
+ display: flex;
+ gap: 12px;
+ align-items: center;
- releaseNote: css`
- overflow: scroll;
+ padding-block: 10px;
+ padding-inline: 12px;
+ `,
+ confirmSub: css`
+ display: block;
+ margin-block-start: 2px;
+ font-size: 11px;
+ color: ${cssVar.colorTextTertiary};
+ `,
+ confirmText: css`
+ flex: 1;
+ font-size: 13px;
+ line-height: 1.3;
+ color: ${cssVar.colorText};
+ `,
+ iconAccent: css`
+ display: flex;
+ flex-shrink: 0;
+ align-items: center;
+ justify-content: center;
- max-height: 300px;
- padding: 8px;
+ width: 28px;
+ height: 28px;
border-radius: 8px;
- background: ${cssVar.colorFillQuaternary};
+ color: ${cssVar.colorSuccess};
+
+ background: color-mix(in srgb, ${cssVar.colorSuccess} 16%, transparent);
`,
-}));
+ iconNeutral: css`
+ display: flex;
+ flex-shrink: 0;
+ align-items: center;
+ justify-content: center;
-interface UpdateDetailContentProps {
- updateInfo: UpdateInfo;
-}
+ width: 28px;
+ height: 28px;
+ border-radius: 8px;
-const UpdateDetailContent = memo<UpdateDetailContentProps>(({ updateInfo }) => {
- const { t: tElectron } = useTranslation('electron');
- const { close } = useModalContext();
- const [isInstalling, setIsInstalling] = useState(false);
+ color: ${cssVar.colorTextSecondary};
- return (
- <Flexbox gap={12} style={{ maxWidth: 480 }}>
- <div style={{ color: cssVar.colorTextSecondary, fontSize: 12 }}>{updateInfo.version}</div>
- {updateInfo.releaseNotes &&
- (typeof updateInfo.releaseNotes === 'string' ? (
- <div className={styles.releaseNote}>
- <Markdown>{updateInfo.releaseNotes}</Markdown>
- </div>
- ) : (
- <div className={styles.releaseNote}>
- {updateInfo.releaseNotes.map((note) => (
- <Markdown key={note.version}>{note.note ?? ''}</Markdown>
- ))}
- </div>
- ))}
- <Flexbox horizontal gap={8} justify={'flex-end'}>
- <BaseButton
- size={'small'}
- onClick={() => {
- autoUpdateService.installLater();
- close();
- }}
- >
- {tElectron('updater.installLater')}
- </BaseButton>
- <BaseButton
- loading={isInstalling}
- size={'small'}
- type={'primary'}
- onClick={() => {
- setIsInstalling(true);
- autoUpdateService.installNow();
- }}
- >
- {tElectron('updater.restartAndInstall')}
- </BaseButton>
- </Flexbox>
- </Flexbox>
- );
-});
+ background: ${cssVar.colorFillTertiary};
+ `,
+ labelStack: css`
+ display: flex;
+ flex: 1;
+ flex-direction: column;
+ `,
+ promptActions: css`
+ display: flex;
+ gap: 4px;
+ align-items: center;
+ `,
+ promptRow: css`
+ display: flex;
+ gap: 12px;
+ align-items: center;
-UpdateDetailContent.displayName = 'UpdateDetailContent';
+ padding-block: 10px;
+ padding-inline: 12px;
+ `,
+ title: css`
+ font-size: 13px;
+ font-weight: 500;
+ line-height: 1.2;
+ color: ${cssVar.colorText};
+ `,
+ version: css`
+ margin-block-start: 2px;
-const openUpdateDetailModal = (updateInfo: UpdateInfo) =>
- createModal({
- content: <UpdateDetailContent updateInfo={updateInfo} />,
- footer: null,
- maskClosable: true,
- title: t('updater.updateReady', { ns: 'electron' }),
- width: 520,
- });
+ font-size: 11px;
+ font-variant-numeric: tabular-nums;
+ color: ${cssVar.colorTextTertiary};
+ letter-spacing: -0.01em;
+ `,
+}));
-export const UpdateNotification: React.FC = () => {
+export const UpdateNotification = memo(() => {
const { t: tElectron } = useTranslation('electron');
- const [updateAvailable, setUpdateAvailable] = useState(false);
- const [updateDownloaded, setUpdateDownloaded] = useState(false);
+ const { isMacOS } = usePlatform();
+
+ const [view, setView] = useState<ViewState>(null);
const [updateInfo, setUpdateInfo] = useState<UpdateInfo | null>(null);
- const [installConfirmMode, setInstallConfirmMode] = useState<
- 'unconfirm' | 'installLater' | 'installNow' | null
- >('unconfirm');
const [isInstalling, setIsInstalling] = useState(false);
useWatchBroadcast('updateDownloaded', (info: UpdateInfo) => {
setUpdateInfo(info);
- setUpdateDownloaded(true);
- setUpdateAvailable(false);
- setInstallConfirmMode('unconfirm');
+ setIsInstalling(false);
+ setView('prompt');
});
useWatchBroadcast('updateWillInstallLater', () => {
- setInstallConfirmMode('installLater');
-
- setTimeout(() => setInstallConfirmMode(null), 5000);
+ setView('confirming');
});
- if (!updateDownloaded && !updateAvailable) return null;
-
- if (installConfirmMode === 'installLater') {
- return (
- <div
- style={{
- backgroundColor: cssVar.colorBgElevated,
- borderRadius: cssVar.borderRadius,
- bottom: 20,
- boxShadow: cssVar.boxShadow,
- color: cssVar.colorText,
- left: 16,
- padding: '10px 16px',
- position: 'fixed',
- zIndex: 1000,
- }}
- >
- {tElectron('updater.willInstallLater')}
- </div>
- );
- }
-
- if (installConfirmMode === 'unconfirm')
- return (
- <div className={styles.container}>
- <div
- style={{
- alignItems: 'center',
- background: cssVar.colorBgElevated,
- border: `1px solid ${cssVar.colorBorderSecondary}`,
- borderRadius: 12,
- boxShadow: cssVar.boxShadow,
- color: cssVar.colorText,
- display: 'flex',
- gap: 8,
- padding: '8px 10px',
- }}
+ const cardRadius = isMacOS ? MAC_CARD_RADIUS : DEFAULT_CARD_RADIUS;
+
+ const handleInstallLater = () => {
+ autoUpdateService.installLater();
+ };
+
+ const handleInstallNow = () => {
+ setIsInstalling(true);
+ autoUpdateService.installNow();
+ };
+
+ const handleDismiss = () => {
+ setView(null);
+ };
+
+ return (
+ <AnimatePresence>
+ {view !== null && (
+ <m.div
+ animate={{ opacity: 1, scale: 1, y: 0 }}
+ aria-live="polite"
+ className={styles.container}
+ exit={{ opacity: 0, scale: 0.96, y: 8 }}
+ initial={{ opacity: 0, scale: 0.96, y: 8 }}
+ transition={{ duration: 0.2, ease: ENTER_EXIT_EASE }}
>
- <Icon icon={CircleFadingArrowUp} style={{ fontSize: 16 }} />
- <div
- style={{ cursor: 'pointer', fontSize: 12 }}
- onClick={() => {
- if (updateInfo) openUpdateDetailModal(updateInfo);
- }}
- >
- {tElectron('updater.updateReady')}
- {updateInfo?.version ? ` Β· ${updateInfo.version}` : ''}
- </div>
- <div style={{ flex: 1 }} />
- <Button
- size="small"
- type="text"
- onClick={() => {
- autoUpdateService.installLater();
- }}
- >
- {tElectron('updater.later')}
- </Button>
-
- <Button
- loading={isInstalling}
- size="small"
- type="primary"
- onClick={() => {
- setIsInstalling(true);
- autoUpdateService.installNow();
- }}
- >
- {tElectron('updater.upgradeNow')}
- </Button>
- </div>
- </div>
- );
-
- return null;
-};
+ <m.div layout className={styles.card} style={{ borderRadius: cardRadius }}>
+ <AnimatePresence initial={false} mode="wait">
+ {view === 'prompt' && (
+ <m.div
+ animate={{ opacity: 1 }}
+ exit={{ opacity: 0 }}
+ initial={{ opacity: 0 }}
+ key="prompt"
+ transition={{ duration: 0.16 }}
+ >
+ <div className={styles.promptRow}>
+ <div className={styles.iconNeutral}>
+ <Icon icon={CircleFadingArrowUp} style={{ fontSize: 16 }} />
+ </div>
+ <div className={styles.labelStack}>
+ <span className={styles.title}>{tElectron('updater.updateReady')}</span>
+ {updateInfo?.version && (
+ <span className={styles.version}>v{updateInfo.version}</span>
+ )}
+ </div>
+ <div className={styles.promptActions}>
+ <BaseButton size="small" onClick={handleInstallLater}>
+ {tElectron('updater.later')}
+ </BaseButton>
+ <BaseButton
+ loading={isInstalling}
+ size="small"
+ type="primary"
+ onClick={handleInstallNow}
+ >
+ {tElectron('updater.upgradeNow')}
+ </BaseButton>
+ </div>
+ </div>
+ </m.div>
+ )}
+ {view === 'confirming' && (
+ <m.div
+ animate={{ opacity: 1 }}
+ exit={{ opacity: 0 }}
+ initial={{ opacity: 0 }}
+ key="confirming"
+ transition={{ duration: 0.16 }}
+ >
+ <div className={styles.confirmRow}>
+ <div className={styles.iconAccent}>
+ <Icon icon={CheckCircle2} style={{ fontSize: 16 }} />
+ </div>
+ <div className={styles.confirmText}>
+ {tElectron('updater.willInstallLater')}
+ {updateInfo?.version && (
+ <span className={styles.confirmSub}>v{updateInfo.version}</span>
+ )}
+ </div>
+ <button
+ aria-label="Dismiss"
+ className={styles.closeButton}
+ type="button"
+ onClick={handleDismiss}
+ >
+ <Icon icon={X} style={{ fontSize: 14 }} />
+ </button>
+ </div>
+ </m.div>
+ )}
+ </AnimatePresence>
+ </m.div>
+ </m.div>
+ )}
+ </AnimatePresence>
+ );
+});
+
+UpdateNotification.displayName = 'UpdateNotification';