diff --git a/packages/electron/README.md b/packages/electron/README.md index c2930bc2..a4db3672 100644 --- a/packages/electron/README.md +++ b/packages/electron/README.md @@ -113,7 +113,7 @@ Use an explicit override when testing a different OpenCode CLI build or when a u |----------|-----| | `OPENCHAMBER_ELECTRON_DEV=1` | Marks the runtime as desktop development mode | | `OPENCHAMBER_ELECTRON_USE_BUNDLED_UI=1` | Uses staged web assets instead of the HMR dev server | -| `OPENCHAMBER_SKIP_LOCAL_SERVER=1` | Skips the in-process local OpenChamber server and uses the configured default remote instance; packaged/bundled UI remains available for connection recovery | +| `OPENCHAMBER_SKIP_LOCAL_SERVER=1` | Skips the in-process local OpenChamber server and uses the configured default remote instance; Desktop imports this from the user's login-shell environment, and packaged/bundled UI remains available for connection recovery | | `OPENCHAMBER_HMR_UI_PORT` | Preferred Vite UI port for desktop dev, default `5173` | | `OPENCHAMBER_HMR_API_PORT` | Preferred API port for desktop dev, default `3901` | | `OPENCHAMBER_RUNTIME=desktop` | Set by Electron before starting the web server | diff --git a/packages/electron/main.mjs b/packages/electron/main.mjs index fcddf8d2..8deec16a 100644 --- a/packages/electron/main.mjs +++ b/packages/electron/main.mjs @@ -183,8 +183,6 @@ const DISCORD_INVITE_URL = 'https://discord.gg/ZYRSdnwwKA'; const INSTALLED_APPS_CACHE_TTL_SECS = 60 * 60 * 24; const INSTALLED_APPS_CACHE_FILE = 'discovered-apps.json'; const OPENCODE_SHUTDOWN_GRACE_MS = 100; -const SKIP_LOCAL_SERVER = process.env.OPENCHAMBER_SKIP_LOCAL_SERVER === '1'; - const { autoUpdater } = updaterPkg; const state = { @@ -1325,6 +1323,11 @@ const inheritUserShellEnv = () => { } }; +const shouldSkipLocalServer = () => { + inheritUserShellEnv(); + return process.env.OPENCHAMBER_SKIP_LOCAL_SERVER === '1'; +}; + const spawnLocalServer = async () => { inheritUserShellEnv(); @@ -2769,7 +2772,8 @@ const resolveInitialUrl = async () => { const hmrUiPort = process.env.OPENCHAMBER_HMR_UI_PORT || '5173'; const hmrApiUrl = `http://127.0.0.1:${hmrApiPort}`; const hmrUiUrl = `http://127.0.0.1:${hmrUiPort}`; - const localUrl = SKIP_LOCAL_SERVER + const skipLocalServer = shouldSkipLocalServer(); + const localUrl = skipLocalServer ? null : isDev && await waitForHealth(hmrApiUrl, 5_000, 100) ? hmrApiUrl @@ -4925,7 +4929,7 @@ app.whenReady().then(async () => { state.requestHeaders = sanitizeRuntimeRequestHeaders(requestHeaders || {}); // Serverless background startup re-probes the remote when a window is // eventually opened instead of trusting reachability from login time. - state.startupResolved = !SKIP_LOCAL_SERVER; + state.startupResolved = !shouldSkipLocalServer(); state.initScript = buildInitScript(localOrigin, state.bootOutcome, apiBaseUrl, clientToken, state.requestHeaders); log.info('[electron] started in background without window'); return;