feat: auto updater background polling and persistent reminder UI (#266)
* feat: add update reminder component and background polling * refactor: replace update reminder banner with subtle bottom-right toast Swap the full-width top banner for a compact fixed-position toast in the bottom-right corner, matching the existing Sonner toast styling. Also extract pure functions (statusesEqual, isBenignCheckFailure) from updater.ts into updater-fallback.ts to fix max-lines lint error. * fix: mock checkForUpdates to return a promise so .catch() works in tests
This commit is contained in:
@@ -19,6 +19,6 @@ export function registerCoreHandlers(store: Store): void {
|
||||
registerUIHandlers(store)
|
||||
registerFilesystemHandlers(store)
|
||||
registerClipboardHandlers()
|
||||
registerUpdaterHandlers()
|
||||
registerUpdaterHandlers(store)
|
||||
warmSystemFontFamilies()
|
||||
}
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -19,9 +19,11 @@ type UpdaterHandlerContext = {
|
||||
getUserInitiatedCheck: () => boolean
|
||||
hasNewerDownloadedVersion: () => boolean
|
||||
performQuitAndInstall: () => void
|
||||
recordCompletedUpdateCheck: () => void
|
||||
sendCheckFailureStatus: (message: string, userInitiated?: boolean) => Promise<void>
|
||||
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 })
|
||||
})
|
||||
|
||||
|
||||
@@ -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[]
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
+60
-60
@@ -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<void> | null = null
|
||||
let autoUpdateCheckTimer: ReturnType<typeof setTimeout> | 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<void> {
|
||||
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 {
|
||||
|
||||
@@ -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')
|
||||
|
||||
+16
-10
@@ -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 {
|
||||
<div className="flex flex-row flex-1 min-h-0 overflow-hidden">
|
||||
{showSidebar ? <Sidebar /> : null}
|
||||
<div className="relative flex flex-1 min-w-0 min-h-0 overflow-hidden">
|
||||
<div
|
||||
className={
|
||||
activeView === 'settings' || !activeWorktreeId
|
||||
? 'hidden flex-1 min-w-0 min-h-0'
|
||||
: 'flex flex-1 min-w-0 min-h-0'
|
||||
}
|
||||
>
|
||||
<Terminal />
|
||||
<div className="flex flex-1 min-w-0 min-h-0 flex-col">
|
||||
<div
|
||||
className={
|
||||
activeView === 'settings' || !activeWorktreeId
|
||||
? 'hidden flex-1 min-w-0 min-h-0'
|
||||
: 'flex flex-1 min-w-0 min-h-0'
|
||||
}
|
||||
>
|
||||
<Terminal />
|
||||
</div>
|
||||
{activeView === 'settings' ? <Settings /> : !activeWorktreeId ? <Landing /> : null}
|
||||
</div>
|
||||
{activeView === 'settings' ? <Settings /> : !activeWorktreeId ? <Landing /> : null}
|
||||
</div>
|
||||
{showSidebar && rightSidebarOpen ? <RightSidebar /> : null}
|
||||
</div>
|
||||
<QuickOpen />
|
||||
<UpdateReminder />
|
||||
<Toaster closeButton toastOptions={{ className: 'font-sans text-sm' }} />
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -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<UpdateStatus, { state: 'available' | 'downloaded' }>
|
||||
): 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.
|
||||
<div className="fixed bottom-14 right-4 z-50 flex w-72 items-center gap-2 rounded-[var(--radius)] border border-border bg-popover px-3 py-2.5 text-popover-foreground shadow-md">
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-sm font-medium">
|
||||
{label} <span className="text-muted-foreground">v{updateStatus.version}</span>
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-1.5">
|
||||
<a
|
||||
href={getReleaseUrl(updateStatus)}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-xs text-muted-foreground underline-offset-2 hover:underline"
|
||||
>
|
||||
Notes
|
||||
</a>
|
||||
<Button
|
||||
variant="default"
|
||||
size="sm"
|
||||
className="h-7 px-2.5 text-xs"
|
||||
onClick={() => {
|
||||
if (isDownloaded) {
|
||||
void window.api.updater.quitAndInstall()
|
||||
} else {
|
||||
void window.api.updater.download()
|
||||
}
|
||||
}}
|
||||
>
|
||||
{isDownloaded ? 'Restart' : 'Install'}
|
||||
</Button>
|
||||
{!isDownloaded ? (
|
||||
<button
|
||||
onClick={() => dismissUpdate()}
|
||||
aria-label="Dismiss"
|
||||
className="ml-0.5 rounded-sm p-0.5 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<X className="size-3.5" />
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -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 (
|
||||
<div className="mt-auto shrink-0">
|
||||
{showUpdateBanner && (
|
||||
<div className="flex items-center border-t border-sidebar-border bg-primary/10">
|
||||
<button
|
||||
onClick={() => {
|
||||
if (updateStatus.state === 'downloaded') {
|
||||
window.api.updater.quitAndInstall()
|
||||
} else if (updateStatus.state === 'available') {
|
||||
window.api.updater.download()
|
||||
}
|
||||
}}
|
||||
disabled={updateStatus.state === 'downloading'}
|
||||
className="flex items-center gap-1.5 flex-1 min-w-0 px-2 py-1.5 text-[11px] font-medium text-primary hover:bg-primary/15 transition-colors cursor-pointer disabled:opacity-60 disabled:cursor-default"
|
||||
>
|
||||
<Download className="size-3.5 shrink-0" />
|
||||
{updateStatus.state === 'downloaded' ? (
|
||||
<span>Restart now (update)</span>
|
||||
) : updateStatus.state === 'downloading' ? (
|
||||
<span>
|
||||
Downloading <span className="font-semibold">v{updateVersion}</span>…{' '}
|
||||
{updateStatus.percent}%
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
Update <span className="font-semibold">v{updateStatus.version}</span> available —
|
||||
{updateStatus.manualDownloadUrl ? ' Download' : ' Install'}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
{updateVersion && (
|
||||
<a
|
||||
href={
|
||||
(updateStatus.state === 'available' || updateStatus.state === 'downloaded') &&
|
||||
updateStatus.releaseUrl
|
||||
? updateStatus.releaseUrl
|
||||
: `https://github.com/stablyai/orca/releases/tag/v${updateVersion}`
|
||||
}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
onClick={(e) => 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
|
||||
</a>
|
||||
)}
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
dismissUpdate()
|
||||
}}
|
||||
className="shrink-0 p-1 mr-1 rounded text-primary/60 hover:text-primary hover:bg-primary/15 transition-colors"
|
||||
title="Dismiss"
|
||||
>
|
||||
<X className="size-3" />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center justify-between px-2 py-1.5 border-t border-sidebar-border">
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -97,6 +97,7 @@ export const createUISlice: StateCreator<AppState, [], [], UISlice> = (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<AppState, [], [], UISlice> = (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 }
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -209,6 +209,8 @@ export type PersistedUIState = {
|
||||
filterRepoIds: string[]
|
||||
uiZoomLevel: number
|
||||
worktreeCardProperties: WorktreeCardProperty[]
|
||||
dismissedUpdateVersion: string | null
|
||||
lastUpdateCheckAt: number | null
|
||||
}
|
||||
|
||||
// ─── Persistence shape ──────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user