diff --git a/src/main/ipc/register-core-handlers.ts b/src/main/ipc/register-core-handlers.ts index 617586622..1bf63f52c 100644 --- a/src/main/ipc/register-core-handlers.ts +++ b/src/main/ipc/register-core-handlers.ts @@ -19,6 +19,6 @@ export function registerCoreHandlers(store: Store): void { registerUIHandlers(store) registerFilesystemHandlers(store) registerClipboardHandlers() - registerUpdaterHandlers() + registerUpdaterHandlers(store) warmSystemFontFamilies() } diff --git a/src/main/persistence.test.ts b/src/main/persistence.test.ts index 17c7a32b1..0dfbad682 100644 --- a/src/main/persistence.test.ts +++ b/src/main/persistence.test.ts @@ -78,6 +78,8 @@ describe('Store', () => { expect(ui.sidebarWidth).toBe(280) expect(ui.groupBy).toBe('none') expect(ui.lastActiveRepoId).toBeNull() + expect(ui.dismissedUpdateVersion).toBeNull() + expect(ui.lastUpdateCheckAt).toBeNull() }) // ── 2. Load from existing valid file ───────────────────────────────── @@ -300,6 +302,15 @@ describe('Store', () => { const ui = store.getUI() expect(ui.sidebarWidth).toBe(400) expect(ui.groupBy).toBe('none') // default preserved + expect(ui.dismissedUpdateVersion).toBeNull() + }) + + it('persists updater reminder metadata in UI state', async () => { + const store = await createStore() + store.updateUI({ dismissedUpdateVersion: '1.0.99', lastUpdateCheckAt: 1234 }) + const ui = store.getUI() + expect(ui.dismissedUpdateVersion).toBe('1.0.99') + expect(ui.lastUpdateCheckAt).toBe(1234) }) it('migrates persisted smart sort to recent', async () => { diff --git a/src/main/updater-events.ts b/src/main/updater-events.ts index f048e9f0e..39d3e108e 100644 --- a/src/main/updater-events.ts +++ b/src/main/updater-events.ts @@ -19,9 +19,11 @@ type UpdaterHandlerContext = { getUserInitiatedCheck: () => boolean hasNewerDownloadedVersion: () => boolean performQuitAndInstall: () => void + recordCompletedUpdateCheck: () => void sendCheckFailureStatus: (message: string, userInitiated?: boolean) => Promise sendErrorStatus: (message: string, userInitiated?: boolean) => void sendStatus: (status: UpdateStatus) => void + scheduleAutomaticUpdateCheck: (delayMs: number) => void setAvailableReleaseUrl: (releaseUrl: string | null) => void setAvailableVersion: (version: string | null) => void setUserInitiatedCheck: (value: boolean) => void @@ -35,9 +37,11 @@ export function registerAutoUpdaterHandlers({ getUserInitiatedCheck, hasNewerDownloadedVersion, performQuitAndInstall, + recordCompletedUpdateCheck, sendCheckFailureStatus, sendErrorStatus, sendStatus, + scheduleAutomaticUpdateCheck, setAvailableReleaseUrl, setAvailableVersion, setUserInitiatedCheck @@ -102,6 +106,10 @@ export function registerAutoUpdaterHandlers({ } setAvailableVersion(info.version) setAvailableReleaseUrl(null) + recordCompletedUpdateCheck() + if (!wasUserInitiated) { + scheduleAutomaticUpdateCheck(36 * 60 * 60 * 1000) + } sendStatus({ state: 'available', version: info.version }) }) @@ -110,6 +118,10 @@ export function registerAutoUpdaterHandlers({ const wasUserInitiated = getUserInitiatedCheck() setUserInitiatedCheck(false) clearAvailableUpdateContext() + recordCompletedUpdateCheck() + if (!wasUserInitiated) { + scheduleAutomaticUpdateCheck(36 * 60 * 60 * 1000) + } sendStatus({ state: 'not-available', userInitiated: wasUserInitiated || undefined }) }) diff --git a/src/main/updater-fallback.ts b/src/main/updater-fallback.ts index 3b6a1bc69..a16856990 100644 --- a/src/main/updater-fallback.ts +++ b/src/main/updater-fallback.ts @@ -1,4 +1,41 @@ import { app } from 'electron' +import type { UpdateStatus } from '../shared/types' + +export function statusesEqual(left: UpdateStatus, right: UpdateStatus): boolean { + switch (left.state) { + case 'idle': + return right.state === 'idle' + case 'checking': + return right.state === 'checking' && left.userInitiated === right.userInitiated + case 'not-available': + return right.state === 'not-available' && left.userInitiated === right.userInitiated + case 'available': + return ( + right.state === 'available' && + left.version === right.version && + left.releaseUrl === right.releaseUrl && + left.manualDownloadUrl === right.manualDownloadUrl + ) + case 'downloading': + return ( + right.state === 'downloading' && + left.version === right.version && + left.percent === right.percent + ) + case 'downloaded': + return ( + right.state === 'downloaded' && + left.version === right.version && + left.releaseUrl === right.releaseUrl + ) + case 'error': + return ( + right.state === 'error' && + left.message === right.message && + left.userInitiated === right.userInitiated + ) + } +} const RELEASES_API_URL = 'https://api.github.com/repos/stablyai/orca/releases' @@ -31,6 +68,26 @@ export function isGitHubReleaseTransitionFailure(normalizedMessage: string): boo ) } +/** Identifies update-check failures that are transient or infrastructure-related + * (e.g. network blips, GitHub release transitions) and should NOT be surfaced + * to the user as errors. */ +export function isBenignCheckFailure(message: string): boolean { + const normalizedMessage = message.toLowerCase() + + if (normalizedMessage.includes('net::err_failed')) { + return true + } + + // GitHub releases can briefly be in a half-published state while the + // release workflow is creating a draft and uploading update metadata. + // During that window electron-updater may fail the check even though + // nothing is wrong on the client side. + return ( + isGitHubReleaseTransitionFailure(normalizedMessage) || + normalizedMessage.includes('no published versions on github') + ) +} + type ParsedVersion = { core: [number, number, number] prerelease: string[] diff --git a/src/main/updater.test.ts b/src/main/updater.test.ts index 629a08618..3cc6d575f 100644 --- a/src/main/updater.test.ts +++ b/src/main/updater.test.ts @@ -43,7 +43,7 @@ const { appOn.mockClear() eventHandlers.clear() on.mockClear() - autoUpdaterMock.checkForUpdates.mockReset() + autoUpdaterMock.checkForUpdates.mockReset().mockResolvedValue(null) autoUpdaterMock.downloadUpdate.mockReset() autoUpdaterMock.quitAndInstall.mockReset() } @@ -184,4 +184,75 @@ describe('updater', () => { expect.objectContaining({ state: 'error', message: 'net::ERR_FAILED' }) ) }) + + it('runs a startup check immediately when the last background check is stale', async () => { + const mainWindow = { webContents: { send: vi.fn() } } + const setLastUpdateCheckAt = vi.fn() + + const { setupAutoUpdater } = await import('./updater') + + setupAutoUpdater(mainWindow as never, { + getLastUpdateCheckAt: () => Date.now() - 37 * 60 * 60 * 1000, + setLastUpdateCheckAt + }) + + expect(autoUpdaterMock.checkForUpdates).toHaveBeenCalledTimes(1) + expect(setLastUpdateCheckAt).not.toHaveBeenCalled() + }) + + it('waits until the remaining interval before the next background check', async () => { + vi.useFakeTimers() + vi.setSystemTime(new Date('2026-04-03T12:00:00Z')) + + const mainWindow = { webContents: { send: vi.fn() } } + const setLastUpdateCheckAt = vi.fn() + + const { setupAutoUpdater } = await import('./updater') + + setupAutoUpdater(mainWindow as never, { + getLastUpdateCheckAt: () => Date.now() - 35 * 60 * 60 * 1000, + setLastUpdateCheckAt + }) + + expect(autoUpdaterMock.checkForUpdates).not.toHaveBeenCalled() + + vi.advanceTimersByTime(59 * 60 * 1000) + expect(autoUpdaterMock.checkForUpdates).not.toHaveBeenCalled() + + vi.advanceTimersByTime(60 * 1000) + expect(autoUpdaterMock.checkForUpdates).toHaveBeenCalledTimes(1) + expect(setLastUpdateCheckAt).not.toHaveBeenCalled() + }) + + it('retries background checks sooner after a failed automatic check', async () => { + vi.useFakeTimers() + vi.setSystemTime(new Date('2026-04-03T12:00:00Z')) + + autoUpdaterMock.checkForUpdates.mockImplementation(() => { + autoUpdaterMock.emit('checking-for-update') + queueMicrotask(() => { + autoUpdaterMock.emit('error', new Error('boom')) + }) + return Promise.reject(new Error('boom')) + }) + + const sendMock = vi.fn() + const mainWindow = { webContents: { send: sendMock } } + + const { setupAutoUpdater } = await import('./updater') + + setupAutoUpdater(mainWindow as never, { + getLastUpdateCheckAt: () => null, + setLastUpdateCheckAt: vi.fn() + }) + + await vi.runAllTicks() + expect(autoUpdaterMock.checkForUpdates).toHaveBeenCalledTimes(1) + + vi.advanceTimersByTime(59 * 60 * 1000) + expect(autoUpdaterMock.checkForUpdates).toHaveBeenCalledTimes(1) + + vi.advanceTimersByTime(60 * 1000) + expect(autoUpdaterMock.checkForUpdates).toHaveBeenCalledTimes(2) + }) }) diff --git a/src/main/updater.ts b/src/main/updater.ts index 35bb16bf1..baac75084 100644 --- a/src/main/updater.ts +++ b/src/main/updater.ts @@ -12,9 +12,14 @@ import { registerAutoUpdaterHandlers } from './updater-events' import { compareVersions, findFallbackReleaseVersion, - isGitHubReleaseTransitionFailure + isBenignCheckFailure, + isGitHubReleaseTransitionFailure, + statusesEqual } from './updater-fallback' +const AUTO_UPDATE_CHECK_INTERVAL_MS = 36 * 60 * 60 * 1000 +const AUTO_UPDATE_RETRY_INTERVAL_MS = 60 * 60 * 1000 + let mainWindowRef: BrowserWindow | null = null let currentStatus: UpdateStatus = { state: 'idle' } let userInitiatedCheck = false @@ -24,6 +29,8 @@ let availableVersion: string | null = null let availableReleaseUrl: string | null = null let pendingCheckFailureKey: string | null = null let pendingCheckFailurePromise: Promise | null = null +let autoUpdateCheckTimer: ReturnType | null = null +let persistLastUpdateCheckAt: ((timestamp: number) => void) | null = null /** Guards against the macOS `activate` handler re-opening the old version * while Squirrel's ShipIt is replacing the .app bundle. */ let quittingForUpdate = false @@ -33,42 +40,6 @@ function clearAvailableUpdateContext(): void { availableReleaseUrl = null } -function statusesEqual(left: UpdateStatus, right: UpdateStatus): boolean { - switch (left.state) { - case 'idle': - return right.state === 'idle' - case 'checking': - return right.state === 'checking' && left.userInitiated === right.userInitiated - case 'not-available': - return right.state === 'not-available' && left.userInitiated === right.userInitiated - case 'available': - return ( - right.state === 'available' && - left.version === right.version && - left.releaseUrl === right.releaseUrl && - left.manualDownloadUrl === right.manualDownloadUrl - ) - case 'downloading': - return ( - right.state === 'downloading' && - left.version === right.version && - left.percent === right.percent - ) - case 'downloaded': - return ( - right.state === 'downloaded' && - left.version === right.version && - left.releaseUrl === right.releaseUrl - ) - case 'error': - return ( - right.state === 'error' && - left.message === right.message && - left.userInitiated === right.userInitiated - ) - } -} - function sendStatus(status: UpdateStatus): void { if (statusesEqual(currentStatus, status)) { return @@ -127,23 +98,6 @@ function performQuitAndInstall(): void { autoUpdater.quitAndInstall(false, true) } -function isBenignCheckFailure(message: string): boolean { - const normalizedMessage = message.toLowerCase() - - if (normalizedMessage.includes('net::err_failed')) { - return true - } - - // GitHub releases can briefly be in a half-published state while the - // release workflow is creating a draft and uploading update metadata. - // During that window electron-updater may fail the check even though - // nothing is wrong on the client side. - return ( - isGitHubReleaseTransitionFailure(normalizedMessage) || - normalizedMessage.includes('no published versions on github') - ) -} - async function sendCheckFailureStatus(message: string, userInitiated?: boolean): Promise { const failureKey = `${userInitiated ? 'user' : 'auto'}:${message}` if (pendingCheckFailureKey === failureKey && pendingCheckFailurePromise) { @@ -162,6 +116,10 @@ async function sendCheckFailureStatus(message: string, userInitiated?: boolean): ) availableVersion = fallbackRelease.version availableReleaseUrl = fallbackRelease.releaseUrl + persistLastUpdateCheckAt?.(Date.now()) + if (!userInitiated) { + scheduleAutomaticUpdateCheck(AUTO_UPDATE_CHECK_INTERVAL_MS) + } sendStatus({ state: 'available', version: fallbackRelease.version, @@ -183,6 +141,7 @@ async function sendCheckFailureStatus(message: string, userInitiated?: boolean): // appear to silently do nothing. if (userInitiated) { clearAvailableUpdateContext() + persistLastUpdateCheckAt?.(Date.now()) sendStatus({ state: 'not-available', userInitiated: true }) return } @@ -190,11 +149,18 @@ async function sendCheckFailureStatus(message: string, userInitiated?: boolean): console.warn('[updater] benign check failure:', message) clearAvailableUpdateContext() + if (!userInitiated) { + scheduleAutomaticUpdateCheck(AUTO_UPDATE_RETRY_INTERVAL_MS) + } sendStatus({ state: 'idle' }) return } clearAvailableUpdateContext() + persistLastUpdateCheckAt?.(Date.now()) + if (!userInitiated) { + scheduleAutomaticUpdateCheck(AUTO_UPDATE_RETRY_INTERVAL_MS) + } sendErrorStatus(message, userInitiated) } @@ -212,7 +178,24 @@ export function getUpdateStatus(): UpdateStatus { return currentStatus } -export function checkForUpdates(): void { +function scheduleAutomaticUpdateCheck(delayMs: number): void { + if (autoUpdateCheckTimer) { + clearTimeout(autoUpdateCheckTimer) + } + autoUpdateCheckTimer = setTimeout(() => { + // Why: Orca is often left running for days. A one-shot startup check means + // users can miss fresh releases entirely, so we always keep the next + // background attempt scheduled in the main process instead of tying checks + // to relaunches or renderer lifetime. + runBackgroundUpdateCheck() + }, delayMs) +} + +function recordCompletedUpdateCheck(): void { + persistLastUpdateCheckAt?.(Date.now()) +} + +function runBackgroundUpdateCheck(): void { if (!app.isPackaged || is.dev) { sendStatus({ state: 'not-available' }) return @@ -224,6 +207,10 @@ export function checkForUpdates(): void { }) } +export function checkForUpdates(): void { + runBackgroundUpdateCheck() +} + /** Menu-triggered check — delegates feedback to renderer toasts via userInitiated flag */ export function checkForUpdatesFromMenu(): void { if (!app.isPackaged || is.dev) { @@ -262,10 +249,15 @@ export function quitAndInstall(): void { export function setupAutoUpdater( mainWindow: BrowserWindow, - opts?: { onBeforeQuit?: () => void } + opts?: { + getLastUpdateCheckAt?: () => number | null + onBeforeQuit?: () => void + setLastUpdateCheckAt?: (timestamp: number) => void + } ): void { mainWindowRef = mainWindow onBeforeQuitCleanup = opts?.onBeforeQuit ?? null + persistLastUpdateCheckAt = opts?.setLastUpdateCheckAt ?? null if (!app.isPackaged && !is.dev) { return @@ -296,7 +288,9 @@ export function setupAutoUpdater( performQuitAndInstall, sendCheckFailureStatus, sendErrorStatus, + recordCompletedUpdateCheck, sendStatus, + scheduleAutomaticUpdateCheck, setAvailableReleaseUrl: (releaseUrl) => { availableReleaseUrl = releaseUrl }, @@ -308,10 +302,16 @@ export function setupAutoUpdater( } }) - autoUpdater.checkForUpdates().catch((err) => { - // Startup check — don't bother the user, but log for diagnostics - console.error('[updater] startup check failed:', err?.message ?? err) - }) + const lastUpdateCheckAt = opts?.getLastUpdateCheckAt?.() ?? null + const msSinceLastCheck = + lastUpdateCheckAt === null ? Number.POSITIVE_INFINITY : Date.now() - lastUpdateCheckAt + + if (msSinceLastCheck >= AUTO_UPDATE_CHECK_INTERVAL_MS) { + runBackgroundUpdateCheck() + scheduleAutomaticUpdateCheck(AUTO_UPDATE_CHECK_INTERVAL_MS) + } else { + scheduleAutomaticUpdateCheck(AUTO_UPDATE_CHECK_INTERVAL_MS - msSinceLastCheck) + } } export function downloadUpdate(): void { diff --git a/src/main/window/attach-main-window-services.ts b/src/main/window/attach-main-window-services.ts index 916000c59..78f2a035b 100644 --- a/src/main/window/attach-main-window-services.ts +++ b/src/main/window/attach-main-window-services.ts @@ -17,7 +17,13 @@ export function attachMainWindowServices(mainWindow: BrowserWindow, store: Store registerWorktreeHandlers(mainWindow, store) registerPtyHandlers(mainWindow) registerFileDropRelay(mainWindow) - setupAutoUpdater(mainWindow, { onBeforeQuit: () => store.flush() }) + setupAutoUpdater(mainWindow, { + getLastUpdateCheckAt: () => store.getUI().lastUpdateCheckAt, + onBeforeQuit: () => store.flush(), + setLastUpdateCheckAt: (timestamp) => { + store.updateUI({ lastUpdateCheckAt: timestamp }) + } + }) const allowedPermissions = new Set(['media', 'fullscreen', 'pointerLock']) mainWindow.webContents.session.setPermissionRequestHandler( @@ -48,7 +54,7 @@ export function registerClipboardHandlers(): void { ipcMain.handle('clipboard:writeText', (_event, text: string) => clipboard.writeText(text)) } -export function registerUpdaterHandlers(): void { +export function registerUpdaterHandlers(_store: Store): void { ipcMain.removeHandler('updater:getStatus') ipcMain.removeHandler('updater:getVersion') ipcMain.removeHandler('updater:check') diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 1d3e0b12a..7995ebced 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -14,6 +14,7 @@ import Landing from './components/Landing' import Settings from './components/settings/Settings' import RightSidebar from './components/right-sidebar' import QuickOpen from './components/QuickOpen' +import UpdateReminder from './components/UpdateReminder' import { useGitStatusPolling } from './components/right-sidebar/useGitStatusPolling' function isEditableTarget(target: EventTarget | null): boolean { @@ -109,7 +110,9 @@ function App(): React.JSX.Element { sortBy: 'name', filterRepoIds: [], uiZoomLevel: 0, - worktreeCardProperties: [...DEFAULT_WORKTREE_CARD_PROPERTIES] + worktreeCardProperties: [...DEFAULT_WORKTREE_CARD_PROPERTIES], + dismissedUpdateVersion: null, + lastUpdateCheckAt: null }) hydrateWorkspaceSession({ activeRepoId: null, @@ -387,20 +390,23 @@ function App(): React.JSX.Element {
{showSidebar ? : null}
-
- +
+
+ +
+ {activeView === 'settings' ? : !activeWorktreeId ? : null}
- {activeView === 'settings' ? : !activeWorktreeId ? : null}
{showSidebar && rightSidebarOpen ? : null}
+
) diff --git a/src/renderer/src/components/UpdateReminder.tsx b/src/renderer/src/components/UpdateReminder.tsx new file mode 100644 index 000000000..9640e89b5 --- /dev/null +++ b/src/renderer/src/components/UpdateReminder.tsx @@ -0,0 +1,71 @@ +import { X } from 'lucide-react' +import { Button } from '@/components/ui/button' +import { useAppStore } from '@/store' +import type { UpdateStatus } from '../../../shared/types' + +function getReleaseUrl( + status: Extract +): string { + return status.releaseUrl ?? `https://github.com/stablyai/orca/releases/tag/v${status.version}` +} + +export default function UpdateReminder(): React.JSX.Element | null { + const updateStatus = useAppStore((s) => s.updateStatus) + const dismissedUpdateVersion = useAppStore((s) => s.dismissedUpdateVersion) + const dismissUpdate = useAppStore((s) => s.dismissUpdate) + + if (updateStatus.state !== 'available' && updateStatus.state !== 'downloaded') { + return null + } + + if (updateStatus.state === 'available' && updateStatus.version === dismissedUpdateVersion) { + return null + } + + const isDownloaded = updateStatus.state === 'downloaded' + const label = isDownloaded ? 'Restart to update' : 'Update available' + + return ( + // Persistent bottom-right toast, positioned to sit above the Sonner toaster. +
+
+

+ {label} v{updateStatus.version} +

+
+
+ + Notes + + + {!isDownloaded ? ( + + ) : null} +
+
+ ) +} diff --git a/src/renderer/src/components/sidebar/SidebarToolbar.tsx b/src/renderer/src/components/sidebar/SidebarToolbar.tsx index 5d94d39fc..d77a397bb 100644 --- a/src/renderer/src/components/sidebar/SidebarToolbar.tsx +++ b/src/renderer/src/components/sidebar/SidebarToolbar.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { Download, FolderPlus, Settings, X } from 'lucide-react' +import { FolderPlus, Settings } from 'lucide-react' import { useAppStore } from '@/store' import { Button } from '@/components/ui/button' import { Tooltip, TooltipTrigger, TooltipContent } from '@/components/ui/tooltip' @@ -7,75 +7,9 @@ import { Tooltip, TooltipTrigger, TooltipContent } from '@/components/ui/tooltip const SidebarToolbar = React.memo(function SidebarToolbar() { const addRepo = useAppStore((s) => s.addRepo) const setActiveView = useAppStore((s) => s.setActiveView) - const updateStatus = useAppStore((s) => s.updateStatus) - const dismissedUpdateVersion = useAppStore((s) => s.dismissedUpdateVersion) - const dismissUpdate = useAppStore((s) => s.dismissUpdate) - - const updateVersion = 'version' in updateStatus ? updateStatus.version : null - const showUpdateBanner = - (updateStatus.state === 'downloaded' || - updateStatus.state === 'available' || - updateStatus.state === 'downloading') && - updateVersion !== dismissedUpdateVersion return (
- {showUpdateBanner && ( -
- - {updateVersion && ( - e.stopPropagation()} - className="shrink-0 px-1.5 py-1 mr-0.5 text-[10px] text-primary/60 hover:text-primary underline transition-colors" - > - Notes - - )} - -
- )}
diff --git a/src/renderer/src/hooks/useIpcEvents.ts b/src/renderer/src/hooks/useIpcEvents.ts index f74a58d07..d1c4a08e2 100644 --- a/src/renderer/src/hooks/useIpcEvents.ts +++ b/src/renderer/src/hooks/useIpcEvents.ts @@ -39,22 +39,12 @@ export function useIpcEvents(): void { }) let checkingToastId: string | number | undefined - let availableToastId: string | number | undefined const downloadToastId = 'update-download-progress' - // When the user clicks "Update" in the toast we download and then - // auto-restart once the download finishes, avoiding a second confirmation. - let autoRestartAfterDownload = false unsubs.push( window.api.updater.onStatus((raw) => { const status = raw as UpdateStatus useAppStore.getState().setUpdateStatus(status) - // A new check cycle or error invalidates any previous one-click - // "Update" intent so we don't auto-restart from a stale flag. - if (status.state === 'checking' || status.state === 'error') { - autoRestartAfterDownload = false - } - // Show toasts for user-initiated checks if (status.state === 'checking' && 'userInitiated' in status && status.userInitiated) { checkingToastId = toast.loading('Checking for updates...') @@ -73,53 +63,13 @@ export function useIpcEvents(): void { toast.dismiss(checkingToastId) } checkingToastId = undefined - const releaseUrl = getReleaseUrl(status) - availableToastId = toast.info(`Version ${status.version} is available.`, { - description: createElement( - 'a', - { - href: releaseUrl, - target: '_blank', - rel: 'noopener noreferrer', - style: { textDecoration: 'underline' } - }, - 'Release notes' - ), - duration: Infinity, - action: { - label: 'Update', - onClick: () => { - // For auto-download updates, download and then auto-restart - // once finished so the user only clicks one button. - if (!status.manualDownloadUrl) { - autoRestartAfterDownload = true - } - window.api.updater.download() - } - } - }) } else if (status.state === 'downloading') { - if (availableToastId) { - toast.dismiss(availableToastId) - availableToastId = undefined - } toast.loading(`Downloading v${status.version}… ${status.percent}%`, { id: downloadToastId, duration: Infinity }) } else if (status.state === 'downloaded') { - if (availableToastId) { - toast.dismiss(availableToastId) - availableToastId = undefined - } toast.dismiss(downloadToastId) - // If the user clicked "Update" in the available toast, skip the - // second confirmation and restart immediately. - if (autoRestartAfterDownload) { - autoRestartAfterDownload = false - window.api.updater.quitAndInstall() - return - } const releaseUrl = getReleaseUrl(status) toast.success(`Version ${status.version} is ready to install.`, { description: createElement( diff --git a/src/renderer/src/store/slices/ui.ts b/src/renderer/src/store/slices/ui.ts index f021e8a4e..d7be41a30 100644 --- a/src/renderer/src/store/slices/ui.ts +++ b/src/renderer/src/store/slices/ui.ts @@ -97,6 +97,7 @@ export const createUISlice: StateCreator = (set) => ( sortBy, filterRepoIds: (ui.filterRepoIds ?? []).filter((repoId) => validRepoIds.has(repoId)), worktreeCardProperties: ui.worktreeCardProperties ?? [...DEFAULT_WORKTREE_CARD_PROPERTIES], + dismissedUpdateVersion: ui.dismissedUpdateVersion ?? null, persistedUIReady: true } }), @@ -105,7 +106,13 @@ export const createUISlice: StateCreator = (set) => ( setUpdateStatus: (status) => set({ updateStatus: status }), dismissedUpdateVersion: null, dismissUpdate: () => - set((s) => ({ - dismissedUpdateVersion: 'version' in s.updateStatus ? (s.updateStatus.version ?? null) : null - })) + set((s) => { + const dismissedUpdateVersion = + 'version' in s.updateStatus ? (s.updateStatus.version ?? null) : null + // Why: dismissing an update is user intent, not transient view state. Persist + // the dismissed version so relaunching the app does not immediately re-show + // the same reminder card until a newer release appears. + void window.api.ui.set({ dismissedUpdateVersion }).catch(console.error) + return { dismissedUpdateVersion } + }) }) diff --git a/src/shared/constants.ts b/src/shared/constants.ts index fa5a4aa3d..d54293e02 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -88,7 +88,9 @@ export function getDefaultUIState(): PersistedUIState { sortBy: 'name', filterRepoIds: [], uiZoomLevel: 0, - worktreeCardProperties: [...DEFAULT_WORKTREE_CARD_PROPERTIES] + worktreeCardProperties: [...DEFAULT_WORKTREE_CARD_PROPERTIES], + dismissedUpdateVersion: null, + lastUpdateCheckAt: null } } diff --git a/src/shared/types.ts b/src/shared/types.ts index 87aff1138..0c6b71555 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -209,6 +209,8 @@ export type PersistedUIState = { filterRepoIds: string[] uiZoomLevel: number worktreeCardProperties: WorktreeCardProperty[] + dismissedUpdateVersion: string | null + lastUpdateCheckAt: number | null } // ─── Persistence shape ──────────────────────────────────────────────