Skip to content

Commit d7e9a9e

Browse files
authored
feat: show current version in tray (#465)
1 parent d9e3ee5 commit d7e9a9e

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

main/src/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
binPath,
3333
} from './toolhive-manager'
3434
import log from './logger'
35+
import { getAppVersion } from './util'
3536

3637
Sentry.init({
3738
dsn: import.meta.env.VITE_SENTRY_DSN,
@@ -440,3 +441,7 @@ ipcMain.handle('shutdown-store:clear-history', () => {
440441
clearShutdownHistory()
441442
return { success: true }
442443
})
444+
445+
ipcMain.handle('get-app-version', () => {
446+
return getAppVersion()
447+
})

main/src/system-tray.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'node:path'
33
import { getAutoLaunchStatus, setAutoLaunch } from './auto-launch'
44
import { createApplicationMenu } from './menu'
55
import log from './logger'
6+
import { getAppVersion } from './util'
67

78
///////////////////////////////////////////////////
89
// Tray icon
@@ -136,6 +137,15 @@ const createStatusMenuItem = (toolHiveIsRunning: boolean) => ({
136137
enabled: false,
137138
})
138139

140+
const getCurrentAppVersion = () => {
141+
const appVersion = getAppVersion()
142+
return {
143+
label: `Current version: v${appVersion}`,
144+
type: 'normal' as const,
145+
enabled: false,
146+
}
147+
}
148+
139149
const startOnLoginMenu = (currentTray: Tray, toolHiveIsRunning: boolean) => {
140150
const isStartOnLogin = getAutoLaunchStatus()
141151
return {
@@ -180,6 +190,7 @@ const createSeparator = () => ({ type: 'separator' as const })
180190

181191
const createMenuTemplate = (currentTray: Tray, toolHiveIsRunning: boolean) => [
182192
createStatusMenuItem(toolHiveIsRunning),
193+
getCurrentAppVersion(),
183194
createSeparator(),
184195
startOnLoginMenu(currentTray, toolHiveIsRunning),
185196
createSeparator(),

main/src/util.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { app } from 'electron'
2+
import { execSync } from 'node:child_process'
3+
4+
function getVersionFromGit(): string {
5+
try {
6+
const exactTag = execSync('git describe --exact-match --tags HEAD', {
7+
encoding: 'utf8',
8+
stdio: 'pipe',
9+
}).trim()
10+
11+
return exactTag.replace(/^v/, '')
12+
} catch {
13+
try {
14+
const describe = execSync('git describe --tags --always', {
15+
encoding: 'utf8',
16+
stdio: 'pipe',
17+
}).trim()
18+
19+
return describe.replace(/^v/, '')
20+
} catch {
21+
return app.getVersion()
22+
}
23+
}
24+
}
25+
26+
export function getAppVersion(): string {
27+
if (process.env.SENTRY_RELEASE) {
28+
return process.env.SENTRY_RELEASE
29+
}
30+
31+
return getVersionFromGit()
32+
}

preload/src/preload.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ contextBridge.exposeInMainWorld('electronAPI', {
1616
hideApp: () => ipcRenderer.invoke('hide-app'),
1717
quitApp: () => ipcRenderer.invoke('quit-app'),
1818

19+
// App version
20+
getAppVersion: () => ipcRenderer.invoke('get-app-version'),
21+
1922
// ToolHive port
2023
getToolhivePort: () => ipcRenderer.invoke('get-toolhive-port'),
2124
// ToolHive is running
@@ -88,6 +91,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
8891
})
8992

9093
export interface ElectronAPI {
94+
getAppVersion: () => Promise<string>
9195
getAutoLaunchStatus: () => Promise<boolean>
9296
setAutoLaunch: (enabled: boolean) => Promise<boolean>
9397
showApp: () => Promise<void>

renderer/src/routes/__root.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ export const Route = createRootRouteWithContext<{
7676
queryKey: ['is-toolhive-running'],
7777
queryFn: async () => {
7878
const res = await window.electronAPI.isToolhiveRunning()
79+
const appVersion = await window.electronAPI.getAppVersion()
7980
if (!res) {
8081
log.error('Error ToolHive is not running')
8182
}
82-
log.info('ToolHive is running')
83+
log.info(`ToolHive version ${appVersion} is running`)
8384
return res
8485
},
8586
retry: 3,

0 commit comments

Comments
 (0)