Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(update): the Download button could silently do nothing

David94d3d035063e
diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsx
index a14e424d..c5ac1222 100644
--- a/src/components/settings/SettingsPage.tsx
+++ b/src/components/settings/SettingsPage.tsx
@@ -1637,7 +1637,7 @@ function UpdateSection() {
{/* Manual check */}
<button
- onClick={() => { useUpdateStore.setState({ lastChecked: null }); checkForUpdate() }}
+ onClick={() => { void checkForUpdate(true) }}
disabled={isChecking}
className="text-[0.6rem] text-gray-500 hover:text-gray-300 transition-colors disabled:opacity-40"
>
diff --git a/src/stores/__tests__/updateStore.test.ts b/src/stores/__tests__/updateStore.test.ts
index 065560de..89f08cbc 100644
--- a/src/stores/__tests__/updateStore.test.ts
+++ b/src/stores/__tests__/updateStore.test.ts
@@ -252,14 +252,21 @@ describe('updateStore', () => {
expect(useUpdateStore.getState().downloadStatus).toBe('idle')
})
- it('downloadUpdate is no-op without pending update (dev mode)', async () => {
+ // These two used to assert the button did NOTHING without a pending
+ // update handle — the defect written down as expected behaviour. Both
+ // paths now surface a reason (see "the Download button never does
+ // nothing" below); what stays asserted here is that neither of them
+ // pretends a download is in flight.
+ it('downloadUpdate does not fake a download without a pending update', async () => {
+ vi.stubGlobal('fetch', vi.fn().mockRejectedValue(new Error('offline')))
await useUpdateStore.getState().downloadUpdate()
- expect(useUpdateStore.getState().downloadStatus).toBe('idle')
+ expect(useUpdateStore.getState().downloadStatus).not.toBe('downloading')
+ expect(useUpdateStore.getState().downloadStatus).not.toBe('downloaded')
})
- it('installAndRestart is no-op without pending update', async () => {
+ it('installAndRestart does not fake an install without a pending update', async () => {
await useUpdateStore.getState().installAndRestart()
- expect(useUpdateStore.getState().downloadStatus).toBe('idle')
+ expect(useUpdateStore.getState().downloadStatus).not.toBe('installing')
})
})
@@ -291,3 +298,53 @@ describe('updateStore', () => {
})
})
})
+
+// The Update handle lives in a module-level variable that dies with the
+// process, while `updateAvailable` is persisted — so the badge can offer a
+// Download button with nothing behind it (after a relaunch, before the startup
+// check lands, or when that check ran offline). It used to return silently.
+describe('the Download button never does nothing', () => {
+ beforeEach(() => {
+ useUpdateStore.setState({
+ updateAvailable: true,
+ latestVersion: '2.6.0',
+ lastChecked: null,
+ isChecking: false,
+ downloadStatus: 'idle',
+ errorMessage: null,
+ })
+ })
+
+ it('says why instead of silently returning when the handle is gone', async () => {
+ vi.stubGlobal('fetch', vi.fn().mockRejectedValue(new Error('offline')))
+
+ await useUpdateStore.getState().downloadUpdate()
+
+ const s = useUpdateStore.getState()
+ expect(s.downloadStatus).toBe('error')
+ expect(s.errorMessage).toMatch(/connection|update server/i)
+ })
+
+ it('installAndRestart reports the lost download instead of doing nothing', async () => {
+ await useUpdateStore.getState().installAndRestart()
+
+ const s = useUpdateStore.getState()
+ expect(s.downloadStatus).toBe('error')
+ expect(s.errorMessage).toMatch(/download it again/i)
+ })
+
+ it('a forced check ignores the 6h cooldown', async () => {
+ const fetchMock = vi.fn().mockResolvedValue({
+ ok: true,
+ json: async () => makeGitHubRelease('v2.6.0'),
+ })
+ vi.stubGlobal('fetch', fetchMock)
+ useUpdateStore.setState({ lastChecked: Date.now(), isChecking: false })
+
+ await useUpdateStore.getState().checkForUpdate()
+ expect(fetchMock).not.toHaveBeenCalled()
+
+ await useUpdateStore.getState().checkForUpdate(true)
+ expect(fetchMock).toHaveBeenCalledOnce()
+ })
+})
diff --git a/src/stores/updateStore.ts b/src/stores/updateStore.ts
index 42c350b8..f2190584 100644
--- a/src/stores/updateStore.ts
+++ b/src/stores/updateStore.ts
@@ -23,7 +23,9 @@ interface UpdateState {
totalBytes: number
errorMessage: string | null
- checkForUpdate: () => Promise<void>
+ /** `force` skips the 6h cooldown — for a user-triggered check, and for
+ * the download path when the Update handle is missing. */
+ checkForUpdate: (force?: boolean) => Promise<void>
downloadUpdate: () => Promise<void>
installAndRestart: () => Promise<void>
dismissUpdate: () => void
@@ -72,10 +74,10 @@ export const useUpdateStore = create<UpdateState>()(
totalBytes: 0,
errorMessage: null,
- checkForUpdate: async () => {
+ checkForUpdate: async (force = false) => {
const state = get()
if (state.isChecking) return
- if (state.lastChecked && Date.now() - state.lastChecked < CHECK_INTERVAL) return
+ if (!force && state.lastChecked && Date.now() - state.lastChecked < CHECK_INTERVAL) return
set({ isChecking: true })
@@ -131,7 +133,23 @@ export const useUpdateStore = create<UpdateState>()(
},
downloadUpdate: async () => {
- if (!_pendingUpdate) return
+ // The Update handle lives in this process only. `updateAvailable` is
+ // persisted, so after a relaunch — or when the startup check has not
+ // landed yet, or ran while offline — the badge offers a Download button
+ // with nothing behind it. This used to `return` silently: the user
+ // clicked and NOTHING happened, no spinner, no error. Re-check first
+ // (forced, or the 6h cooldown a failed check just armed would block
+ // it), and if the handle still is not there, say so.
+ if (!_pendingUpdate) {
+ await get().checkForUpdate(true)
+ }
+ if (!_pendingUpdate) {
+ set({
+ downloadStatus: 'error',
+ errorMessage: 'Could not reach the update server. Check your connection and try again.',
+ })
+ return
+ }
set({ downloadStatus: 'downloading', downloadProgress: 0, downloadedBytes: 0, errorMessage: null })
let downloaded = 0
@@ -163,7 +181,15 @@ export const useUpdateStore = create<UpdateState>()(
},
installAndRestart: async () => {
- if (!_pendingUpdate) return
+ if (!_pendingUpdate) {
+ // Nothing was downloaded in THIS process — same dead-button problem
+ // as above, and here a re-check would not help.
+ set({
+ downloadStatus: 'error',
+ errorMessage: 'The downloaded update was lost when the app restarted. Download it again.',
+ })
+ return
+ }
set({ downloadStatus: 'installing' })