Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Switch to This computer from a Cloud's settings takes the rail's own switch

aivsomkarbf4c721d846a
diff --git a/electron/main.mjs b/electron/main.mjs
index 8adb001159..f1d2780b15 100644
--- a/electron/main.mjs
+++ b/electron/main.mjs
@@ -2625,7 +2625,7 @@ const showStartPlace = () => openStartPlace({ home: homeWindow, places: homePlac
const placeInbox = createPlaceInboxWatch({ places: () => [{ id: LOCAL_ID, local: true }, ...environmentsState.environments.filter(entry => entry.kind !== "local" && entry.origin)], activeId: () => environmentsState.activeId, local: localServerRequest, cloudFetch: (...args) => session.defaultSession.fetch(...args), asleep: origin => homeWindow.asleepAt(origin), shown: () => !desktopRemoteAccess && serverReady && Boolean(mainWindow && !mainWindow.isDestroyed() && mainWindow.isVisible()), changed: () => railChanged() });
const localProfiles = createLocalProfiles({ registry: createProfileRegistry({ dataDir: desktopDataDir }), clean: cleanWorkspace, dataDir: desktopDataDir, allowed: () => app.isPackaged && !desktopRemoteAccess, home: () => (homeWindow.cloudOrigin() ? "cloud" : ownHome?.origin() || cleanWorkspace.marker().frozen ? null : "local"), window: { openProfile: id => homeWindow.openProfile(id), profile: () => homeWindow.profile(), showCloud: () => showHome({ place: "cloud" }) }, showLocal: () => { homeWindow.cancel(); persistEnvironments(withActive(environmentsState, LOCAL_ID)); return navigateMainWindow(rendererOrigin()); }, onLocal: () => Boolean(mainWindow && !mainWindow.isDestroyed() && senderIsLocal({ sender: mainWindow.webContents })), busy: async () => { const said = await (await localServerRequest("/api/move/freeze", { signal: AbortSignal.timeout(5_000) })).json(); return typeof said?.busy === "string" ? { name: said.busy, what: said.what } : null; }, trash: dir => shell.trashItem(dir), reserved: () => nativeT(process.platform === "darwin" ? "rail.thisMac" : "rail.thisPc"), remember: homePlaces.remember, changed: () => railChanged(), log: slog }); const railList = () => { ownHome?.refresh(); const settling = localProfiles.settling(); return railPlaces({ saved: environmentsState, waiting: placeInbox.waiting, home: homeWindow.cloudOrigin() ?? ownHome?.origin() ?? null, mine: myCloud(), state: desktopRemoteAccess ? null : cloudAccount?.state(), offers: entry => !desktopRemoteAccess && ownHome?.offers(entry) === true, accounts: accountRing.waiting(), profiles: localProfiles.places({ activeLocal: environmentsState.activeId === LOCAL_ID }), computerSettling: settling && settling.id === null ? settling.name : null }); };
// The rail as the window's own chrome (chrome-rail.mjs): this app's page beside every place's page, the one that lists.
-const placeSwitch = createPlaceSwitch({ changed: () => railChanged(), stop: () => homeWindow.stopOpening(), kept: () => homePlaces.remembered(), pageSettled: () => { const page = mainWindow && !mainWindow.isDestroyed() ? mainWindow.webContents : null; if (page?.isLoadingMainFrame()) return new Promise(done => { page.once("did-stop-loading", done); page.once("destroyed", done); }); } }); const chromeRail = createChromeRail({ createView: options => new WebContentsView(options), preload: path.join(__dirname, "preload.cjs"), log: slog, prefs: () => desktopPrefs, changed: () => rail.changed(), openComputer: (page) => openComputerSettings({ window: () => mainWindow, onLocal: (win) => senderIsLocal({ sender: win.webContents }), showLocal: () => persistEnvironments(withActive(environmentsState, LOCAL_ID)), navigate: navigateMainWindow, origin: rendererOrigin }, page),
+const placeSwitch = createPlaceSwitch({ changed: () => railChanged(), stop: () => homeWindow.stopOpening(), kept: () => homePlaces.remembered(), pageSettled: () => { const page = mainWindow && !mainWindow.isDestroyed() ? mainWindow.webContents : null; if (page?.isLoadingMainFrame()) return new Promise(done => { page.once("did-stop-loading", done); page.once("destroyed", done); }); } }); const openPlace = (id, stale) => workspaceMenuAction(async () => { if (id === LOCAL_ID) await cleanWorkspace.settled(); if (!stale()) await switchEnvironment(id, stale); }); const chromeRail = createChromeRail({ createView: options => new WebContentsView(options), preload: path.join(__dirname, "preload.cjs"), log: slog, prefs: () => desktopPrefs, changed: () => rail.changed(), openComputer: (page) => openComputerSettings({ window: () => mainWindow, onLocal: (win) => senderIsLocal({ sender: win.webContents }), showLocal: () => placeSwitch.ask(LOCAL_ID, stale => { localProfiles.cancel(); return openPlace(LOCAL_ID, stale); }) }, page),
args: () => [...desktopCompanionRendererArguments(rendererOrigin(), desktopRemoteAccess), ...(app.isPackaged && !desktopRemoteAccess ? ["--omb-company-desktop=1"] : []), `--omb-app-version=${app.getVersion()}`],
url: () => `${rendererOrigin()}${CHROME_RAIL_PATH}`, wanted: () => !desktopRemoteAccess && (serverReady || placeSwitch.target() !== null) && railList().length > 0 });
chromeRail.install(ipcMain);
@@ -2636,7 +2636,7 @@ const rail = installCloudRail({ t: nativeT, ipcMain, clipboard, openCloud: openO
guard: handler => (event, ...args) => (chromeRail.owns(event) ? handler(event, ...args) : workspaceOnly(handler)(event, ...args)),
lists: event => chromeRail.owns(event), trusted: event => chromeRail.owns(event) || senderIsLocal(event), beside: () => chromeRail.shown(),
targets: () => [mainWindow && !mainWindow.isDestroyed() ? mainWindow.webContents : null, { send: channel => chromeRail.send(channel), isDestroyed: () => false }],
- places: railList, ask: placeSwitch.ask, switching: placeSwitch.target, open: (id, stale) => workspaceMenuAction(async () => { if (id === LOCAL_ID) await cleanWorkspace.settled(); if (!stale()) await switchEnvironment(id, stale); }), makeHome: id => ownHome.start(id), forget: id => forgetEnvironment(id, false, true), openProfile: (id, stale = () => false) => workspaceMenuAction(async () => { await cleanWorkspace.settled(); if (stale()) return; const opened = await localProfiles.open(id); railChanged(); if (opened === false) throw new Error(nativeT("native.places.profileFailed")); }), local: localProfiles,
+ places: railList, ask: placeSwitch.ask, switching: placeSwitch.target, open: openPlace, makeHome: id => ownHome.start(id), forget: id => forgetEnvironment(id, false, true), openProfile: (id, stale = () => false) => workspaceMenuAction(async () => { await cleanWorkspace.settled(); if (stale()) return; const opened = await localProfiles.open(id); railChanged(); if (opened === false) throw new Error(nativeT("native.places.profileFailed")); }), local: localProfiles,
add: { choices: () => ({ cloud: cloudOffersAllowed(), link: !desktopRemoteAccess, address: !desktopRemoteAccess && !homeWindow.cloudOrigin(), account: !desktopRemoteAccess && Boolean(accounts.view().active) }),
probe: serverConnect.probe, run: (choice, link, code) => (choice === "link" ? (link ? (code === null ? connectHostedWorkspace(link) : serverConnect.connect(link, code)) : addServerFromClipboard()) : choice === "address" ? openWorkspaceSettings() : homeWindow.cloudOrigin() ? undefined : openCloudAdd("app_menu")) } });
const announceAddedCloud = createAddedCloudNotice({ t: nativeT, Notification, focused: () => Boolean(mainWindow && !mainWindow.isDestroyed() && mainWindow.isFocused()), sheetOpen: rail.sheetOpen,
diff --git a/electron/open-computer-settings.mjs b/electron/open-computer-settings.mjs
index 29f03c1160..f0bf7946e5 100644
--- a/electron/open-computer-settings.mjs
+++ b/electron/open-computer-settings.mjs
@@ -2,16 +2,12 @@
// Kept out of main.mjs, which is at its size limit; main.mjs passes what this needs from its own state.
/**
- * @param {{ window: () => import("electron").BrowserWindow | null, onLocal: (window: import("electron").BrowserWindow) => boolean, showLocal: () => void, navigate: (url: string) => unknown, origin: () => string }} deps
+ * @param {{ window: () => import("electron").BrowserWindow | null, onLocal: (window: import("electron").BrowserWindow) => boolean, showLocal: () => Promise<unknown> }} deps
+ * `showLocal()`: the rail's own click on This computer, settled once its page has loaded or the switch could not happen.
* @param {string | undefined} page the Settings page to open, if any
*/
-export function openComputerSettings(deps, page) {
+export async function openComputerSettings(deps, page) {
+ await deps.showLocal();
const window = deps.window();
- if (!window || window.isDestroyed()) return;
- if (deps.onLocal(window)) {
- if (page) window.webContents.send("app:open-settings", page);
- return;
- }
- deps.showLocal();
- deps.navigate(`${deps.origin()}${page ? `/?desktop-settings=${encodeURIComponent(page)}` : "/"}`);
+ if (page && window && !window.isDestroyed() && deps.onLocal(window)) window.webContents.send("app:open-settings", page);
}
diff --git a/electron/open-computer-settings.node-test.mjs b/electron/open-computer-settings.node-test.mjs
new file mode 100644
index 0000000000..3eae082900
--- /dev/null
+++ b/electron/open-computer-settings.node-test.mjs
@@ -0,0 +1,46 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { openComputerSettings } from "./open-computer-settings.mjs";
+
+const LOCAL = "http://127.0.0.1:8799";
+const CLOUD = "https://home.example";
+
+/** The window and this computer's one server: `runs` is what that server runs (This computer's own copy, or a profile),
+ * `shows` the address on screen. Settings opens on whatever runs once the window shows this computer's page, whether
+ * it is asked by message or by address. `showLocal` is the switch to This computer, which may not land. */
+function world({ runs, shows = CLOUD, lands = true }) {
+ const w = { runs, shows, opened: [] };
+ const window = { isDestroyed: () => false, webContents: { send: (channel, page) => { if (channel === "app:open-settings" && w.shows === LOCAL) w.opened.push([w.runs, page]); } } };
+ w.deps = {
+ window: () => window,
+ onLocal: () => w.shows === LOCAL,
+ showLocal: async () => { await Promise.resolve(); if (lands) { w.runs = "computer"; w.shows = LOCAL; } },
+ origin: () => LOCAL,
+ navigate: (url) => {
+ const to = new URL(url);
+ w.shows = to.origin;
+ if (w.shows === LOCAL && to.searchParams.get("desktop-settings")) w.opened.push([w.runs, to.searchParams.get("desktop-settings")]);
+ },
+ };
+ return w;
+}
+
+test("from a Cloud, with a profile running here, Settings opens on This computer once the switch has brought it back", async () => {
+ const w = world({ runs: "profile" });
+ await openComputerSettings(w.deps, "app");
+ assert.deepEqual(w.opened, [["computer", "app"]]);
+});
+
+test("a switch that does not land opens no Settings, and the Cloud stays on screen", async () => {
+ const w = world({ runs: "profile", lands: false });
+ await openComputerSettings(w.deps, "account");
+ assert.deepEqual(w.opened, []);
+ assert.equal(w.shows, CLOUD);
+});
+
+test("already on This computer, Settings opens there on the page asked for", async () => {
+ const w = world({ runs: "computer", shows: LOCAL });
+ await openComputerSettings(w.deps, "phone");
+ assert.deepEqual(w.opened, [["computer", "phone"]]);
+});