Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

feat(update): manual updates download on click with per-OS install steps, and the first run after an update shows that release's page

Chaitanya Giri4f7878e7b49c
diff --git a/src/main/updater.ts b/src/main/updater.ts
index 164fa784..7a960661 100644
--- a/src/main/updater.ts
+++ b/src/main/updater.ts
@@ -1,7 +1,7 @@
import { app, ipcMain, shell } from 'electron';
import type { WebContents } from 'electron';
import { request as httpsRequest } from 'node:https';
-import { appendFileSync, mkdirSync, readFileSync } from 'node:fs';
+import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { readConfig } from './config';
import { DEFAULT_DROP_HTML } from '../shared/releaseDrop';
@@ -169,6 +169,35 @@ export function pickDownloadAsset(
return hit?.browser_download_url ?? null;
}
+/** Body of the release tagged v{version}, or undefined. Never throws. */
+function fetchReleaseBody(version: string, done: (notes: string | undefined) => void): void {
+ try {
+ const req = httpsRequest(
+ {
+ hostname: 'api.github.com',
+ path: `/repos/${REPO}/releases/tags/v${version}`,
+ method: 'GET',
+ headers: { 'User-Agent': 'munder-difflin-updater', Accept: 'application/vnd.github+json' },
+ timeout: 10_000
+ },
+ (res) => {
+ let body = '';
+ res.setEncoding('utf8');
+ res.on('data', (d) => { body += d; if (body.length > 262_144) req.destroy(); });
+ res.on('end', () => {
+ try {
+ const rel = JSON.parse(body) as { body?: string };
+ done(typeof rel.body === 'string' ? rel.body : undefined);
+ } catch { done(undefined); }
+ });
+ }
+ );
+ req.on('error', () => done(undefined));
+ req.on('timeout', () => { req.destroy(); done(undefined); });
+ req.end();
+ } catch { done(undefined); }
+}
+
/** Notify-only check against releases/latest (no download). Never throws. */
function fallbackCheck(reason: string | undefined, force = false): void {
const now = Date.now();
@@ -369,6 +398,31 @@ export function initAutoUpdater(getWebContents: () => WebContents | null): void
logLine(`MD_DROP_PREVIEW unreadable: ${errText(e)}`);
}
}
+ // First launch after the version moved: show THIS release's page. The stamp
+ // is the updater's own (analytics keeps a separate one that only exists when
+ // telemetry initialised). Skipped when a preview is being forced, and the
+ // fetch failing just means no page, never a broken boot.
+ if (!previewPath) {
+ try {
+ const stampFile = join(app.getPath('userData'), 'last-run-version');
+ let previous: string | null = null;
+ try { previous = readFileSync(stampFile, 'utf8').trim() || null; } catch { /* first run */ }
+ const current = app.getVersion();
+ if (previous !== current) {
+ mkdirSync(app.getPath('userData'), { recursive: true });
+ writeFileSync(stampFile, current + '\n', 'utf8');
+ }
+ if (previous && previous !== current && isNewer(current, previous)) {
+ logLine(`first run after update ${previous} -> ${current}; fetching its release page`);
+ fetchReleaseBody(current, (notes) => {
+ emit({ state: 'just-updated', version: current, notes });
+ logLine(`just-updated ${current} ${notes ? 'with' : 'without'} release notes`);
+ });
+ }
+ } catch (e) {
+ logLine(`post-update check failed: ${errText(e)}`);
+ }
+ }
ipcMain.handle('update:openRelease', (_evt, url: unknown) => {
const href = typeof url === 'string' ? url : `https://github.com/${REPO}/releases/latest`;
// Only ever open the project's releases page — this is not a generic opener.
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 32d65078..90e865f1 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -1374,6 +1374,8 @@ const api = {
/** Open the project's releases page for a notify-only update. */
updateOpenRelease: (url?: string): Promise<{ ok: boolean }> =>
ipcRenderer.invoke('update:openRelease', url),
+ /** Which OS this window runs on, for platform-specific copy. */
+ platform: process.platform as string,
/** DEV ONLY — fabricate an update status so the toast can be inspected without
* cutting a release. Refused (`{ok:false}`) in a packaged build; see the
* handler in updater.ts. Call it from the devtools console:
diff --git a/src/renderer/src/components/UpdateBadge.tsx b/src/renderer/src/components/UpdateBadge.tsx
index f7ee3260..56ff6b41 100644
--- a/src/renderer/src/components/UpdateBadge.tsx
+++ b/src/renderer/src/components/UpdateBadge.tsx
@@ -13,13 +13,18 @@
* is wiring and pixels.
*/
import { useCallback, useEffect, useState } from 'react';
-import { describeUpdate, reduceStatus, type UpdateStatus } from '@shared/updateState';
+import { describeUpdate, manualInstallSteps, reduceStatus, type UpdateStatus } from '@shared/updateState';
+import { PixelButton } from './PixelButton';
declare const __APP_VERSION__: string;
export function UpdateBadge() {
const [status, setStatus] = useState<UpdateStatus | null>(null);
const [busy, setBusy] = useState(false);
+ const [hover, setHover] = useState(false);
+ /** The version whose download was just started, for the "now replace the
+ * app" notice. Local state: it is a one-off explanation, not an update state. */
+ const [started, setStarted] = useState<string | null>(null);
useEffect(() => {
// Subscribe first, then pull — main may have emitted before this window
@@ -41,7 +46,11 @@ export function UpdateBadge() {
else if (view.action === 'download') await window.cth.updateDownload();
else if (view.action === 'check') await window.cth.updateCheckNow();
else if (view.action === 'open-release') {
- await window.cth.updateOpenRelease(status?.state === 'available-manual' ? status.url : undefined);
+ // With a direct installer for this machine the click IS the download;
+ // the release page is only for installs the release has no asset for.
+ const manual = status?.state === 'available-manual' ? status : null;
+ await window.cth.updateOpenRelease(manual ? (manual.downloadUrl ?? manual.url) : undefined);
+ if (manual?.downloadUrl) setStarted(manual.version);
}
} catch { /* the emitted status carries the failure — nothing to do here */ }
setBusy(false);
@@ -56,7 +65,16 @@ export function UpdateBadge() {
: view.tone === 'warn' ? 'var(--cth-amber-light, #f6e2b3)'
: 'transparent';
+ const manual = status?.state === 'available-manual' && status.downloadUrl ? status : null;
+ const steps = manualInstallSteps(window.cth.platform ?? 'darwin');
+ const INK = 'var(--cth-ink-900)';
+
return (
+ <span
+ style={{ position: 'relative', display: 'inline-flex' }}
+ onMouseEnter={() => setHover(true)}
+ onMouseLeave={() => setHover(false)}
+ >
<button
className="cth-titlebar-nodrag"
onClick={() => { void onClick(); }}
@@ -87,5 +105,65 @@ export function UpdateBadge() {
</>
)}
</button>
+
+ {/* Hover card: what the click does and what to do with the file, for this OS. */}
+ {manual && hover && !started && (
+ <div
+ role="tooltip"
+ className="cth-titlebar-nodrag"
+ style={{
+ position: 'absolute', top: 'calc(100% + 6px)', left: 0, zIndex: 400,
+ width: 340, padding: '10px 12px',
+ background: 'var(--cth-paper-100)', color: INK,
+ border: `2px solid ${INK}`, boxShadow: `4px 4px 0 ${INK}`,
+ fontFamily: 'var(--cth-font-ui)', fontSize: 12, lineHeight: 1.5, textAlign: 'left'
+ }}
+ >
+ <div style={{ fontFamily: 'var(--cth-font-mono, monospace)', fontWeight: 700, fontSize: 12.5 }}>
+ Click to download v{manual.version}
+ </div>
+ <div style={{ marginTop: 4, color: 'var(--cth-ink-700)' }}>
+ This build cannot update itself. Download the latest version and replace the app you have.
+ </div>
+ <div style={{
+ marginTop: 8, fontFamily: 'var(--cth-font-mono, monospace)', fontSize: 9,
+ letterSpacing: '.18em', textTransform: 'uppercase', color: 'var(--cth-ink-500)'
+ }}>On {steps.os}</div>
+ <ol style={{ margin: '4px 0 0', paddingLeft: 18, color: 'var(--cth-ink-700)' }}>
+ {steps.steps.map((t) => <li key={t}>{t}</li>)}
+ </ol>
+ </div>
+ )}
+
+ {/* After the click: the download is in the browser, here is what to do next. */}
+ {started && (
+ <div
+ role="dialog"
+ aria-label="Install the update"
+ className="cth-titlebar-nodrag"
+ style={{
+ position: 'absolute', top: 'calc(100% + 6px)', left: 0, zIndex: 400,
+ width: 380, padding: '12px 14px',
+ background: 'var(--cth-paper-100)', color: INK,
+ border: `2px solid ${INK}`, boxShadow: `4px 4px 0 ${INK}`,
+ fontFamily: 'var(--cth-font-ui)', fontSize: 12.5, lineHeight: 1.5, textAlign: 'left'
+ }}
+ >
+ <div style={{ fontFamily: 'var(--cth-font-mono, monospace)', fontWeight: 700, fontSize: 13 }}>
+ v{started} is downloading in your browser.
+ </div>
+ <div style={{ marginTop: 6, color: 'var(--cth-ink-700)' }}>
+ When it lands, quit this app and install the new version over the current one. Open it and
+ pick the same project. Your agents, memory and settings stay where they are.
+ </div>
+ <ol style={{ margin: '8px 0 0', paddingLeft: 18, color: 'var(--cth-ink-700)' }}>
+ {steps.steps.map((t) => <li key={t}>{t}</li>)}
+ </ol>
+ <div style={{ display: 'flex', gap: 8, marginTop: 10, justifyContent: 'flex-end' }}>
+ <PixelButton variant="ghost" size="sm" onClick={() => setStarted(null)}>got it</PixelButton>
+ </div>
+ </div>
+ )}
+ </span>
);
}
diff --git a/src/renderer/src/components/UpdateToast.tsx b/src/renderer/src/components/UpdateToast.tsx
index 66c67d44..432afc99 100644
--- a/src/renderer/src/components/UpdateToast.tsx
+++ b/src/renderer/src/components/UpdateToast.tsx
@@ -44,10 +44,10 @@ import type { UpdateStatus } from '@shared/updateState';
/** The toast is the LOUD half — it only interrupts for the two states a user has
* to act on. Everything else (checking, available, download progress, errors)
* lives quietly in the toolbar badge next to the logo. */
-type ToastStatus = Extract<UpdateStatus, { state: 'downloaded' | 'available-manual' }>;
+type ToastStatus = Extract<UpdateStatus, { state: 'downloaded' | 'available-manual' | 'just-updated' }>;
function toastable(s: UpdateStatus): ToastStatus | null {
- return s.state === 'downloaded' || s.state === 'available-manual' ? s : null;
+ return s.state === 'downloaded' || s.state === 'available-manual' || s.state === 'just-updated' ? s : null;
}
const GITHUB_REPO_URL = 'https://github.com/chaitanyagiri/munder-difflin';
@@ -201,6 +201,8 @@ export function UpdateToast() {
/>
);
}
+ // Freshly updated with nothing authored for this release: nothing to say.
+ if (status.state === 'just-updated') return null;
const buttonStyle: React.CSSProperties = {
padding: '3px 10px 1px',
diff --git a/src/shared/updateState.ts b/src/shared/updateState.ts
index 1a894748..425d6af8 100644
--- a/src/shared/updateState.ts
+++ b/src/shared/updateState.ts
@@ -26,6 +26,9 @@ export type UpdateStatus =
* modal's primary button downloads it; without it the button falls back
* to the releases page. */
downloadUrl?: string }
+ /** First launch after the version moved: `version` is the one now RUNNING and
+ * `notes` its release body, so the renderer can show that release's page. */
+ | { state: 'just-updated'; version: string; notes?: string }
| { state: 'error'; message: string };
export type UpdateAction = 'none' | 'check' | 'download' | 'restart' | 'open-release';
@@ -73,6 +76,7 @@ function rank(s: UpdateStatus): number {
case 'checking': return 1;
case 'not-available': return 1;
case 'error': return 1;
+ case 'just-updated': return 1;
case 'available-manual': return 2;
case 'available': return 3;
case 'downloading': return 4;
@@ -129,12 +133,19 @@ export function describeUpdate(status: UpdateStatus | null, currentVersion: stri
title: `v${status.version} is downloaded and ready — click to restart and apply it`
};
case 'available-manual':
- return {
- label: `v${status.version} — get it manually`, action: 'open-release', tone: 'warn', busy: false,
- title: status.reason
- ? `This install couldn't update itself (${status.reason}) — click to open the release page`
- : `This install can't update itself — click to open the release page`
- };
+ return status.downloadUrl
+ ? {
+ label: `v${status.version} · download`, action: 'open-release', tone: 'ready', busy: false,
+ title: `Click to download v${status.version}, then replace the app you have`
+ }
+ : {
+ label: `v${status.version} — get it manually`, action: 'open-release', tone: 'warn', busy: false,
+ title: status.reason
+ ? `This install couldn't update itself (${status.reason}) — click to open the release page`
+ : `This install can't update itself — click to open the release page`
+ };
+ case 'just-updated':
+ return { label: null, action: 'check', tone: 'idle', busy: false, title: `v${v} is the latest version — click to check again` };
case 'error':
return {
label: 'update check failed', action: 'check', tone: 'warn', busy: false,
@@ -208,7 +219,14 @@ export function describeUpdateSettings(
detail: status.reason
? `This install can't update itself (${status.reason}) — download it from the release page.`
: `This install can't update itself — download it from the release page.`,
- button: 'Open release page', action: 'open-release', busy: false, tone: 'warn'
+ button: status.downloadUrl ? `Download v${status.version}` : 'Open release page',
+ action: 'open-release', busy: false, tone: 'warn'
+ };
+ case 'just-updated':
+ return {
+ headline: `You're on v${v}`,
+ detail: 'Freshly updated. This is the latest release.',
+ button: 'Check for updates', action: 'check', busy: false, tone: 'idle'
};
case 'error':
return {
@@ -231,3 +249,33 @@ export function describeUpdateSettings(
};
}
}
+
+/** What to do with the installer once it has downloaded, per platform. Shown
+ * on the title-bar badge's hover card and in the notice after the click. */
+export function manualInstallSteps(platform: string): { os: string; steps: string[] } {
+ if (platform === 'darwin') {
+ return {
+ os: 'macOS',
+ steps: [
+ 'Open the .dmg and drag Munder Difflin onto Applications. Choose Replace when asked.',
+ 'Quit this app, open the new one from Applications, and pick the same project.'
+ ]
+ };
+ }
+ if (platform === 'win32') {
+ return {
+ os: 'Windows',
+ steps: [
+ 'Quit this app, then run the downloaded setup .exe. It replaces the installed version.',
+ 'Open Munder Difflin again and pick the same project.'
+ ]
+ };
+ }
+ return {
+ os: 'Linux',
+ steps: [
+ 'Make the downloaded .AppImage executable (chmod +x) and move it over the one you run now.',
+ 'Quit this app, launch the new AppImage, and pick the same project.'
+ ]
+ };
+}
diff --git a/test/update-state.test.cjs b/test/update-state.test.cjs
index fbb683f1..dc4997bb 100644
--- a/test/update-state.test.cjs
+++ b/test/update-state.test.cjs
@@ -188,3 +188,29 @@ test('failures reach Settings verbatim, same as the tooltip', () => {
assert.match(manual.detail, /win-portable/);
assert.equal(manual.action, 'open-release');
});
+
+test('manual update with a direct installer reads as a download, not a page to hunt on', () => {
+ const { manualInstallSteps } = loadTs('src/shared/updateState.ts');
+ const v = describeUpdate(
+ { state: 'available-manual', version: '0.4.5', url: 'https://x', downloadUrl: 'https://x/a.dmg' },
+ '0.4.4'
+ );
+ assert.match(v.label, /download/);
+ assert.equal(v.action, 'open-release');
+ assert.equal(v.tone, 'ready');
+ for (const p of ['darwin', 'win32', 'linux']) {
+ const s = manualInstallSteps(p);
+ assert.equal(s.steps.length, 2);
+ assert.match(s.steps.join(' '), /same project/);
+ }
+});
+
+test('just-updated is quiet on the badge and loses to a newer available release', () => {
+ const v = describeUpdate({ state: 'just-updated', version: '0.4.5' }, '0.4.5');
+ assert.equal(v.label, null);
+ const next = reduceStatus(
+ { state: 'just-updated', version: '0.4.5' },
+ { state: 'available', version: '0.4.6' }
+ );
+ assert.equal(next.state, 'available');
+});