diff --git a/electron/main.js b/electron/main.js index 1d3c231728..021d2be4fc 100644 --- a/electron/main.js +++ b/electron/main.js @@ -64,6 +64,25 @@ let serverPort = 20128; const getServerUrl = () => `http://localhost:${serverPort}`; +function resolveNodeExecutable(env = process.env) { + const candidates = [ + env.OMNIROUTE_NODE_PATH, + "/usr/local/bin/node", + "/opt/homebrew/bin/node", + "/opt/local/bin/node", + ].filter(Boolean); + + for (const candidate of candidates) { + try { + if (fs.existsSync(candidate)) return candidate; + } catch { + /* continue */ + } + } + + return "node"; +} + function resolveDataDir(overridePath, env = process.env) { if (overridePath && overridePath.trim()) return path.resolve(overridePath); @@ -516,11 +535,14 @@ function startNextServer() { } } + const nodeExecutable = resolveNodeExecutable(serverEnv); + console.log("[Electron] Starting Next.js server on port", serverPort); + console.log("[Electron] Using Node executable:", nodeExecutable); sendToRenderer("server-status", { status: "starting", port: serverPort }); // Fix #10: Use pipe instead of inherit for logging & readiness detection - nextServer = spawn("node", [serverScript], { + nextServer = spawn(nodeExecutable, [serverScript], { cwd: NEXT_SERVER_PATH, env: { ...serverEnv, diff --git a/scripts/prepare-electron-standalone.mjs b/scripts/prepare-electron-standalone.mjs index 1d59b68f5f..cc8cef1cb1 100644 --- a/scripts/prepare-electron-standalone.mjs +++ b/scripts/prepare-electron-standalone.mjs @@ -83,6 +83,16 @@ function ensurePackage(pkgPath, sourcePath) { cpSync(sourcePath, pkgPath, { recursive: true, dereference: true }); } +function removeGeneratedElectronArtifacts() { + const generatedDirs = [ + join(ELECTRON_STANDALONE_DIR, "electron", "dist-electron"), + ]; + + for (const dir of generatedDirs) { + rmSync(dir, { recursive: true, force: true }); + } +} + function assertBundleIsPackagable(bundleDir) { const nodeModulesPath = join(bundleDir, "node_modules"); if (!existsSync(nodeModulesPath)) return; @@ -131,6 +141,8 @@ if (existsSync(PUBLIC_SRC)) { cpSync(PUBLIC_SRC, PUBLIC_DEST, { recursive: true, dereference: true }); } +removeGeneratedElectronArtifacts(); + ensurePackage( join(ELECTRON_STANDALONE_DIR, "node_modules", "@swc", "helpers"), join(ROOT, "node_modules", "@swc", "helpers")