Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/add-auto-updater.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"think-app": patch
---

Add auto-updater for GitHub releases

- Integrate electron-updater with GitHub releases provider
- Add app menu with "Check for Updates..." option
- Show in-app toast notification when update is ready
- Add "Restart" action to apply downloaded updates
16 changes: 12 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ jobs:
CSC_KEY_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PWD }}
run: pnpm build:all:release

- name: Upload DMG artifact
- name: Upload macOS artifacts
uses: actions/upload-artifact@v4
with:
name: electron-app-macos
path: app/release/*.dmg
path: |
app/release/*.dmg
app/release/*.zip
app/release/latest-mac.yml
retention-days: 1

build-windows:
Expand Down Expand Up @@ -216,11 +219,13 @@ jobs:
- name: Build Electron app (NSIS installer)
run: pnpm --filter think-app electron:build

- name: Upload Windows artifact
- name: Upload Windows artifacts
uses: actions/upload-artifact@v4
with:
name: electron-app-windows
path: app/release/*.exe
path: |
app/release/*.exe
app/release/latest.yml
retention-days: 1

upload-release:
Expand All @@ -244,7 +249,10 @@ jobs:
files: |
artifacts/chrome-extension/*.zip
artifacts/electron-app-macos/*.dmg
artifacts/electron-app-macos/*.zip
artifacts/electron-app-macos/latest-mac.yml
artifacts/electron-app-windows/*.exe
artifacts/electron-app-windows/latest.yml
draft: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108 changes: 107 additions & 1 deletion app/electron/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { app, BrowserWindow, ipcMain } = require('electron');
const { app, BrowserWindow, ipcMain, Menu } = require('electron');
const { autoUpdater } = require('electron-updater');
const { spawn, execSync } = require('child_process');
const crypto = require('crypto');
const path = require('path');
Expand Down Expand Up @@ -71,6 +72,25 @@ const HEALTH_CHECK_URL = 'http://localhost:8765/health';
const HEALTH_CHECK_INTERVAL_MS = 200;
const HEALTH_CHECK_TIMEOUT_MS = 30000;

// Configure auto-updater
autoUpdater.autoDownload = true;
autoUpdater.autoInstallOnAppQuit = true;

autoUpdater.on('update-available', (info) => {
console.log('Update available:', info.version);
});

autoUpdater.on('update-downloaded', (info) => {
console.log('Update downloaded:', info.version);
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.webContents.send('update-downloaded', info.version);
}
});

autoUpdater.on('error', (err) => {
console.error('Auto-updater error:', err);
});

/**
* Polls the backend health endpoint until it responds successfully.
* Returns a Promise that resolves when backend is ready, or rejects on timeout.
Expand Down Expand Up @@ -191,6 +211,80 @@ function startPythonBackend() {
});
}

function createMenu() {
const isMac = process.platform === 'darwin';

const template = [
...(isMac ? [{
label: app.name,
submenu: [
{ role: 'about' },
{ type: 'separator' },
{
label: 'Check for Updates...',
click: () => autoUpdater.checkForUpdates()
},
{ type: 'separator' },
{ role: 'services' },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideOthers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' }
]
}] : []),
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'selectAll' }
]
},
{
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'forceReload' },
{ role: 'toggleDevTools' },
{ type: 'separator' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
},
{
label: 'Window',
submenu: [
{ role: 'minimize' },
{ role: 'zoom' },
...(isMac ? [
{ type: 'separator' },
{ role: 'front' }
] : [
{ role: 'close' }
])
]
},
...(!isMac ? [{
label: 'Help',
submenu: [{
label: 'Check for Updates...',
click: () => autoUpdater.checkForUpdates()
}]
}] : [])
];

Menu.setApplicationMenu(Menu.buildFromTemplate(template));
}

function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
Expand Down Expand Up @@ -237,6 +331,14 @@ app.whenReady().then(async () => {
const isDev = !app.isPackaged;
installNativeHost(resourcesPath, undefined, isDev);

// Set up application menu
createMenu();

// Check for updates (only in production)
if (app.isPackaged) {
autoUpdater.checkForUpdatesAndNotify();
}

// Start Ollama if installed (don't wait, let it start in background)
ensureOllamaRunning();

Expand Down Expand Up @@ -437,3 +539,7 @@ ipcMain.handle('pull-model', async (_event, modelName) => {
return { success: false, error: error.message };
}
});

ipcMain.handle('install-update', () => {
autoUpdater.quitAndInstall();
});
8 changes: 8 additions & 0 deletions app/electron/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@ contextBridge.exposeInMainWorld('electronAPI', {
},
// Get the app token for API authentication
getAppToken: () => appToken,
// Auto-update handlers
onUpdateDownloaded: (callback) => {
ipcRenderer.on('update-downloaded', (_, version) => callback(version));
},
removeUpdateListeners: () => {
ipcRenderer.removeAllListeners('update-downloaded');
},
installUpdate: () => ipcRenderer.invoke('install-update'),
});
8 changes: 7 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
],
"mac": {
"icon": "build/icon.icns",
"target": "dmg",
"target": ["dmg", "zip"],
"category": "public.app-category.productivity",
"hardenedRuntime": true,
"gatekeeperAssess": false,
Expand All @@ -55,6 +55,11 @@
"createDesktopShortcut": true,
"createStartMenuShortcut": true,
"shortcutName": "Think"
},
"publish": {
"provider": "github",
"owner": "ThinkFoundation",
"repo": "ThinkOS-Client"
}
},
"dependencies": {
Expand All @@ -65,6 +70,7 @@
"@tiptap/starter-kit": "^3.13.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"electron-updater": "^6.6.2",
"lucide-react": "^0.460.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
21 changes: 21 additions & 0 deletions app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SettingsPage from "./pages/SettingsPage";
import { NamePromptDialog } from "./components/NamePromptDialog";
import { Button } from "@/components/ui/button";
import { Toaster } from "@/components/ui/sonner";
import { toast } from "sonner";
import { useSystemTheme } from "@/hooks/useSystemTheme";
import { initializeApiToken, apiFetch } from "@/lib/api";

Expand Down Expand Up @@ -183,6 +184,26 @@ function App() {
}
}, [appState]);

// Listen for app updates
useEffect(() => {
if (window.electronAPI?.onUpdateDownloaded) {
window.electronAPI.onUpdateDownloaded((version: string) => {
toast("Update Ready", {
description: `Version ${version} is ready to install.`,
action: {
label: "Restart",
onClick: () => window.electronAPI?.installUpdate(),
},
duration: Infinity,
});
});

return () => {
window.electronAPI?.removeUpdateListeners();
};
}
}, []);

if (appState === "waiting_for_backend") {
return (
<div className="flex flex-col items-center justify-center min-h-screen gap-6 bg-background">
Expand Down
4 changes: 4 additions & 0 deletions app/src/SetupWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ declare global {
removeBackendListeners: () => void;
// App token for API authentication
getAppToken: () => string | null;
// Auto-update handlers
onUpdateDownloaded: (callback: (version: string) => void) => void;
removeUpdateListeners: () => void;
installUpdate: () => Promise<void>;
};
}
}
Expand Down
46 changes: 46 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.