Skip to content

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

Keep the Cloud name chosen at setup when the Admin lists it under its own name

AdityaUmalea77b9a647c97
diff --git a/electron/cloud-buy.d.mts b/electron/cloud-buy.d.mts
index 8e3d580268..faecdbbdd1 100644
--- a/electron/cloud-buy.d.mts
+++ b/electron/cloud-buy.d.mts
@@ -6,14 +6,16 @@ export declare const CLOUD_COLOR_HEX: Readonly<Record<CloudColor, string>>;
export declare function cleanCloudName(value: unknown): string | null;
export declare function cleanCloudColor(value: unknown): CloudColor | null;
export declare function colorDotIcons<T extends { addRepresentation(options: { scaleFactor: number; dataURL: string }): void; isEmpty(): boolean }>(nativeImage: { createEmpty(): T }): (color: unknown) => T | null;
-export interface CloudLookRecord { accountId: string; name: string; color: CloudColor }
+export interface CloudLookRecord { accountId: string; name: string; color: CloudColor; listed?: string | null }
export declare function lookFile(file: () => string, fs: { readFileSync(path: string, encoding: "utf8"): string; writeFileSync(path: string, data: string, options: { mode: number }): void }): { read(): CloudLookRecord | null; write(value: CloudLookRecord): void };
export declare function createCloudLook(options: {
store: { read(): CloudLookRecord | null; write(value: CloudLookRecord): void };
accountId(): string | null;
homeEntry(): { origin: string; name: string; color?: string } | null;
saveEntry(origin: string, look: { name: string; color: CloudColor }): void;
-}): { pending(): { name: string; color: CloudColor } | null; current(): { name: string; color: CloudColor }; save(name: string, color: string): { name: string; color: CloudColor } };
+ /** The name the Admin lists My Cloud under now, null while it lists none. */
+ listedName?(): string | null;
+}): { pending(): { name: string; color: CloudColor } | null; current(): { name: string; color: CloudColor }; save(name: string, color: string): { name: string; color: CloudColor }; homeName(listed: string): string };
export declare function createCloudReadyNotice(options: {
Notification: { isSupported(): boolean; new (options: { title: string; body: string }): { on(event: "click", listener: () => void): void; show(): void } };
focused(): boolean; sheetOpen(): boolean; name(): string; open(): void;
diff --git a/electron/cloud-buy.mjs b/electron/cloud-buy.mjs
index 1edab5c05e..8c4e3acec7 100644
--- a/electron/cloud-buy.mjs
+++ b/electron/cloud-buy.mjs
@@ -25,7 +25,10 @@ export const cleanCloudColor = value => (CLOUD_COLORS.includes(value) ? value :
/** The native switcher's dot for a saved colour (14 pt, sharp at 2x), drawn once per colour; null where it cannot be drawn. */
export const colorDotIcons = nativeImage => dotIcons(nativeImage, CLOUD_COLOR_HEX);
-/** The name and colour chosen while the Cloud is set up, kept for its account until the Cloud is listed (userData). */
+const listedOf = saved => (saved.listed === null || typeof saved.listed === "string" ? { listed: saved.listed } : {});
+
+/** The name and colour chosen while the Cloud is set up, kept for its account (userData), with the name the Admin
+ * listed it under then (`listed`, null while it listed none). */
export function lookFile(file, fs) {
let cached;
return {
@@ -34,7 +37,7 @@ export function lookFile(file, fs) {
try {
const saved = JSON.parse(fs.readFileSync(file(), "utf8"));
cached = typeof saved?.accountId === "string" && cleanCloudName(saved.name) && cleanCloudColor(saved.color)
- ? { accountId: saved.accountId, name: cleanCloudName(saved.name), color: saved.color } : null;
+ ? { accountId: saved.accountId, name: cleanCloudName(saved.name), color: saved.color, ...listedOf(saved) } : null;
} catch { cached = null; }
return cached;
},
@@ -46,7 +49,7 @@ export function lookFile(file, fs) {
}
/** One answer to "what is this Cloud called, in which colour": its Servers entry once listed, else what was chosen, else My Cloud. */
-export function createCloudLook({ store, accountId, homeEntry, saveEntry }) {
+export function createCloudLook({ store, accountId, homeEntry, saveEntry, listedName = () => null }) {
const chosen = () => { const saved = store.read(); return saved && saved.accountId === accountId() ? { name: saved.name, color: saved.color } : null; };
const current = () => {
const entry = homeEntry();
@@ -61,11 +64,22 @@ export function createCloudLook({ store, accountId, homeEntry, saveEntry }) {
const look = { name: cleanCloudName(name), color: cleanCloudColor(color) };
if (!look.name || !look.color) throw new Error(`Choose a name of up to ${CLOUD_NAME_MAX} characters and one of the colours.`);
const id = accountId();
- if (id) store.write({ accountId: id, ...look });
+ if (id) store.write({ accountId: id, ...look, listed: listedName() ?? null });
const entry = homeEntry();
if (entry) saveEntry(entry.origin, look);
return current();
},
+ /** The name My Cloud's entry carries while the Admin lists it as `listed`: the one chosen here, until the Admin's
+ * name differs from the one it had when it was chosen (renamed there), which from then on is the one answer. */
+ homeName(listed) {
+ const saved = store.read();
+ if (!saved || saved.accountId !== accountId() || !("listed" in saved)) return listed;
+ if (saved.listed === listed) return saved.name;
+ if (saved.listed === null) { store.write({ ...saved, listed }); return saved.name; }
+ const { listed: _before, ...chosen } = saved;
+ store.write({ ...chosen, name: cleanCloudName(listed) ?? saved.name });
+ return listed;
+ },
};
}
diff --git a/electron/cloud-buy.node-test.mjs b/electron/cloud-buy.node-test.mjs
index b16056a86e..b93709233e 100644
--- a/electron/cloud-buy.node-test.mjs
+++ b/electron/cloud-buy.node-test.mjs
@@ -66,7 +66,7 @@ test("the name and colour chosen while setting up are kept for that account unti
const look = createCloudLook({ store: lookFile(() => "/user/cloud-home-look.json", fs), accountId: () => account, homeEntry: () => entry, saveEntry: (at, value) => saved.push([at, value]) });
assert.deepEqual(look.current(), { name: "My Cloud", color: "blue" }); assert.equal(look.pending(), null);
assert.deepEqual(look.save(" Studio ", "teal"), { name: "Studio", color: "teal" });
- assert.deepEqual(JSON.parse(files.get("/user/cloud-home-look.json")), { accountId: "acct-1", name: "Studio", color: "teal" });
+ assert.deepEqual(JSON.parse(files.get("/user/cloud-home-look.json")), { accountId: "acct-1", name: "Studio", color: "teal", listed: null });
assert.deepEqual(look.pending(), { name: "Studio", color: "teal" });
for (const [name, color] of [["", "teal"], ["x".repeat(29), "teal"], ["Studio", "#00ff00"]]) assert.throws(() => look.save(name, color), /up to 28 characters/);
const again = createCloudLook({ store: lookFile(() => "/user/cloud-home-look.json", fs), accountId: () => account, homeEntry: () => entry, saveEntry: () => {} });
diff --git a/electron/home-places.mjs b/electron/home-places.mjs
index 98716f60a3..907f4cb151 100644
--- a/electron/home-places.mjs
+++ b/electron/home-places.mjs
@@ -9,10 +9,10 @@ import { homeLook, listedColors, ownCloudPlaces } from "./cloud-list.mjs";
/** My Cloud's saved place under the name the Admin lists it by now, so a rename there (Settings → Name and colour) reaches
* the switcher and the top bar too, not only at setup (cloud-home.mjs withCloudHome). Only the entry that is home. */
-function withHomeName(state, session) {
+function withHomeName(state, session, homeName) {
const look = homeLook(session), origin = environments.normalizeOrigin(session?.machine?.origin);
if (!look || !origin || !state.environments.some((entry) => entry.home === true && entry.origin === origin)) return state;
- return environments.withEnvironmentLook(state, origin, { name: look.name });
+ return environments.withEnvironmentLook(state, origin, { name: homeName(look.name) });
}
const idOf = (value) => (typeof value === "string" && value ? value : null);
@@ -33,7 +33,7 @@ const KINDS = Object.freeze(["team", "cloud", "profile", "server"]);
* places and their file; `homeOrigin()`: My Cloud's verified origin, the place the window falls back to. `synced(state)`: each sign-in state as it
* comes, after the places follow it (a team the person just joined opens from there: team-join-main.mjs).
*/
-export function createHomePlaces({ store, environments: read, persist, makeId, homeOrigin, synced = () => {}, log = () => {} }) {
+export function createHomePlaces({ store, environments: read, persist, makeId, homeOrigin, homeName = (name) => name, synced = () => {}, log = () => {} }) {
let cached = null;
const pending = [];
/** One kind of place at most: the first of KINDS the record names. */
@@ -100,7 +100,7 @@ export function createHomePlaces({ store, environments: read, persist, makeId, h
const clouds = Array.isArray(state.clouds) ? ownCloudPlaces(state.clouds) : null;
const owned = environments.reconcileOwnClouds(withTeams, clouds, makeId, homeOrigin());
const coloured = clouds ? environments.withListedColors(owned, listedColors(state.clouds), homeOrigin()) : owned;
- const next = withHomeName(coloured, state);
+ const next = withHomeName(coloured, state, homeName);
if (next !== read()) persist(next);
for (const name of left) places.left(name);
if (current().team && !teams.some((team) => team?.id === current().team)) places.remember(null);
diff --git a/electron/home-places.node-test.mjs b/electron/home-places.node-test.mjs
index 4865938194..347517c3a6 100644
--- a/electron/home-places.node-test.mjs
+++ b/electron/home-places.node-test.mjs
@@ -1,6 +1,7 @@
import assert from "node:assert/strict";
import test from "node:test";
+import { createCloudLook } from "./cloud-buy.mjs";
import { parseCloudList } from "./cloud-list.mjs";
import environments from "./environments.cjs";
import { createHomePlaces } from "./home-places.mjs";
@@ -10,11 +11,12 @@ const acme = { id: "team-acme", name: "Acme", role: "admin", machine: { status:
const beta = { id: "team-beta", name: "Beta", role: "member", machine: { status: "ready", origin: OTHER } };
const connected = (teams) => ({ status: "connected", account: { id: "acct-1" }, teams });
-function world({ saved = null, state = { environments: [{ id: "c", kind: "remote", name: "My Cloud", origin: HOME, home: true }], activeId: "c" } } = {}) {
+function world({ saved = null, state = { environments: [{ id: "c", kind: "remote", name: "My Cloud", origin: HOME, home: true }], activeId: "c" }, homeName } = {}) {
const w = { saved, state, persisted: [], ids: 0, log: [] };
w.places = createHomePlaces({
store: { read: () => { if (w.saved === null) throw new Error("ENOENT"); return w.saved; }, write: (value) => { if (w.failWrite) throw new Error("disk full"); w.saved = value; } },
environments: () => w.state, persist: (next) => { w.persisted.push(next); w.state = next; }, makeId: () => `id-${++w.ids}`, homeOrigin: () => HOME, log: (line) => w.log.push(line),
+ ...(homeName ? { homeName } : {}),
});
return w;
}
@@ -115,3 +117,27 @@ test("a listed name never renames a place that isn't home at the machine's addre
w.places.sync(withHome("Freedom Fox"));
assert.equal(w.state.environments[0].name, "Saved by hand");
});
+
+test("the name chosen while setting up My Cloud stays when the Admin lists it under its own name, until it is renamed there", () => {
+ let listed = null, record = null;
+ const look = createCloudLook({ store: { read: () => record, write: (value) => { record = value; } }, accountId: () => "acct-1", homeEntry: () => null, saveEntry: () => {}, listedName: () => listed });
+ look.save("Juniper Cloud", "teal");
+ const w = world({ state: { environments: [{ id: "c", kind: "remote", name: "Juniper Cloud", origin: HOME, home: true }], activeId: "c" }, homeName: (name) => look.homeName(name) });
+ w.places.sync(withHome("My Cloud"));
+ assert.equal(w.state.environments[0].name, "Juniper Cloud", "the Admin's first name is not a rename");
+ w.places.sync(withHome("My Cloud"));
+ assert.equal(w.state.environments[0].name, "Juniper Cloud");
+ w.places.sync(withHome("Freedom Fox"));
+ assert.equal(w.state.environments[0].name, "Freedom Fox", "renamed in the Admin: its name wins");
+ w.places.sync(withHome("Freedom Fox"));
+ assert.equal(w.state.environments[0].name, "Freedom Fox");
+ w.places.sync(withHome("A name longer than twenty-eight letters"));
+ w.places.sync(withHome("A name longer than twenty-eight letters"));
+ assert.equal(w.state.environments[0].name, "A name longer than twenty-eight letters", "renamed there again: still the Admin's name");
+ listed = "Studio"; look.save("Juniper Cloud", "teal");
+ w.places.sync(withHome("Studio"));
+ assert.equal(w.state.environments[0].name, "Juniper Cloud", "chosen while the Admin listed it: that name is the one to compare");
+ record = { accountId: "acct-1", name: "Old choice", color: "teal" };
+ w.places.sync(withHome("Lab"));
+ assert.equal(w.state.environments[0].name, "Lab", "a choice saved before the Admin name was kept: the Admin's name, as before");
+});
diff --git a/electron/main.mjs b/electron/main.mjs
index cf9dc9c154..ca7e44f66a 100644
--- a/electron/main.mjs
+++ b/electron/main.mjs
@@ -2574,13 +2574,13 @@ const savedWorkspace = id => {
};
// The buying sheet (cloud-buy.mjs): its channels, and the Cloud's name and colour (Servers entry once listed).
const cloudLook = createCloudLook({ store: lookFile(() => path.join(app.getPath("userData"), cloudTarget(process.env).look), fs), accountId: () => cloudAccount?.state().account?.id ?? null,
- homeEntry: cloudHomeEntry, saveEntry: (origin, look) => persistEnvironments(withEnvironmentLook(environmentsState, origin, look)) });
+ homeEntry: cloudHomeEntry, saveEntry: (origin, look) => persistEnvironments(withEnvironmentLook(environmentsState, origin, look)), listedName: () => homeLook(cloudAccount?.state())?.name ?? null });
const cloudBuy = installCloudBuy({ ipcMain, guard: localWorkspaceOnly, client: ensureCloudAccount, offersReady: cloudOffersReady, clipboard, look: cloudLook });
const localServerRequest = (route, init = {}) => (serverProc && serverReady ? fetch(`http://127.0.0.1:${SERVER_PORT}${route}`, { ...init, redirect: "error", credentials: "omit", headers: { ...init.headers, [DESKTOP_MUTATION_HEADER]: desktopMutationToken } }) : Promise.reject(new Error("not running"))); launchRecord.deliverWith((part) => localServerRequest("/api/diagnostics/launch", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(part), signal: AbortSignal.timeout(5_000) }).then((res) => res.json()));
const teamProfileSeeds = createTeamProfileSeeds({ teamFetch: (...args) => session.defaultSession.fetch(...args), localRequest: localServerRequest, log: slog });
const oneHome = installOneHome({ ipcMain, clean: cleanWorkspace, cloudPage: cloudPageAsking, pageOrigin: activePageOrigin, confirmMove: confirmTeamMove, server: () => serverProc, cookieFetch: (...args) => session.defaultSession.fetch(...args), home: () => (myCloud() && cloudAccount ? { origin: myCloud(), grant: () => cloudAccount.pairHome() } : null), power: cloudPower, file: () => path.join(app.getPath("userData"), "cloud-send.json"), localRequest: localServerRequest, space: { disk: () => cloudPlanDisk(ensureCloudAccount().state()), grow: sizeGb => ensureCloudAccount().growDisk(sizeGb) }, reconnect: origin => signInCloudSession({ origin, mine: myCloud(), pair: () => ensureCloudAccount().pairHome(), fetch: (...args) => session.defaultSession.fetch(...args) }), window: () => (desktopRemoteAccess ? null : mainWindow), localOrigin: rendererOrigin, account: () => cloudAccount, journalFile: () => path.join(app.getPath("userData"), "one-home.json"), tempRoot: () => path.join(app.getPath("temp"), "openmaus-one-home"), lend: projects => sharingController().lendProjects(projects), phone: { paired: () => companionStartsAtLaunch({ remoteClient: Boolean(desktopRemoteAccess), serverReady }), start: () => startDesktopCompanion({ waitForHosted: false, remember: false }).then(() => {}) }, openHome: () => void showHome({ place: "cloud" }), openTeam: team => void showHome({ place: { team: team.id, name: team.name } }), openLocal: () => void showHome(), restart: () => relaunchAfterDesktopRemoteChange(), version: app.getVersion(), log: slog, other: () => ownHome, accountsHere: () => accountRing()?.count() ?? 1, chooses: true, t: nativeT }); ownHome = installOwnHome({ t: nativeT, localRequest: localServerRequest, fetch: (...args) => session.defaultSession.fetch(...args), environments: () => environmentsState.environments, handoff: what => oneHome.handoff(what), cloudJournal: () => oneHome.journal(), journal: jsonFile(path.join(app.getPath("userData"), "own-home.json")), choice: jsonFile(path.join(app.getPath("userData"), "own-home-choice.json")), sendState: jsonFile(path.join(app.getPath("userData"), "own-home-send.json")), lend: (projects, place) => sharingController().lendProjects(projects, place), phone: { paired: () => companionStartsAtLaunch({ remoteClient: Boolean(desktopRemoteAccess), serverReady }), start: () => startDesktopCompanion({ waitForHosted: false, remember: false }).then(() => {}) }, openHome: place => void workspaceMenuAction(() => switchEnvironment(place.id)), lastInput: oneHome.lastInput, version: app.getVersion(), log: slog, onChange: () => { oneHome.publish(); computerSharing?.cloudChanged(); railChanged(); } }); botLink = createBotLinkMain({ wanted: () => placesTogether.on(), pref: jsonFile(path.join(app.getPath("userData"), PLACES_TOGETHER_FILE)), localRequest: localServerRequest, fetch: (...args) => session.defaultSession.fetch(...args), cloud: () => ({ origin: myCloud(), account: cloudAccount?.state().account?.id ?? null, asleep: cloudPower.asleep(), signedOut: cloudAccount?.state().status === "signed-out" }), cloudName: () => nativeT("cloudSetup.myCloud"), changed: () => placesTogether.linkChanged(), log: slog }); twoPlaces = installTwoPlacesMain({ t: nativeT, ipcMain, guard: localWorkspaceOnly, localRequest: localServerRequest, fetch: (...args) => session.defaultSession.fetch(...args), environments: () => environmentsState.environments, cloud: () => ({ origin: myCloud(), asleep: cloudPower.asleep() }), oneHome, ownHome, dismissed: jsonFile(path.join(app.getPath("userData"), "two-places.json")), account: () => cloudAccount, teamsRemembered: jsonFile(path.join(app.getPath("userData"), "team-places.json")), log: slog, tell: () => { if (mainWindow && !mainWindow.isDestroyed() && senderIsLocal({ sender: mainWindow.webContents })) mainWindow.webContents.send("two-places:changed"); } });
// Teams from the verified session as places this window shows (home-places.mjs): the one to open next time, and its lines.
-const homePlaces = createHomePlaces({ store: jsonFile(path.join(app.getPath("userData"), "home-place.json")), environments: () => environmentsState, persist: persistEnvironments, makeId: randomUUID, homeOrigin: myCloud, synced: state => teamLinks.changed(state), log: slog });
+const homePlaces = createHomePlaces({ store: jsonFile(path.join(app.getPath("userData"), "home-place.json")), environments: () => environmentsState, persist: persistEnvironments, makeId: randomUUID, homeOrigin: myCloud, homeName: name => cloudLook.homeName(name), synced: state => teamLinks.changed(state), log: slog });
const homeWindow = createHomeWindow({ clean: cleanWorkspace, journal: oneHome.journal, frozen: oneHome.marker, account: () => (app.isPackaged && !desktopRemoteAccess ? cloudAccount : null), restored: cloudAccountRestored,
window: () => (mainWindow && !mainWindow.isDestroyed() ? mainWindow : null), ensureWindow: () => { if (!mainWindow || mainWindow.isDestroyed()) createWindow({ deferNavigation: true }); },
localOrigin: rendererOrigin, cookieFetch: (...args) => session.defaultSession.fetch(...args), power: cloudPower, splash: () => startupScreen, lastInput: oneHome.lastInput, rehomed: () => talk.homeChanged(), log: slog, t: nativeT,
diff --git a/src/components/DesktopWorkspaceSwitcher.home.test.ts b/src/components/DesktopWorkspaceSwitcher.home.test.ts
index 6103916377..a42da8691b 100644
--- a/src/components/DesktopWorkspaceSwitcher.home.test.ts
+++ b/src/components/DesktopWorkspaceSwitcher.home.test.ts
@@ -30,6 +30,19 @@ it("in a window whose home is My Cloud, names My Cloud with nothing to open: no
expect(menu).not.toHaveBeenCalled();
});
+it("in a window whose home is My Cloud, names it as the top bar does: its own name, else the team's, else My Cloud", async () => {
+ const home = { local: false, origin: "https://omb-u-1a2b3c4d5e6f.fly.dev", home: true };
+ const label = () => host.querySelector("[data-cloud-home-indicator]")?.textContent ?? "";
+ for (const props of [{ cloudHome: true }, { cloudHome: true, inline: true, pill: true }]) {
+ await show({ ...home, name: "Juniper Cloud" }, props);
+ expect(label(), JSON.stringify(props)).toBe("Juniper Cloud");
+ await show({ ...home, name: "Juniper Cloud" }, { ...props, place: "Acme Labs" });
+ expect(label(), JSON.stringify(props)).toBe("Acme Labs");
+ await show({ ...home, name: "My Cloud" }, props);
+ expect(label(), JSON.stringify(props)).toBe("My Cloud");
+ }
+});
+
it("anywhere else keeps the switcher as it was", async () => {
await show({ local: false, name: "My Cloud", origin: "https://omb-u-1a2b3c4d5e6f.fly.dev" }, { cloudHome: true });
expect(host.querySelector("button")?.getAttribute("aria-haspopup")).toBe("menu");
diff --git a/src/components/DesktopWorkspaceSwitcher.tsx b/src/components/DesktopWorkspaceSwitcher.tsx
index 49cb1ba86f..ec4e2d76d0 100644
--- a/src/components/DesktopWorkspaceSwitcher.tsx
+++ b/src/components/DesktopWorkspaceSwitcher.tsx
@@ -9,6 +9,7 @@ import { t } from "@/lib/i18n";
import { railShown, usePlaces } from "@/lib/places";
import { CloudTile } from "./cloud-buy/parts";
import { SIMPLE_RAIL_BUTTON } from "./SidebarSimpleTop";
+import { windowPlaceName } from "./WindowPlaceTitle";
export function openServerMenu(bridge: { menu: (options?: { from?: "howto" }) => Promise<void> }, { howTo = false, onClosed }: { howTo?: boolean; onClosed?: () => void } = {}): Promise<void> {
return bridge.menu(howTo ? { from: "howto" } : undefined).finally(() => { if (howTo) onClosed?.(); });
@@ -92,8 +93,8 @@ export function DesktopWorkspaceSwitcher(props: SwitcherProps) {
}
function Switcher({ compact = false, inline = false, pill = false, rail = false, cloudHome = false, owner = null, howTo = false, place, onMenuClosed }: SwitcherProps) {
- const cloudName = place || t("cloudSetup.myCloud");
const { bridge, current, open, error, onLine, waking, openMenu } = useWorkspacePlace({ cloudHome, howTo, onMenuClosed });
+ const cloudName = current?.home ? windowPlaceName(current, place) : place || t("cloudSetup.myCloud");
const withPower = (name: string) => (onLine ? `${name} · ${onLine}` : name);
// This window's home is My Cloud: it opens nothing else, so there is nothing to switch.
if (!bridge || current?.home === true) {