mirror of
https://github.com/aipoch/open-science.git
synced 2026-10-02 02:14:40 +08:00
* feat(cli): manage the headless backend as a daemon Add cross-platform start, stop, status, and URL commands so browser-only users can run Open Science in the background while preserving graceful agent and Notebook shutdown. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(tray): headless web menu and Windows context menu visibility Replace Chromium's --headless flag with --open-science-headless so native tray menus render on Windows, and wire headless tray actions for Open Web UI, Copy URL, and Quit. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Ewen <ewen@aipoch.com>
39 lines
1.5 KiB
JavaScript
39 lines
1.5 KiB
JavaScript
/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/explicit-function-return-type */
|
|
|
|
// Starts electron-vite dev with the localhost web service enabled. Use --headless to skip the
|
|
// initial Electron window while keeping the tray, agent runtime, and web UI available.
|
|
const { spawnSync } = require('node:child_process')
|
|
const path = require('node:path')
|
|
|
|
const DEFAULT_WEB_PORT = '44100'
|
|
|
|
// Builds the electron-vite invocation from argv/env: default the web port when unset and forward
|
|
// --headless through electron-vite's `--` passthrough. Pure so it can be unit-tested without spawning.
|
|
const buildDevWebCommand = (argv, env) => {
|
|
const headless = argv.includes('--headless')
|
|
const nextEnv = { ...env }
|
|
if (!nextEnv.OPEN_SCIENCE_WEB_PORT?.trim()) {
|
|
nextEnv.OPEN_SCIENCE_WEB_PORT = DEFAULT_WEB_PORT
|
|
}
|
|
const args = ['electron-vite', 'dev']
|
|
// Pass a namespaced flag to Electron: Chromium consumes a literal `--headless` and renders native
|
|
// menus (like the tray context menu) invisibly on Windows (electron/electron#48982).
|
|
if (headless) args.push('--', '--open-science-headless')
|
|
return { command: 'npx', args, env: nextEnv }
|
|
}
|
|
|
|
const main = () => {
|
|
const { command, args, env } = buildDevWebCommand(process.argv, process.env)
|
|
const result = spawnSync(command, args, {
|
|
cwd: path.join(__dirname, '..'),
|
|
stdio: 'inherit',
|
|
env,
|
|
shell: process.platform === 'win32'
|
|
})
|
|
process.exit(result.status ?? 1)
|
|
}
|
|
|
|
if (require.main === module) main()
|
|
|
|
module.exports = { buildDevWebCommand, DEFAULT_WEB_PORT }
|