Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(desktop): add auto-update with GitHub releases
Jiang Bohane5881601adcf
diff --git a/apps/desktop/electron-builder.yml b/apps/desktop/electron-builder.ymlindex 71106c50f5..7fc51b124b 100644--- a/apps/desktop/electron-builder.yml+++ b/apps/desktop/electron-builder.yml@@ -28,4 +28,8 @@ win:target:- nsisartifactName: ${name}-${version}-setup.${ext}+publish:+ provider: github+ owner: multica-ai+ repo: multicanpmRebuild: falsediff --git a/apps/desktop/package.json b/apps/desktop/package.jsonindex 788e95d388..688c3cafc0 100644--- a/apps/desktop/package.json+++ b/apps/desktop/package.json@@ -21,11 +21,12 @@"@dnd-kit/utilities": "^3.2.2","@electron-toolkit/preload": "^3.0.2","@electron-toolkit/utils": "^4.0.0",+ "@fontsource/geist-mono": "^5.2.7",+ "@fontsource/geist-sans": "^5.2.5","@multica/core": "workspace:*","@multica/ui": "workspace:*","@multica/views": "workspace:*",- "@fontsource/geist-mono": "^5.2.7",- "@fontsource/geist-sans": "^5.2.5",+ "electron-updater": "^6.8.3","react-router-dom": "^7.6.0","shadcn": "^4.1.0","sonner": "^2.0.7",diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.tsindex c858bee0b2..631f8d4319 100644--- a/apps/desktop/src/main/index.ts+++ b/apps/desktop/src/main/index.ts@@ -1,6 +1,7 @@import { app, shell, BrowserWindow } from "electron";import { join } from "path";import { electronApp, optimizer, is } from "@electron-toolkit/utils";+import { setupAutoUpdater } from "./updater";let mainWindow: BrowserWindow | null = null;@@ -46,6 +47,8 @@ app.whenReady().then(() => {createWindow();+ setupAutoUpdater(() => mainWindow);+app.on("activate", () => {if (BrowserWindow.getAllWindows().length === 0) createWindow();});diff --git a/apps/desktop/src/main/updater.ts b/apps/desktop/src/main/updater.tsnew file mode 100644index 0000000000..f2f4f9c594--- /dev/null+++ b/apps/desktop/src/main/updater.ts@@ -0,0 +1,46 @@+import { autoUpdater } from "electron-updater";+import { BrowserWindow, ipcMain } from "electron";++autoUpdater.autoDownload = false;+autoUpdater.autoInstallOnAppQuit = true;++export function setupAutoUpdater(getMainWindow: () => BrowserWindow | null): void {+ autoUpdater.on("update-available", (info) => {+ const win = getMainWindow();+ win?.webContents.send("updater:update-available", {+ version: info.version,+ releaseNotes: info.releaseNotes,+ });+ });++ autoUpdater.on("download-progress", (progress) => {+ const win = getMainWindow();+ win?.webContents.send("updater:download-progress", {+ percent: progress.percent,+ });+ });++ autoUpdater.on("update-downloaded", () => {+ const win = getMainWindow();+ win?.webContents.send("updater:update-downloaded");+ });++ autoUpdater.on("error", (err) => {+ console.error("Auto-updater error:", err);+ });++ ipcMain.handle("updater:download", () => {+ return autoUpdater.downloadUpdate();+ });++ ipcMain.handle("updater:install", () => {+ autoUpdater.quitAndInstall(false, true);+ });++ // Check for updates after a short delay to avoid blocking startup+ setTimeout(() => {+ autoUpdater.checkForUpdates().catch((err) => {+ console.error("Failed to check for updates:", err);+ });+ }, 5000);+}diff --git a/apps/desktop/src/preload/index.d.ts b/apps/desktop/src/preload/index.d.tsindex a0bbf5f6e0..3f29792e81 100644--- a/apps/desktop/src/preload/index.d.ts+++ b/apps/desktop/src/preload/index.d.ts@@ -1,8 +1,17 @@import { ElectronAPI } from "@electron-toolkit/preload";+interface UpdaterAPI {+ onUpdateAvailable: (callback: (info: { version: string; releaseNotes?: string }) => void) => () => void;+ onDownloadProgress: (callback: (progress: { percent: number }) => void) => () => void;+ onUpdateDownloaded: (callback: () => void) => () => void;+ downloadUpdate: () => Promise<void>;+ installUpdate: () => Promise<void>;+}+declare global {interface Window {electron: ElectronAPI;+ updater: UpdaterAPI;}}diff --git a/apps/desktop/src/preload/index.ts b/apps/desktop/src/preload/index.tsindex fac8176162..2c1cf0d2d8 100644--- a/apps/desktop/src/preload/index.ts+++ b/apps/desktop/src/preload/index.ts@@ -1,9 +1,32 @@-import { contextBridge } from "electron";+import { contextBridge, ipcRenderer } from "electron";import { electronAPI } from "@electron-toolkit/preload";+const updaterAPI = {+ onUpdateAvailable: (callback: (info: { version: string; releaseNotes?: string }) => void) => {+ const handler = (_: unknown, info: { version: string; releaseNotes?: string }) => callback(info);+ ipcRenderer.on("updater:update-available", handler);+ return () => ipcRenderer.removeListener("updater:update-available", handler);+ },+ onDownloadProgress: (callback: (progress: { percent: number }) => void) => {+ const handler = (_: unknown, progress: { percent: number }) => callback(progress);+ ipcRenderer.on("updater:download-progress", handler);+ return () => ipcRenderer.removeListener("updater:download-progress", handler);+ },+ onUpdateDownloaded: (callback: () => void) => {+ const handler = () => callback();+ ipcRenderer.on("updater:update-downloaded", handler);+ return () => ipcRenderer.removeListener("updater:update-downloaded", handler);+ },+ downloadUpdate: () => ipcRenderer.invoke("updater:download"),+ installUpdate: () => ipcRenderer.invoke("updater:install"),+};+if (process.contextIsolated) {contextBridge.exposeInMainWorld("electron", electronAPI);+ contextBridge.exposeInMainWorld("updater", updaterAPI);} else {// @ts-expect-error - fallback for non-isolated contextwindow.electron = electronAPI;+ // @ts-expect-error - fallback for non-isolated context+ window.updater = updaterAPI;}diff --git a/apps/desktop/src/renderer/src/App.tsx b/apps/desktop/src/renderer/src/App.tsxindex b1617efd5f..0d41097f09 100644--- a/apps/desktop/src/renderer/src/App.tsx+++ b/apps/desktop/src/renderer/src/App.tsx@@ -5,6 +5,7 @@ import { MulticaIcon } from "@multica/ui/components/common/multica-icon";import { Toaster } from "sonner";import { DesktopLoginPage } from "./pages/login";import { DesktopShell } from "./components/desktop-layout";+import { UpdateNotification } from "./components/update-notification";function AppContent() {const user = useAuthStore((s) => s.user);@@ -32,6 +33,7 @@ export default function App() {<AppContent /></CoreProvider><Toaster />+ <UpdateNotification /></ThemeProvider>);}diff --git a/apps/desktop/src/renderer/src/components/update-notification.tsx b/apps/desktop/src/renderer/src/components/update-notification.tsxnew file mode 100644index 0000000000..2cb4bf8c48--- /dev/null+++ b/apps/desktop/src/renderer/src/components/update-notification.tsx@@ -0,0 +1,120 @@+import { useCallback, useEffect, useState } from "react";+import { ArrowDownToLine, RefreshCw, X } from "lucide-react";++type UpdateState =+ | { status: "idle" }+ | { status: "available"; version: string }+ | { status: "downloading"; percent: number }+ | { status: "ready" };++export function UpdateNotification() {+ const [state, setState] = useState<UpdateState>({ status: "idle" });+ const [dismissed, setDismissed] = useState(false);++ useEffect(() => {+ const cleanups: (() => void)[] = [];++ cleanups.push(+ window.updater.onUpdateAvailable((info) => {+ setState({ status: "available", version: info.version });+ setDismissed(false);+ }),+ );++ cleanups.push(+ window.updater.onDownloadProgress((progress) => {+ setState({ status: "downloading", percent: progress.percent });+ }),+ );++ cleanups.push(+ window.updater.onUpdateDownloaded(() => {+ setState({ status: "ready" });+ }),+ );++ return () => cleanups.forEach((fn) => fn());+ }, []);++ const handleDownload = useCallback(() => {+ setState({ status: "downloading", percent: 0 });+ window.updater.downloadUpdate();+ }, []);++ const handleInstall = useCallback(() => {+ window.updater.installUpdate();+ }, []);++ if (state.status === "idle" || dismissed) return null;++ return (+ <div className="fixed bottom-4 right-4 z-50 w-80 rounded-lg border border-border bg-background p-4 shadow-lg animate-in slide-in-from-bottom-2 fade-in duration-300">+ <button+ onClick={() => setDismissed(true)}+ className="absolute top-2 right-2 rounded-md p-1 text-muted-foreground hover:text-foreground transition-colors"+ >+ <X className="size-3.5" />+ </button>++ {state.status === "available" && (+ <div className="flex items-start gap-3">+ <div className="mt-0.5 rounded-md bg-primary/10 p-1.5">+ <ArrowDownToLine className="size-4 text-primary" />+ </div>+ <div className="flex-1 min-w-0">+ <p className="text-sm font-medium">New version available</p>+ <p className="text-xs text-muted-foreground mt-0.5">+ v{state.version} is ready to download+ </p>+ <button+ onClick={handleDownload}+ className="mt-2 inline-flex items-center rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors"+ >+ Download update+ </button>+ </div>+ </div>+ )}++ {state.status === "downloading" && (+ <div className="flex items-start gap-3">+ <div className="mt-0.5 rounded-md bg-primary/10 p-1.5">+ <ArrowDownToLine className="size-4 text-primary animate-pulse" />+ </div>+ <div className="flex-1 min-w-0">+ <p className="text-sm font-medium">Downloading update...</p>+ <div className="mt-2 h-1.5 w-full rounded-full bg-muted overflow-hidden">+ <div+ className="h-full rounded-full bg-primary transition-all duration-300"+ style={{ width: `${Math.round(state.percent)}%` }}+ />+ </div>+ <p className="text-xs text-muted-foreground mt-1">+ {Math.round(state.percent)}%+ </p>+ </div>+ </div>+ )}++ {state.status === "ready" && (+ <div className="flex items-start gap-3">+ <div className="mt-0.5 rounded-md bg-green-500/10 p-1.5">+ <RefreshCw className="size-4 text-green-600 dark:text-green-400" />+ </div>+ <div className="flex-1 min-w-0">+ <p className="text-sm font-medium">Update ready</p>+ <p className="text-xs text-muted-foreground mt-0.5">+ Restart to apply the update+ </p>+ <button+ onClick={handleInstall}+ className="mt-2 inline-flex items-center rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors"+ >+ Restart now+ </button>+ </div>+ </div>+ )}+ </div>+ );+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 0875558629..b8adb0b5fa 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -123,6 +123,9 @@ importers:'@multica/views':specifier: workspace:*version: link:../../packages/views+ electron-updater:+ specifier: ^6.8.3+ version: 6.8.3react-router-dom:specifier: ^7.6.0@@ -3639,6 +3642,9 @@ packages:resolution: {integrity: sha512-L2C7Q279W2D/J4PLZLk7sebOILDSWos7bMsMNN06rK482umHUrh/3lM8G7IlHFOYip2oAg5nha1rCMxr/rs6ZQ==}+ resolution: {integrity: sha512-Z6sgw3jgbikWKXei1ENdqFOxBP0WlXg3TtKfz0rgw2vIZFJUyI4pD7ZN7jrkm7EoMK+tcm/qTnPUdqfZukBlBQ==}+resolution: {integrity: sha512-OHp/vjdlubNlhNkPkL/+3JD34ii5ov7M0GpuXEVdQeqdQ3ulvVR7Dg/rNBLfS5XPIFwgoBLDf9sjjrL+CuDyRQ==}engines: {node: ^20.19.0 || >=22.12.0}@@ -4836,6 +4842,13 @@ packages:resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==}engines: {node: '>=10'}+ resolution: {integrity: sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw==}++ resolution: {integrity: sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==}+ deprecated: This package is deprecated. Use require('node:util').isDeepStrictEqual instead.+resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==}@@ -6349,6 +6362,9 @@ packages:resolution: {integrity: sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==}+ resolution: {integrity: sha512-qVtvMxeXbVej0cQWKqVSSAHmKZEHAvxdF8HEUBFWts8h+xEo5m/lEiPakuyZ3BnCBjOD8i24kzNOiOLLgsSxhA==}+resolution: {integrity: sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==}@@ -9798,6 +9814,19 @@ snapshots:+ dependencies:+ builder-util-runtime: 9.5.1+ fs-extra: 10.1.0+ js-yaml: 4.1.1+ lazy-val: 1.0.5+ lodash.escaperegexp: 4.1.2+ lodash.isequal: 4.5.0+ semver: 7.7.4+ tiny-typed-emitter: 2.1.0+ transitivePeerDependencies:+ - supports-color+dependencies:'@babel/core': 7.29.0@@ -11260,6 +11289,10 @@ snapshots:dependencies:p-locate: 5.0.0+ [email protected]: {}++ [email protected]: {}+@@ -13329,6 +13362,8 @@ snapshots:+ [email protected]: {}+