add desktop tray and updater support (#1193)
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@@ -6,6 +6,10 @@ directories:
|
||||
output: release
|
||||
buildResources: build
|
||||
|
||||
publish:
|
||||
provider: generic
|
||||
url: https://download.ekkolearnai.com
|
||||
|
||||
# Don't auto-prune our root node_modules; we curate `files` and `extraResources` ourselves.
|
||||
buildDependenciesFromSource: false
|
||||
nodeGypRebuild: false
|
||||
@@ -25,6 +29,7 @@ extraResources:
|
||||
to: "build"
|
||||
filter:
|
||||
- "icon.png"
|
||||
- "trayTemplate.png"
|
||||
- from: "../.."
|
||||
to: "webui"
|
||||
filter:
|
||||
@@ -49,6 +54,8 @@ mac:
|
||||
target:
|
||||
- target: dmg
|
||||
arch: [arm64, x64]
|
||||
- target: zip
|
||||
arch: [arm64, x64]
|
||||
category: public.app-category.developer-tools
|
||||
hardenedRuntime: true
|
||||
gatekeeperAssess: false
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "hermes-studio",
|
||||
"version": "0.6.7",
|
||||
"version": "0.6.8",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "hermes-studio",
|
||||
"version": "0.6.7",
|
||||
"version": "0.6.8",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"electron-updater": "^6.3.9"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hermes-studio",
|
||||
"version": "0.6.7",
|
||||
"version": "0.6.8",
|
||||
"description": "Hermes Studio desktop distribution with bundled Python runtime and hermes-agent",
|
||||
"homepage": "https://ekkolearnai.com",
|
||||
"author": {
|
||||
@@ -33,4 +33,4 @@
|
||||
"dependencies": {
|
||||
"electron-updater": "^6.3.9"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
import { app } from 'electron'
|
||||
|
||||
type DesktopLocale = 'en' | 'zh' | 'zh-TW' | 'ja' | 'ko' | 'fr' | 'es' | 'de' | 'pt'
|
||||
|
||||
type TranslationKey =
|
||||
| 'tray.show'
|
||||
| 'tray.hide'
|
||||
| 'tray.checkForUpdates'
|
||||
| 'tray.openAtLogin'
|
||||
| 'tray.quit'
|
||||
| 'update.upToDateTitle'
|
||||
| 'update.upToDateMessage'
|
||||
| 'update.checkingTitle'
|
||||
| 'update.checkingMessage'
|
||||
| 'update.currentVersion'
|
||||
| 'update.availableTitle'
|
||||
| 'update.availableMessage'
|
||||
| 'update.downloading'
|
||||
| 'update.readyTitle'
|
||||
| 'update.readyMessage'
|
||||
| 'update.readyDetail'
|
||||
| 'update.restartNow'
|
||||
| 'update.download'
|
||||
| 'update.later'
|
||||
| 'update.failedTitle'
|
||||
| 'update.failedMessage'
|
||||
| 'update.packagedOnlyMessage'
|
||||
| 'common.ok'
|
||||
|
||||
const supportedLocales: DesktopLocale[] = ['en', 'zh', 'zh-TW', 'ja', 'ko', 'fr', 'es', 'de', 'pt']
|
||||
|
||||
const translations: Record<DesktopLocale, Record<TranslationKey, string>> = {
|
||||
en: {
|
||||
'tray.show': 'Show Hermes Studio',
|
||||
'tray.hide': 'Hide Hermes Studio',
|
||||
'tray.checkForUpdates': 'Check for Updates',
|
||||
'tray.openAtLogin': 'Open at Login',
|
||||
'tray.quit': 'Quit Hermes Studio',
|
||||
'update.upToDateTitle': 'Hermes Studio',
|
||||
'update.upToDateMessage': 'Hermes Studio is up to date.',
|
||||
'update.checkingTitle': 'Hermes Studio',
|
||||
'update.checkingMessage': 'Checking for updates...',
|
||||
'update.currentVersion': 'Current version: {version}',
|
||||
'update.availableTitle': 'Update available',
|
||||
'update.availableMessage': 'Hermes Studio {version} is available.',
|
||||
'update.downloading': 'The update is downloading in the background.',
|
||||
'update.readyTitle': 'Update ready',
|
||||
'update.readyMessage': 'Hermes Studio {version} is ready to install.',
|
||||
'update.readyDetail': 'Restart now to apply the update, or it will be installed on next quit.',
|
||||
'update.restartNow': 'Restart now',
|
||||
'update.download': 'Download',
|
||||
'update.later': 'Later',
|
||||
'update.failedTitle': 'Update check failed',
|
||||
'update.failedMessage': 'Could not check for Hermes Studio updates.',
|
||||
'update.packagedOnlyMessage': 'Automatic updates are only available in the packaged desktop app.',
|
||||
'common.ok': 'OK',
|
||||
},
|
||||
zh: {
|
||||
'tray.show': '显示 Hermes Studio',
|
||||
'tray.hide': '隐藏 Hermes Studio',
|
||||
'tray.checkForUpdates': '检查更新',
|
||||
'tray.openAtLogin': '开机启动',
|
||||
'tray.quit': '退出 Hermes Studio',
|
||||
'update.upToDateTitle': 'Hermes Studio',
|
||||
'update.upToDateMessage': 'Hermes Studio 已是最新版本。',
|
||||
'update.checkingTitle': 'Hermes Studio',
|
||||
'update.checkingMessage': '正在检查更新...',
|
||||
'update.currentVersion': '当前版本:{version}',
|
||||
'update.availableTitle': '发现新版本',
|
||||
'update.availableMessage': 'Hermes Studio {version} 可用。',
|
||||
'update.downloading': '更新正在后台下载。',
|
||||
'update.readyTitle': '更新已就绪',
|
||||
'update.readyMessage': 'Hermes Studio {version} 已准备好安装。',
|
||||
'update.readyDetail': '立即重启以应用更新,或下次退出时自动安装。',
|
||||
'update.restartNow': '立即重启',
|
||||
'update.download': '下载',
|
||||
'update.later': '稍后',
|
||||
'update.failedTitle': '检查更新失败',
|
||||
'update.failedMessage': '无法检查 Hermes Studio 更新。',
|
||||
'update.packagedOnlyMessage': '自动更新仅在打包后的桌面应用中可用。',
|
||||
'common.ok': '确定',
|
||||
},
|
||||
'zh-TW': {
|
||||
'tray.show': '顯示 Hermes Studio',
|
||||
'tray.hide': '隱藏 Hermes Studio',
|
||||
'tray.checkForUpdates': '檢查更新',
|
||||
'tray.openAtLogin': '開機啟動',
|
||||
'tray.quit': '結束 Hermes Studio',
|
||||
'update.upToDateTitle': 'Hermes Studio',
|
||||
'update.upToDateMessage': 'Hermes Studio 已是最新版本。',
|
||||
'update.checkingTitle': 'Hermes Studio',
|
||||
'update.checkingMessage': '正在檢查更新...',
|
||||
'update.currentVersion': '目前版本:{version}',
|
||||
'update.availableTitle': '發現新版本',
|
||||
'update.availableMessage': 'Hermes Studio {version} 可用。',
|
||||
'update.downloading': '更新正在背景下載。',
|
||||
'update.readyTitle': '更新已就緒',
|
||||
'update.readyMessage': 'Hermes Studio {version} 已準備好安裝。',
|
||||
'update.readyDetail': '立即重新啟動以套用更新,或下次結束時自動安裝。',
|
||||
'update.restartNow': '立即重新啟動',
|
||||
'update.download': '下載',
|
||||
'update.later': '稍後',
|
||||
'update.failedTitle': '檢查更新失敗',
|
||||
'update.failedMessage': '無法檢查 Hermes Studio 更新。',
|
||||
'update.packagedOnlyMessage': '自動更新僅可在打包後的桌面應用中使用。',
|
||||
'common.ok': '確定',
|
||||
},
|
||||
ja: {
|
||||
'tray.show': 'Hermes Studio を表示',
|
||||
'tray.hide': 'Hermes Studio を隠す',
|
||||
'tray.checkForUpdates': 'アップデートを確認',
|
||||
'tray.openAtLogin': 'ログイン時に開く',
|
||||
'tray.quit': 'Hermes Studio を終了',
|
||||
'update.upToDateTitle': 'Hermes Studio',
|
||||
'update.upToDateMessage': 'Hermes Studio は最新です。',
|
||||
'update.checkingTitle': 'Hermes Studio',
|
||||
'update.checkingMessage': 'アップデートを確認しています...',
|
||||
'update.currentVersion': '現在のバージョン: {version}',
|
||||
'update.availableTitle': 'アップデートがあります',
|
||||
'update.availableMessage': 'Hermes Studio {version} が利用できます。',
|
||||
'update.downloading': 'アップデートをバックグラウンドでダウンロードしています。',
|
||||
'update.readyTitle': 'アップデートの準備ができました',
|
||||
'update.readyMessage': 'Hermes Studio {version} をインストールできます。',
|
||||
'update.readyDetail': '今すぐ再起動して適用するか、次回終了時にインストールされます。',
|
||||
'update.restartNow': '今すぐ再起動',
|
||||
'update.download': 'ダウンロード',
|
||||
'update.later': '後で',
|
||||
'update.failedTitle': 'アップデート確認に失敗しました',
|
||||
'update.failedMessage': 'Hermes Studio のアップデートを確認できませんでした。',
|
||||
'update.packagedOnlyMessage': '自動アップデートはパッケージ版デスクトップアプリでのみ利用できます。',
|
||||
'common.ok': 'OK',
|
||||
},
|
||||
ko: {
|
||||
'tray.show': 'Hermes Studio 표시',
|
||||
'tray.hide': 'Hermes Studio 숨기기',
|
||||
'tray.checkForUpdates': '업데이트 확인',
|
||||
'tray.openAtLogin': '로그인 시 열기',
|
||||
'tray.quit': 'Hermes Studio 종료',
|
||||
'update.upToDateTitle': 'Hermes Studio',
|
||||
'update.upToDateMessage': 'Hermes Studio가 최신 버전입니다.',
|
||||
'update.checkingTitle': 'Hermes Studio',
|
||||
'update.checkingMessage': '업데이트를 확인하는 중...',
|
||||
'update.currentVersion': '현재 버전: {version}',
|
||||
'update.availableTitle': '업데이트 사용 가능',
|
||||
'update.availableMessage': 'Hermes Studio {version}을 사용할 수 있습니다.',
|
||||
'update.downloading': '업데이트를 백그라운드에서 다운로드하고 있습니다.',
|
||||
'update.readyTitle': '업데이트 준비 완료',
|
||||
'update.readyMessage': 'Hermes Studio {version}을 설치할 준비가 되었습니다.',
|
||||
'update.readyDetail': '지금 다시 시작해 업데이트를 적용하거나 다음 종료 시 설치합니다.',
|
||||
'update.restartNow': '지금 다시 시작',
|
||||
'update.download': '다운로드',
|
||||
'update.later': '나중에',
|
||||
'update.failedTitle': '업데이트 확인 실패',
|
||||
'update.failedMessage': 'Hermes Studio 업데이트를 확인할 수 없습니다.',
|
||||
'update.packagedOnlyMessage': '자동 업데이트는 패키징된 데스크톱 앱에서만 사용할 수 있습니다.',
|
||||
'common.ok': '확인',
|
||||
},
|
||||
fr: {
|
||||
'tray.show': 'Afficher Hermes Studio',
|
||||
'tray.hide': 'Masquer Hermes Studio',
|
||||
'tray.checkForUpdates': 'Rechercher les mises a jour',
|
||||
'tray.openAtLogin': 'Ouvrir a la connexion',
|
||||
'tray.quit': 'Quitter Hermes Studio',
|
||||
'update.upToDateTitle': 'Hermes Studio',
|
||||
'update.upToDateMessage': 'Hermes Studio est a jour.',
|
||||
'update.checkingTitle': 'Hermes Studio',
|
||||
'update.checkingMessage': 'Recherche de mises a jour...',
|
||||
'update.currentVersion': 'Version actuelle : {version}',
|
||||
'update.availableTitle': 'Mise a jour disponible',
|
||||
'update.availableMessage': 'Hermes Studio {version} est disponible.',
|
||||
'update.downloading': 'La mise a jour se telecharge en arriere-plan.',
|
||||
'update.readyTitle': 'Mise a jour prete',
|
||||
'update.readyMessage': 'Hermes Studio {version} est pret a etre installe.',
|
||||
'update.readyDetail': 'Redemarrez maintenant pour appliquer la mise a jour, ou elle sera installee a la prochaine fermeture.',
|
||||
'update.restartNow': 'Redemarrer maintenant',
|
||||
'update.download': 'Telecharger',
|
||||
'update.later': 'Plus tard',
|
||||
'update.failedTitle': 'Echec de la recherche de mise a jour',
|
||||
'update.failedMessage': 'Impossible de rechercher les mises a jour de Hermes Studio.',
|
||||
'update.packagedOnlyMessage': 'Les mises a jour automatiques ne sont disponibles que dans l application de bureau packagee.',
|
||||
'common.ok': 'OK',
|
||||
},
|
||||
es: {
|
||||
'tray.show': 'Mostrar Hermes Studio',
|
||||
'tray.hide': 'Ocultar Hermes Studio',
|
||||
'tray.checkForUpdates': 'Buscar actualizaciones',
|
||||
'tray.openAtLogin': 'Abrir al iniciar sesion',
|
||||
'tray.quit': 'Salir de Hermes Studio',
|
||||
'update.upToDateTitle': 'Hermes Studio',
|
||||
'update.upToDateMessage': 'Hermes Studio esta actualizado.',
|
||||
'update.checkingTitle': 'Hermes Studio',
|
||||
'update.checkingMessage': 'Buscando actualizaciones...',
|
||||
'update.currentVersion': 'Version actual: {version}',
|
||||
'update.availableTitle': 'Actualizacion disponible',
|
||||
'update.availableMessage': 'Hermes Studio {version} esta disponible.',
|
||||
'update.downloading': 'La actualizacion se esta descargando en segundo plano.',
|
||||
'update.readyTitle': 'Actualizacion lista',
|
||||
'update.readyMessage': 'Hermes Studio {version} esta listo para instalarse.',
|
||||
'update.readyDetail': 'Reinicia ahora para aplicar la actualizacion, o se instalara al salir.',
|
||||
'update.restartNow': 'Reiniciar ahora',
|
||||
'update.download': 'Descargar',
|
||||
'update.later': 'Mas tarde',
|
||||
'update.failedTitle': 'Error al buscar actualizaciones',
|
||||
'update.failedMessage': 'No se pudieron buscar actualizaciones de Hermes Studio.',
|
||||
'update.packagedOnlyMessage': 'Las actualizaciones automaticas solo estan disponibles en la app de escritorio empaquetada.',
|
||||
'common.ok': 'Aceptar',
|
||||
},
|
||||
de: {
|
||||
'tray.show': 'Hermes Studio anzeigen',
|
||||
'tray.hide': 'Hermes Studio ausblenden',
|
||||
'tray.checkForUpdates': 'Nach Updates suchen',
|
||||
'tray.openAtLogin': 'Beim Anmelden offnen',
|
||||
'tray.quit': 'Hermes Studio beenden',
|
||||
'update.upToDateTitle': 'Hermes Studio',
|
||||
'update.upToDateMessage': 'Hermes Studio ist auf dem neuesten Stand.',
|
||||
'update.checkingTitle': 'Hermes Studio',
|
||||
'update.checkingMessage': 'Suche nach Updates...',
|
||||
'update.currentVersion': 'Aktuelle Version: {version}',
|
||||
'update.availableTitle': 'Update verfugbar',
|
||||
'update.availableMessage': 'Hermes Studio {version} ist verfugbar.',
|
||||
'update.downloading': 'Das Update wird im Hintergrund heruntergeladen.',
|
||||
'update.readyTitle': 'Update bereit',
|
||||
'update.readyMessage': 'Hermes Studio {version} ist zur Installation bereit.',
|
||||
'update.readyDetail': 'Jetzt neu starten, um das Update anzuwenden, oder es wird beim nachsten Beenden installiert.',
|
||||
'update.restartNow': 'Jetzt neu starten',
|
||||
'update.download': 'Herunterladen',
|
||||
'update.later': 'Spater',
|
||||
'update.failedTitle': 'Update-Prufung fehlgeschlagen',
|
||||
'update.failedMessage': 'Updates fur Hermes Studio konnten nicht gepruft werden.',
|
||||
'update.packagedOnlyMessage': 'Automatische Updates sind nur in der paketierten Desktop-App verfugbar.',
|
||||
'common.ok': 'OK',
|
||||
},
|
||||
pt: {
|
||||
'tray.show': 'Mostrar Hermes Studio',
|
||||
'tray.hide': 'Ocultar Hermes Studio',
|
||||
'tray.checkForUpdates': 'Verificar atualizacoes',
|
||||
'tray.openAtLogin': 'Abrir ao iniciar sessao',
|
||||
'tray.quit': 'Sair do Hermes Studio',
|
||||
'update.upToDateTitle': 'Hermes Studio',
|
||||
'update.upToDateMessage': 'Hermes Studio esta atualizado.',
|
||||
'update.checkingTitle': 'Hermes Studio',
|
||||
'update.checkingMessage': 'Verificando atualizacoes...',
|
||||
'update.currentVersion': 'Versao atual: {version}',
|
||||
'update.availableTitle': 'Atualizacao disponivel',
|
||||
'update.availableMessage': 'Hermes Studio {version} esta disponivel.',
|
||||
'update.downloading': 'A atualizacao esta sendo baixada em segundo plano.',
|
||||
'update.readyTitle': 'Atualizacao pronta',
|
||||
'update.readyMessage': 'Hermes Studio {version} esta pronto para instalar.',
|
||||
'update.readyDetail': 'Reinicie agora para aplicar a atualizacao, ou ela sera instalada ao sair.',
|
||||
'update.restartNow': 'Reiniciar agora',
|
||||
'update.download': 'Baixar',
|
||||
'update.later': 'Depois',
|
||||
'update.failedTitle': 'Falha ao verificar atualizacoes',
|
||||
'update.failedMessage': 'Nao foi possivel verificar atualizacoes do Hermes Studio.',
|
||||
'update.packagedOnlyMessage': 'Atualizacoes automaticas estao disponiveis apenas no app desktop empacotado.',
|
||||
'common.ok': 'OK',
|
||||
},
|
||||
}
|
||||
|
||||
function resolveLocale(): DesktopLocale {
|
||||
const tag = app.getLocale()
|
||||
const lower = tag.toLowerCase()
|
||||
if (lower.startsWith('zh')) {
|
||||
return lower.includes('hant') || lower.includes('-tw') || lower.includes('-hk') || lower.includes('-mo')
|
||||
? 'zh-TW'
|
||||
: 'zh'
|
||||
}
|
||||
|
||||
const short = tag.slice(0, 2) as DesktopLocale
|
||||
return supportedLocales.includes(short) ? short : 'en'
|
||||
}
|
||||
|
||||
export function t(key: TranslationKey, params: Record<string, string> = {}): string {
|
||||
const message = translations[resolveLocale()][key] || translations.en[key]
|
||||
return Object.entries(params).reduce(
|
||||
(value, [name, replacement]) => value.replaceAll(`{${name}}`, replacement),
|
||||
message,
|
||||
)
|
||||
}
|
||||
@@ -1,13 +1,106 @@
|
||||
import { app, BrowserWindow, Menu, shell, ipcMain } from 'electron'
|
||||
import { app, BrowserWindow, Menu, Tray, shell, ipcMain, nativeImage } from 'electron'
|
||||
import { join } from 'node:path'
|
||||
import { startWebUiServer, stopWebUiServer, getToken } from './webui-server'
|
||||
import { desktopIcon, hermesBinExists, hermesBin } from './paths'
|
||||
import { initAutoUpdater } from './updater'
|
||||
import { desktopIcon, desktopTrayTemplateIcon, hermesBinExists, hermesBin } from './paths'
|
||||
import { checkForDesktopUpdates, initAutoUpdater } from './updater'
|
||||
import { t } from './desktop-i18n'
|
||||
|
||||
const PORT = Number(process.env.HERMES_DESKTOP_PORT) || 8748
|
||||
const START_HIDDEN = process.argv.includes('--hidden')
|
||||
|
||||
let mainWindow: BrowserWindow | null = null
|
||||
let serverUrl: string | null = null
|
||||
let tray: Tray | null = null
|
||||
let isQuitting = false
|
||||
|
||||
function showMainWindow() {
|
||||
if (!mainWindow) {
|
||||
createWindow()
|
||||
}
|
||||
if (!mainWindow) return
|
||||
if (mainWindow.isMinimized()) mainWindow.restore()
|
||||
mainWindow.show()
|
||||
mainWindow.focus()
|
||||
}
|
||||
|
||||
function quitApp() {
|
||||
isQuitting = true
|
||||
app.quit()
|
||||
}
|
||||
|
||||
function getOpenAtLogin(): boolean {
|
||||
return app.getLoginItemSettings().openAtLogin
|
||||
}
|
||||
|
||||
function setOpenAtLogin(openAtLogin: boolean) {
|
||||
app.setLoginItemSettings({
|
||||
openAtLogin,
|
||||
openAsHidden: true,
|
||||
path: process.execPath,
|
||||
args: ['--hidden'],
|
||||
})
|
||||
}
|
||||
|
||||
function updateTrayMenu() {
|
||||
if (!tray) return
|
||||
const isVisible = !!mainWindow && mainWindow.isVisible()
|
||||
const menu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: isVisible ? t('tray.hide') : t('tray.show'),
|
||||
click: () => {
|
||||
if (mainWindow?.isVisible()) {
|
||||
mainWindow.hide()
|
||||
} else {
|
||||
showMainWindow()
|
||||
}
|
||||
updateTrayMenu()
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t('tray.checkForUpdates'),
|
||||
click: () => {
|
||||
checkForDesktopUpdates(true).catch(err => {
|
||||
console.error('[tray] update check failed:', err)
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t('tray.openAtLogin'),
|
||||
type: 'checkbox',
|
||||
checked: getOpenAtLogin(),
|
||||
click: (item) => {
|
||||
setOpenAtLogin(item.checked)
|
||||
updateTrayMenu()
|
||||
},
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: t('tray.quit'),
|
||||
click: quitApp,
|
||||
},
|
||||
])
|
||||
tray.setContextMenu(menu)
|
||||
}
|
||||
|
||||
function createTray() {
|
||||
if (tray) return
|
||||
const source = process.platform === 'darwin' ? desktopTrayTemplateIcon() : desktopIcon()
|
||||
const icon = nativeImage.createFromPath(source).resize({
|
||||
width: process.platform === 'darwin' ? 18 : 16,
|
||||
height: process.platform === 'darwin' ? 18 : 16,
|
||||
quality: 'best',
|
||||
})
|
||||
if (process.platform === 'darwin') {
|
||||
icon.setTemplateImage(true)
|
||||
}
|
||||
tray = new Tray(icon)
|
||||
tray.setToolTip('Hermes Studio')
|
||||
tray.on('click', () => {
|
||||
showMainWindow()
|
||||
updateTrayMenu()
|
||||
})
|
||||
updateTrayMenu()
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
mainWindow = new BrowserWindow({
|
||||
@@ -18,6 +111,7 @@ function createWindow() {
|
||||
title: 'Hermes Studio',
|
||||
backgroundColor: '#1a1a1a',
|
||||
autoHideMenuBar: true,
|
||||
show: !START_HIDDEN,
|
||||
...(process.platform === 'linux' ? { icon: desktopIcon() } : {}),
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '..', 'preload', 'index.js'),
|
||||
@@ -27,6 +121,16 @@ function createWindow() {
|
||||
},
|
||||
})
|
||||
|
||||
mainWindow.on('close', (event) => {
|
||||
if (isQuitting) return
|
||||
event.preventDefault()
|
||||
mainWindow?.hide()
|
||||
updateTrayMenu()
|
||||
})
|
||||
|
||||
mainWindow.on('show', updateTrayMenu)
|
||||
mainWindow.on('hide', updateTrayMenu)
|
||||
|
||||
// External links → system browser
|
||||
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||
if (url.startsWith('http://127.0.0.1') || url.startsWith('http://localhost')) {
|
||||
@@ -44,6 +148,7 @@ function createWindow() {
|
||||
} else {
|
||||
mainWindow.loadURL(splashHtml())
|
||||
}
|
||||
updateTrayMenu()
|
||||
}
|
||||
|
||||
function splashHtml(): string {
|
||||
@@ -95,10 +200,7 @@ if (!gotLock) {
|
||||
app.quit()
|
||||
} else {
|
||||
app.on('second-instance', () => {
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore()
|
||||
mainWindow.focus()
|
||||
}
|
||||
showMainWindow()
|
||||
})
|
||||
|
||||
app.whenReady().then(() => {
|
||||
@@ -107,25 +209,34 @@ if (!gotLock) {
|
||||
// visual clutter. macOS keeps a menu (system requirement) but Electron's
|
||||
// default is fine there.
|
||||
if (process.platform !== 'darwin') Menu.setApplicationMenu(null)
|
||||
createTray()
|
||||
createWindow()
|
||||
bootstrap()
|
||||
initAutoUpdater()
|
||||
initAutoUpdater({
|
||||
beforeQuitAndInstall: () => {
|
||||
isQuitting = true
|
||||
},
|
||||
})
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow()
|
||||
} else if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore()
|
||||
mainWindow.show()
|
||||
mainWindow.focus()
|
||||
showMainWindow()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') app.quit()
|
||||
if (isQuitting && process.platform !== 'darwin') app.quit()
|
||||
})
|
||||
|
||||
app.on('before-quit', async (e) => {
|
||||
if (!isQuitting && process.platform !== 'darwin') {
|
||||
e.preventDefault()
|
||||
mainWindow?.hide()
|
||||
updateTrayMenu()
|
||||
return
|
||||
}
|
||||
e.preventDefault()
|
||||
await stopWebUiServer().catch(() => undefined)
|
||||
app.exit(0)
|
||||
|
||||
@@ -45,6 +45,11 @@ export function desktopIcon(): string {
|
||||
return resolve(app.getAppPath(), 'build', 'icon.png')
|
||||
}
|
||||
|
||||
export function desktopTrayTemplateIcon(): string {
|
||||
if (app.isPackaged) return resolve(process.resourcesPath, 'build', 'trayTemplate.png')
|
||||
return resolve(app.getAppPath(), 'build', 'trayTemplate.png')
|
||||
}
|
||||
|
||||
export function webUiHome(): string {
|
||||
return process.env.HERMES_WEB_UI_HOME?.trim() || resolve(homedir(), '.hermes-web-ui')
|
||||
}
|
||||
|
||||
@@ -1,46 +1,165 @@
|
||||
import { app, dialog } from 'electron'
|
||||
import { autoUpdater } from 'electron-updater'
|
||||
import { autoUpdater, type ProgressInfo, type UpdateDownloadedEvent, type UpdateInfo } from 'electron-updater'
|
||||
import { t } from './desktop-i18n'
|
||||
|
||||
let initialized = false
|
||||
let checking = false
|
||||
let updateDownloaded = false
|
||||
|
||||
export function initAutoUpdater() {
|
||||
const LATEST_RELEASE_URL = 'https://api.github.com/repos/EKKOLearnAI/hermes-web-ui/releases/latest'
|
||||
const CLOUDFLARE_DOWNLOAD_BASE_URL = 'https://download.ekkolearnai.com'
|
||||
|
||||
interface GitHubRelease {
|
||||
tag_name?: string
|
||||
}
|
||||
|
||||
interface AutoUpdaterOptions {
|
||||
beforeQuitAndInstall?: () => void
|
||||
}
|
||||
|
||||
let options: AutoUpdaterOptions = {}
|
||||
|
||||
async function getLatestReleaseTag(): Promise<string> {
|
||||
const res = await fetch(LATEST_RELEASE_URL, {
|
||||
headers: {
|
||||
Accept: 'application/vnd.github+json',
|
||||
'User-Agent': `Hermes-Studio/${app.getVersion()}`,
|
||||
},
|
||||
})
|
||||
if (!res.ok) throw new Error(`GitHub returned ${res.status}`)
|
||||
|
||||
const release = await res.json() as GitHubRelease
|
||||
const tag = release.tag_name?.trim()
|
||||
if (!tag) throw new Error('Latest release response did not include a tag')
|
||||
return tag.startsWith('v') ? tag : `v${tag}`
|
||||
}
|
||||
|
||||
async function configureFeedFromLatestRelease(): Promise<void> {
|
||||
const tag = await getLatestReleaseTag()
|
||||
autoUpdater.setFeedURL({
|
||||
provider: 'generic',
|
||||
url: `${CLOUDFLARE_DOWNLOAD_BASE_URL}/${tag}`,
|
||||
})
|
||||
}
|
||||
|
||||
function showUpToDate(info?: UpdateInfo) {
|
||||
const version = info?.version || app.getVersion()
|
||||
dialog.showMessageBox({
|
||||
type: 'info',
|
||||
title: t('update.upToDateTitle'),
|
||||
message: t('update.upToDateMessage'),
|
||||
detail: t('update.currentVersion', { version }),
|
||||
buttons: [t('common.ok')],
|
||||
}).catch(() => undefined)
|
||||
}
|
||||
|
||||
function showUpdateCheckFailed(err: unknown) {
|
||||
const detail = err instanceof Error ? err.message : String(err)
|
||||
dialog.showMessageBox({
|
||||
type: 'error',
|
||||
title: t('update.failedTitle'),
|
||||
message: t('update.failedMessage'),
|
||||
detail,
|
||||
buttons: [t('common.ok')],
|
||||
}).catch(() => undefined)
|
||||
}
|
||||
|
||||
export function initAutoUpdater(nextOptions: AutoUpdaterOptions = {}) {
|
||||
options = { ...options, ...nextOptions }
|
||||
if (initialized) return
|
||||
initialized = true
|
||||
|
||||
if (!app.isPackaged) return // dev mode: skip
|
||||
if (process.env.HERMES_DESKTOP_ENABLE_AUTO_UPDATE !== 'true') return
|
||||
|
||||
autoUpdater.autoDownload = true
|
||||
autoUpdater.autoInstallOnAppQuit = true
|
||||
|
||||
autoUpdater.on('update-available', info => {
|
||||
console.log(`[updater] update available: ${info.version}`)
|
||||
dialog.showMessageBox({
|
||||
type: 'info',
|
||||
title: t('update.availableTitle'),
|
||||
message: t('update.availableMessage', { version: info.version }),
|
||||
detail: t('update.downloading'),
|
||||
buttons: [t('common.ok')],
|
||||
}).catch(() => undefined)
|
||||
})
|
||||
autoUpdater.on('update-not-available', () => {
|
||||
autoUpdater.on('update-not-available', info => {
|
||||
console.log('[updater] up to date')
|
||||
if (checking) showUpToDate(info)
|
||||
})
|
||||
autoUpdater.on('error', err => {
|
||||
console.error('[updater] error:', err)
|
||||
if (checking) showUpdateCheckFailed(err)
|
||||
})
|
||||
autoUpdater.on('update-downloaded', async info => {
|
||||
autoUpdater.on('download-progress', (info: ProgressInfo) => {
|
||||
console.log(`[updater] download ${Math.round(info.percent)}%`)
|
||||
})
|
||||
autoUpdater.on('update-downloaded', async (info: UpdateDownloadedEvent) => {
|
||||
updateDownloaded = true
|
||||
const { response } = await dialog.showMessageBox({
|
||||
type: 'info',
|
||||
title: 'Update ready',
|
||||
message: `Hermes Studio ${info.version} is ready to install.`,
|
||||
detail: 'Restart now to apply the update, or it will be installed on next quit.',
|
||||
buttons: ['Restart now', 'Later'],
|
||||
title: t('update.readyTitle'),
|
||||
message: t('update.readyMessage', { version: info.version }),
|
||||
detail: t('update.readyDetail'),
|
||||
buttons: [t('update.restartNow'), t('update.later')],
|
||||
defaultId: 0,
|
||||
cancelId: 1,
|
||||
})
|
||||
if (response === 0) autoUpdater.quitAndInstall()
|
||||
if (response === 0) {
|
||||
options.beforeQuitAndInstall?.()
|
||||
autoUpdater.quitAndInstall()
|
||||
}
|
||||
})
|
||||
|
||||
autoUpdater.checkForUpdates().catch(err => {
|
||||
console.error('[updater] initial check failed:', err)
|
||||
})
|
||||
if (process.env.HERMES_DESKTOP_ENABLE_AUTO_UPDATE !== 'false') {
|
||||
checkForDesktopUpdates(false).catch(err => {
|
||||
console.error('[updater] initial check failed:', err)
|
||||
})
|
||||
}
|
||||
|
||||
// Recheck every 6h while app is running
|
||||
setInterval(() => {
|
||||
autoUpdater.checkForUpdates().catch(() => undefined)
|
||||
checkForDesktopUpdates(false).catch(() => undefined)
|
||||
}, 6 * 60 * 60 * 1000)
|
||||
}
|
||||
|
||||
export async function checkForDesktopUpdates(manual: boolean): Promise<void> {
|
||||
if (!app.isPackaged) {
|
||||
if (manual) {
|
||||
await dialog.showMessageBox({
|
||||
type: 'info',
|
||||
title: t('update.checkingTitle'),
|
||||
message: t('update.packagedOnlyMessage'),
|
||||
buttons: [t('common.ok')],
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (updateDownloaded) {
|
||||
options.beforeQuitAndInstall?.()
|
||||
autoUpdater.quitAndInstall()
|
||||
return
|
||||
}
|
||||
|
||||
if (manual) {
|
||||
await dialog.showMessageBox({
|
||||
type: 'info',
|
||||
title: t('update.checkingTitle'),
|
||||
message: t('update.checkingMessage'),
|
||||
buttons: [t('common.ok')],
|
||||
})
|
||||
}
|
||||
|
||||
checking = manual
|
||||
try {
|
||||
await configureFeedFromLatestRelease()
|
||||
await autoUpdater.checkForUpdates()
|
||||
} catch (err) {
|
||||
if (manual) showUpdateCheckFailed(err)
|
||||
throw err
|
||||
} finally {
|
||||
checking = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,27 @@ const execFileAsync = promisify(execFile)
|
||||
let serverProc: ChildProcess | null = null
|
||||
let cachedToken: string | null = null
|
||||
|
||||
function killProcessTree(proc: ChildProcess): void {
|
||||
if (!proc.pid || proc.killed) return
|
||||
if (process.platform === 'win32') {
|
||||
try {
|
||||
const killer = spawn('taskkill.exe', ['/PID', String(proc.pid), '/T', '/F'], {
|
||||
stdio: 'ignore',
|
||||
windowsHide: true,
|
||||
})
|
||||
killer.once('error', () => undefined)
|
||||
return
|
||||
} catch {
|
||||
/* fall through */
|
||||
}
|
||||
}
|
||||
try {
|
||||
proc.kill('SIGKILL')
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
function envPositiveInt(name: string): number | undefined {
|
||||
const raw = process.env[name]
|
||||
if (!raw) return undefined
|
||||
@@ -207,12 +228,14 @@ export async function startWebUiServer(port = DEFAULT_PORT): Promise<string> {
|
||||
// setup is a #!/bin/sh wrapper, not a python interpreter, so detection
|
||||
// resolves to /bin/sh and the bridge crashes (exit code 2) immediately.
|
||||
const isWin = process.platform === 'win32'
|
||||
const bundledPython = isWin
|
||||
? join(pythonDir(), 'python.exe')
|
||||
: join(pythonDir(), 'bin', 'python3')
|
||||
const bundledPythonNoWindow = isWin
|
||||
? join(pythonDir(), 'pythonw.exe')
|
||||
: bundledPython
|
||||
: join(pythonDir(), 'bin', 'python3')
|
||||
const bundledPython = isWin && existsSync(bundledPythonNoWindow)
|
||||
? bundledPythonNoWindow
|
||||
: isWin
|
||||
? join(pythonDir(), 'python.exe')
|
||||
: join(pythonDir(), 'bin', 'python3')
|
||||
const bridgePort = await getFreeTcpPort()
|
||||
const workerPortBase = await getFreeTcpPortInRange(20000, 59000)
|
||||
const loginShellPath = await getLoginShellPath()
|
||||
@@ -312,7 +335,7 @@ export function stopWebUiServer(): Promise<void> {
|
||||
if (!serverProc || serverProc.killed) return resolve()
|
||||
const proc = serverProc
|
||||
const timer = setTimeout(() => {
|
||||
try { proc.kill('SIGKILL') } catch { /* */ }
|
||||
killProcessTree(proc)
|
||||
resolve()
|
||||
}, 3000)
|
||||
proc.once('exit', () => {
|
||||
|
||||
Reference in New Issue
Block a user