/** * Electron main process. The GUI arrives in M5; for now the app runs its services in the background. * The data folder comes from JARVIS_DATA_DIR until the setup wizard picks one (M5). */ import { join } from "node:path"; import { app } from "electron"; import { errorLog } from "./core/log.js"; import { startServices, type Services } from "./services.js"; const dataDir = process.env.JARVIS_DATA_DIR; // Electron's own profile goes inside the data folder too, not into the user's AppData. if (dataDir) app.setPath("userData", join(dataDir, "cache", "electron")); if (!app.requestSingleInstanceLock()) app.quit(); let services: Services | null = null; app.on("window-all-closed", () => { // No windows yet; keep running. }); app.whenReady().then(async () => { if (!dataDir) throw new Error("JARVIS_DATA_DIR is not set"); services = await startServices(dataDir); }).catch((e: Error) => { errorLog(`could not start: ${e.message}`); app.exit(1); }); let quitting = false; app.on("before-quit", (event) => { if (quitting || !services) return; event.preventDefault(); quitting = true; void services.stop().finally(() => app.quit()); });