graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
feat(desktop): update-ready modal pops once per downloaded version
Rach Pradhana1fed23e0f92
diff --git a/apps/native/electron/updates.cjs b/apps/native/electron/updates.cjsindex 03868f0f..ba10249d 100644--- a/apps/native/electron/updates.cjs+++ b/apps/native/electron/updates.cjs@@ -1,7 +1,7 @@const fs = require('node:fs');const path = require('node:path');-function createUpdates({ updater, version, available = true, automatic = true, notify, save = () => {} }) {+function createUpdates({ updater, version, available = true, automatic = true, notify, save = () => {}, onReady }) {let state = { status: available ? 'idle' : 'unavailable', currentVersion: version, automatic, interactive: false };let checking = false;const emit = patch => { state = { ...state, ...patch }; notify({ ...state }); };@@ -19,7 +19,13 @@ function createUpdates({ updater, version, available = true, automatic = true, nif (percent !== state.percent) emit({ status: 'downloading', percent });});updater.on('update-not-available', () => emit({ status: 'current', version: undefined, percent: undefined }));- updater.on('update-downloaded', info => emit({ status: 'ready', version: info.version, percent: 100 }));+ updater.on('update-downloaded', info => {+ emit({ status: 'ready', version: info.version, percent: 100 });+ if (onReady && info.version && info.version !== state.prompted) {+ state.prompted = info.version; // once per version: dismiss means Later, never a loop+ onReady(info.version);+ }+ });updater.on('error', () => emit({ status: 'error', message: 'Could not update. Check your connection and try again.' }));}return {@@ -52,6 +58,7 @@ function createUpdates({ updater, version, available = true, automatic = true, n}function installUpdates({ app, win, ipcMain, trusted, resources }) {+ const { dialog } = require('electron');const prefs = path.join(app.getPath('userData'), 'updates.json');let automatic = true;try { automatic = JSON.parse(fs.readFileSync(prefs, 'utf8')).automatic !== false; } catch {}@@ -61,6 +68,20 @@ function installUpdates({ app, win, ipcMain, trusted, resources }) {updater: available ? require('./updater-runtime.cjs') : null,save: value => { fs.mkdirSync(path.dirname(prefs), { recursive: true }); fs.writeFileSync(prefs, JSON.stringify({ automatic: value })); },notify: state => { if (!win.isDestroyed()) { win.webContents.send('update-state', state); win.setProgressBar(state.status === 'downloading' ? (state.percent ?? 0) / 100 : -1); } },+ onReady: readyVersion => {+ // The standard update modal (Sparkle/electron-updater style): pops once+ // per downloaded version, after the download — never mid-conversation.+ if (win.isDestroyed()) return;+ void dialog.showMessageBox(win, {+ type: 'info',+ title: 'Update Available',+ message: `Codegraff ${readyVersion} is ready to install.`,+ detail: 'Restart to apply the update now, or keep working — Codegraff offers the restart again at next launch.',+ buttons: ['Restart to update', 'Later'], defaultId: 0, cancelId: 1,+ }).then(({ response }) => {+ if (response === 0 && !win.isDestroyed()) { try { controller.restart(); } catch {} }+ }).catch(() => {});+ },});ipcMain.handle('updates', async (event, action) => {trusted(event);diff --git a/apps/native/electron/updates.test.cjs b/apps/native/electron/updates.test.cjsindex 62cf00da..d64775a9 100644--- a/apps/native/electron/updates.test.cjs+++ b/apps/native/electron/updates.test.cjs@@ -4,10 +4,11 @@ const { createUpdates } = require('./updates.cjs');function fixture(options = {}) {const updater = new EventEmitter(), events = [], saved = [];let checks = 0, installs = 0;+ const ready = [];updater.checkForUpdates = async () => { checks++; updater.emit('checking-for-update'); return null; };updater.quitAndInstall = () => { installs++; };- const updates = createUpdates({ updater, version: '1.0.0', notify: state => events.push(state), save: value => saved.push(value), ...options });- return { updater, updates, events, saved, checks: () => checks, installs: () => installs };+ const updates = createUpdates({ updater, version: '1.0.0', notify: state => events.push(state), save: value => saved.push(value), onReady: v => ready.push(v), ...options });+ return { updater, updates, events, saved, ready, checks: () => checks, installs: () => installs };}test('downloads in the background but never interrupts a running task automatically', async () => {const f = fixture();@@ -63,3 +64,16 @@ test('concurrent checks are coalesced and automatic-download preference persistsexpect(f.saved).toEqual([false]);expect(f.updates.state().automatic).toBe(false);});++test('the ready modal pops once per version, never in a dismiss loop', async () => {+ const f = fixture();+ await f.updates.check();+ f.updater.emit('update-available', { version: '1.0.1' });+ f.updater.emit('update-downloaded', { version: '1.0.1' });+ f.updater.emit('update-downloaded', { version: '1.0.1' }); // duplicate event after a redownload+ expect(f.ready).toEqual(['1.0.1']);+ await f.updates.check(); // checks while ready do not re-prompt+ expect(f.ready).toEqual(['1.0.1']);+ f.updater.emit('update-downloaded', { version: '1.0.2' });+ expect(f.ready).toEqual(['1.0.1', '1.0.2']);+});