Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Desktop: move the launch-failure box into error-pages.mjs so main.mjs stays under its ratchet
milind-soni5bdf70ca6694
diff --git a/electron/error-pages.mjs b/electron/error-pages.mjsindex 5ca3e32ffa..a47de13922 100644--- a/electron/error-pages.mjs+++ b/electron/error-pages.mjs@@ -33,6 +33,16 @@ export function buildErrorPage({ allPortsOccupied, logDir, keepTrying = false },);}+/**+ * The box shown when the packaged server did not start at launch, after the fallback to the default data folder: it+ * started and then stopped answering (`retried`), or it never started. Returns true when the app should quit.+ */+export function showBootFailure(dialog, t, { retried, folder }) {+ if (retried) dialog.showErrorBox(t("native.boot.unhealthy.title"), t("native.boot.unhealthy.body", { folder }));+ else dialog.showErrorBox(t("native.boot.failed.title"), t("native.boot.failed.body", { folder }));+ return !retried;+}+/** The page the live-desktop viewer shows when it cannot open, in `text`'s language. */export function desktopViewerErrorPage(message, retryUrl, text = nativeText.englishText) {return (diff --git a/electron/error-pages.node-test.mjs b/electron/error-pages.node-test.mjsindex c5f3cda63b..eabcb7cde8 100644--- a/electron/error-pages.node-test.mjs+++ b/electron/error-pages.node-test.mjs@@ -3,7 +3,7 @@ import path from "node:path";import test from "node:test";import { pathToFileURL } from "node:url";-import { buildErrorPage } from "./error-pages.mjs";+import { buildErrorPage, showBootFailure } from "./error-pages.mjs";import nativeText from "./native-text.cjs";const page = (url) => decodeURIComponent(url.slice("data:text/html;charset=utf-8,".length));@@ -36,3 +36,17 @@ test("on an always-on home the page says, in one more line, that it keeps tryingconst text = nativeText.createNativeText({ saved: "pt-br" });assert.ok(page(buildErrorPage({ allPortsOccupied: false, logDir, keepTrying: true }, text)).includes("continua tentando iniciar o servidor a cada 5 minutos"));});++test("the launch failure box: a server that stopped answering keeps the app open, one that never started quits it", () => {+ const shown = [];+ const dialog = { showErrorBox: (title, body) => shown.push([title, body]) };+ const t = nativeText.englishText.t;+ assert.equal(showBootFailure(dialog, t, { retried: true, folder: "/data" }), false);+ assert.equal(showBootFailure(dialog, t, { retried: false, folder: "/data" }), true);+ assert.deepEqual(shown, [+ [t("native.boot.unhealthy.title"), t("native.boot.unhealthy.body", { folder: "/data" })],+ [t("native.boot.failed.title"), t("native.boot.failed.body", { folder: "/data" })],+ ]);+ assert.notEqual(shown[0][0], shown[1][0]);+ assert.ok(shown[1][1].includes("/data"));+});diff --git a/electron/main.mjs b/electron/main.mjsindex 4f2470f572..17472a8196 100644--- a/electron/main.mjs+++ b/electron/main.mjs@@ -5,7 +5,7 @@ import fs from "node:fs";import os from "node:os";import path from "node:path";import { fileURLToPath } from "node:url";-import { buildErrorPage, desktopViewerErrorPage } from "./error-pages.mjs";+import { buildErrorPage, desktopViewerErrorPage, showBootFailure } from "./error-pages.mjs";import { startCua, stopCua, registerCuaIpc, requestComputerUse, setCuaStateListener, grantLocalComputer } from "./cua.mjs";import { createAndroidDeviceController } from "./android-device.mjs";import { finishSpeech, speechBusy, startSpeech, stopSpeech } from "./speech.mjs";@@ -2982,19 +2982,7 @@ app.whenReady().then(async () => {app.quit();return;}- const retried = await startServerPackaged();- if (retried) {- dialog.showErrorBox(- nativeT("native.boot.unhealthy.title"),- nativeT("native.boot.unhealthy.body", { folder: bootDataDir }),- );- } else {- dialog.showErrorBox(- nativeT("native.boot.failed.title"),- nativeT("native.boot.failed.body", { folder: bootDataDir }),- );- app.quit();- }+ if (showBootFailure(dialog, nativeT, { retried: await startServerPackaged(), folder: bootDataDir })) app.quit();}if (!serverReady && !desktopShutdownStarted) serverSupervisor.startLater(startServerPackaged); // an always-on home keeps trying}