feat: add startup launch support (#1421)

Add launch-at-startup support across the Electron desktop app and the web CLI.

Electron now supports macOS launch-at-login through the native login item API. Login launches start OpenChamber in the background without opening a window, while Dock activation, deep links, and second-instance launches still open or focus the normal app window. The desktop Settings UI now exposes a localized launch-at-login toggle in Desktop Network Access.

The web CLI now includes `openchamber startup status|enable|disable`, backed by native user services:
- macOS: launchd LaunchAgent
- Linux: systemd --user service
- Windows: Task Scheduler

Startup services run `openchamber serve --foreground` so the OS service manager owns process lifetime and restarts. Foreground service updates now defer restarts to the service manager instead of spawning duplicate CLI restarts.

Startup services snapshot useful environment variables by default so provider tokens, PATH, SSH agent settings, and OpenCode configuration survive login/reboot starts. The snapshot avoids shell/session-only state, uses systemd-compatible env quoting on Linux, and avoids unused env artifacts on macOS.

Also adds localized docs for startup services and environment variables.
This commit is contained in:
Bohdan Triapitsyn
2026-05-26 01:36:11 +03:00
committed by GitHub
parent e97bf0d9dc
commit 2014303bc0
30 changed files with 1854 additions and 30 deletions
@@ -1,7 +1,6 @@
export const registerOpenChamberRoutes = (app, dependencies) => {
const {
fs,
os,
path,
process,
server,
@@ -104,14 +103,15 @@ export const registerOpenChamberRoutes = (app, dependencies) => {
}
const currentPort = server.address()?.port || 3000;
const tmpDir = os.tmpdir();
const instanceFilePath = path.join(tmpDir, `openchamber-${currentPort}.json`);
const instanceFilePath = path.join(openchamberDataDir, 'run', `openchamber-${currentPort}.json`);
let storedOptions = { port: currentPort, daemon: true };
try {
const content = await fs.promises.readFile(instanceFilePath, 'utf8');
storedOptions = JSON.parse(content);
} catch {
}
const launchMode = storedOptions.launchMode === 'foreground' ? 'foreground' : 'daemon';
const isForegroundService = launchMode === 'foreground';
const isWindows = process.platform === 'win32';
const quotePosix = (value) => `'${String(value).replace(/'/g, "'\\''")}'`;
@@ -152,7 +152,7 @@ export const registerOpenChamberRoutes = (app, dependencies) => {
restartCmdFallback += ` --ui-password '${escapedPw}'`;
}
}
const restartCmd = `(${restartCmdPrimary}) || (${restartCmdFallback})`;
const restartCmd = isForegroundService ? '' : `(${restartCmdPrimary}) || (${restartCmdFallback})`;
const updateLogPath = path.join(openchamberDataDir, 'update-install.log');
const logPreamble = [
'',
@@ -165,8 +165,9 @@ export const registerOpenChamberRoutes = (app, dependencies) => {
`packagePath=${pmDetails.packagePath || 'unknown'}`,
`globalNodeModulesRoot=${pmDetails.globalNodeModulesRoot || 'unknown'}`,
`mode=${isContainer ? 'container' : 'restart'}`,
`launchMode=${launchMode}`,
`updateCommand=${updateCmd}`,
`restartCommand=${restartCmd}`,
`restartCommand=${restartCmd || 'service-manager'}`,
`logPath=${updateLogPath}`,
].join('\n');
@@ -176,6 +177,7 @@ export const registerOpenChamberRoutes = (app, dependencies) => {
version: updateInfo.version,
packageManager: pm,
autoRestart: true,
restartManager: isForegroundService ? 'service' : 'cli',
});
setTimeout(() => {
@@ -192,7 +194,7 @@ export const registerOpenChamberRoutes = (app, dependencies) => {
${updateCmd}
if %ERRORLEVEL% EQU 0 (
echo Update successful, restarting OpenChamber...
${restartCmd}
${restartCmd || 'echo Service manager will restart OpenChamber.'}
) else (
echo Update failed
exit /b 1
@@ -204,7 +206,7 @@ export const registerOpenChamberRoutes = (app, dependencies) => {
${updateCmd}
if [ $? -eq 0 ]; then
echo "Update successful, restarting OpenChamber..."
${restartCmd}
${restartCmd || 'echo "Service manager will restart OpenChamber."'}
else
echo "Update failed"
exit 1