Skip to content

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

wip: the You menu's Sign in row

milind-soniec4952f2077d
diff --git a/electron/accounts-main.mjs b/electron/accounts-main.mjs
index a3816fb1db..188345023d 100644
--- a/electron/accounts-main.mjs
+++ b/electron/accounts-main.mjs
@@ -40,14 +40,15 @@ export function createAccountLeave({ saved, persist, session, mine, leaveWindow,
* leave: ReturnType<typeof createAccountLeave>,
* show(): Promise<unknown>,
* tell(): void,
- * }} deps `ownPage`: this app's own page in the window, or the rail's. `placePage`: the page of a place of the person's own
+ * clean?(): boolean,
+ * }} deps `clean`: the clean workspace runs (clean-workspace.mjs). `ownPage`: this app's own page in the window, or the rail's. `placePage`: the page of a place of the person's own
* or their team's, which may offer the sheet. `holdSheet`: the rail's page stays up for the sheet, even for someone who hid
* the rail. `leaving`: the home window lets go of what it was doing for this account; `leave`: createAccountLeave's;
* `show`: the window goes where it belongs now; `tell`: this app's pages read the list again.
*/
-export function installAccounts({ ipcMain, ownPage, placePage, account, client, holdSheet, tellSheet, leaving, leave, show, tell }) {
+export function installAccounts({ ipcMain, ownPage, placePage, account, client, holdSheet, tellSheet, leaving, leave, show, tell, clean = () => false }) {
let sheetPending = false, queue = Promise.resolve();
- const view = () => accountsView(account()?.state());
+ const view = () => ({ ...accountsView(account()?.state()), ...(clean() ? { clean: true } : {}) });
const serial = (work) => { const run = queue.then(work, work); queue = run.catch(() => {}); return run; };
const own = (channel, handler) => ipcMain.handle(channel, (event, ...args) => {
if (!ownPage(event)) throw new Error(`${channel} is only available on this app's own page`);
diff --git a/electron/accounts-main.node-test.mjs b/electron/accounts-main.node-test.mjs
index 1270b13c19..55853a02c7 100644
--- a/electron/accounts-main.node-test.mjs
+++ b/electron/accounts-main.node-test.mjs
@@ -143,3 +143,14 @@ test("a My Cloud saved by hand is the account's only while the sign-in names it;
assert.equal(withoutPlaces(changed, [byHand]).activeId, "local");
assert.equal(withoutPlaces(changed, []), changed, "nothing to remove: the same list");
});
+
+test("the view says when the clean workspace runs, for the You menu's Sign in; nothing changes otherwise", async () => {
+ const handlers = new Map();
+ let clean = true;
+ const client = { state: () => ({ status: "signed-out" }) };
+ installAccounts({ ipcMain: { handle: (channel, handler) => handlers.set(channel, handler) }, ownPage: () => true, placePage: () => true, account: () => client, client: () => client, clean: () => clean,
+ holdSheet() {}, tellSheet() {}, leaving() {}, leave: { places: () => [], finish: async () => [] }, show: async () => {}, tell() {} });
+ assert.deepEqual(await handlers.get("accounts:list")({}), { active: null, others: [], clean: true });
+ clean = false;
+ assert.deepEqual(await handlers.get("accounts:list")({}), { active: null, others: [] });
+});
diff --git a/electron/cloud-account.d.mts b/electron/cloud-account.d.mts
index ffcfe742b0..8af5360fb5 100644
--- a/electron/cloud-account.d.mts
+++ b/electron/cloud-account.d.mts
@@ -174,7 +174,8 @@ export interface CloudAccountBridge {
}
/** Who is signed in on this device, as the You menu shows it. `signIn`: this account's sign-in has ended here. */
export interface AccountRow { id: string; email: string; signIn?: true }
-export interface AccountsView { active: AccountRow | null; others: AccountRow[] }
+/** `clean`: the clean workspace runs on this computer, whose line asks the person to sign in. */
+export interface AccountsView { active: AccountRow | null; others: AccountRow[]; clean?: true }
/** This app's own pages only: main refuses any other page. Absent on an older app. */
export interface AccountsBridge {
list(): Promise<AccountsView>;
diff --git a/electron/main.mjs b/electron/main.mjs
index a3369f3856..42c6f31517 100644
--- a/electron/main.mjs
+++ b/electron/main.mjs
@@ -2688,7 +2688,7 @@ const chromeRail = createChromeRail({ createView: options => new WebContentsView
chromeRail.install(ipcMain);
function railChanged() { chromeRail.refresh(); rail.changed(); }
const accountPages = [() => (mainWindow && !mainWindow.isDestroyed() && senderIsLocal({ sender: mainWindow.webContents }) ? mainWindow.webContents : null), () => ({ send: channel => chromeRail.send(channel) })];
-const accounts = installAccounts({ ipcMain, ownPage: event => chromeRail.owns(event) || cloudPageAsking(event) === "local", placePage: event => cloudPageAsking(event) !== null || ownCloudPage(event) !== null || homeWindow.homePage(event) || (Boolean(ownHome?.home()) && activeEnvironment(environmentsState)?.origin === ownHome.home().origin && workspaceSenderAllowed(event, mainWindow?.webContents, environmentsState, rendererOrigin())), account: () => (app.isPackaged && !desktopRemoteAccess ? cloudAccount : null), client: ensureCloudAccount, holdSheet: open => chromeRail.holdOpen(open), tellSheet: () => chromeRail.send("accounts:open-sheet"), leaving: () => homeWindow.accountLeaving(), leave: createAccountLeave({ saved: () => environmentsState, persist: persistEnvironments, session: () => session.defaultSession, mine: () => myCloud(), leaveWindow: () => (mainWindow && !mainWindow.isDestroyed() && !senderIsLocal({ sender: mainWindow.webContents }) ? navigateMainWindow(rendererOrigin()) : null), settled: () => computerSharing?.goodbyesDone(), log: slog }), show: () => showHome(), tell: () => { for (const page of accountPages) page()?.send("accounts:changed"); } });
+const accounts = installAccounts({ ipcMain, clean: () => cleanWorkspace.active(), ownPage: event => chromeRail.owns(event) || cloudPageAsking(event) === "local", placePage: event => cloudPageAsking(event) !== null || ownCloudPage(event) !== null || homeWindow.homePage(event) || (Boolean(ownHome?.home()) && activeEnvironment(environmentsState)?.origin === ownHome.home().origin && workspaceSenderAllowed(event, mainWindow?.webContents, environmentsState, rendererOrigin())), account: () => (app.isPackaged && !desktopRemoteAccess ? cloudAccount : null), client: ensureCloudAccount, holdSheet: open => chromeRail.holdOpen(open), tellSheet: () => chromeRail.send("accounts:open-sheet"), leaving: () => homeWindow.accountLeaving(), leave: createAccountLeave({ saved: () => environmentsState, persist: persistEnvironments, session: () => session.defaultSession, mine: () => myCloud(), leaveWindow: () => (mainWindow && !mainWindow.isDestroyed() && !senderIsLocal({ sender: mainWindow.webContents }) ? navigateMainWindow(rendererOrigin()) : null), settled: () => computerSharing?.goodbyesDone(), log: slog }), show: () => showHome(), tell: () => { for (const page of accountPages) page()?.send("accounts:changed"); } });
const rail = installCloudRail({ ipcMain, clipboard, openCloud: openOwnCloud, account: () => (app.isPackaged && !desktopRemoteAccess ? cloudAccount : null),
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(),
diff --git a/src/components/AccountMenu.test.ts b/src/components/AccountMenu.test.ts
index 073b6b1bb4..27de9c3164 100644
--- a/src/components/AccountMenu.test.ts
+++ b/src/components/AccountMenu.test.ts
@@ -1,5 +1,5 @@
import { afterEach, expect, it, vi } from "vitest";
-import { accountMenuItems } from "./AccountMenu";
+import { accountMenuItems, cloudRowLabel } from "./AccountMenu";
afterEach(() => vi.unstubAllGlobals());
const signOut = vi.fn();
@@ -24,3 +24,10 @@ it("another place's page shows no address, only the row that asks main for the s
items[0].onSelect();
expect(openSheet).toHaveBeenCalled();
});
+
+it("the MausBot Cloud row says Sign in only while the clean workspace's line asks for it", () => {
+ expect(cloudRowLabel({ active: null, others: [], clean: true })).toBe("Sign in");
+ expect(cloudRowLabel({ active: null, others: [] })).toBe("MausBot Cloud");
+ expect(cloudRowLabel({ active: { id: "b", email: "[email protected]" }, others: [], clean: true })).toBe("MausBot Cloud");
+ expect(cloudRowLabel(null)).toBe("MausBot Cloud");
+});
diff --git a/src/components/AccountMenu.tsx b/src/components/AccountMenu.tsx
index b126a82dfd..1d471b7f29 100644
--- a/src/components/AccountMenu.tsx
+++ b/src/components/AccountMenu.tsx
@@ -40,6 +40,12 @@ export function useAccounts(): AccountsAccess {
};
}
+/** The You menu's row for the MausBot Cloud page: with the clean workspace open and nobody signed in, the line there asks the person
+ * to sign in, and this row is how. */
+export function cloudRowLabel(view: AccountsView | null): string {
+ return t(view?.clean && !view.active ? "accounts.signIn" : "settings.section.cloudAccount");
+}
+
/** The You menu's last rows. On another page, one row that opens the sheet. Signed out: nothing, as Settings has the sign-in. */
export function accountMenuItems({ view, openSheet, signOut }: AccountsAccess): SidebarMenuItem[] {
if (openSheet) return [{ key: "accounts-sheet", label: t("accounts.manage"), icon: <UserRound size={18} />, onSelect: openSheet }];
diff --git a/src/components/SidebarProfileMenu.tsx b/src/components/SidebarProfileMenu.tsx
index 9b6622abc3..2289034b70 100644
--- a/src/components/SidebarProfileMenu.tsx
+++ b/src/components/SidebarProfileMenu.tsx
@@ -23,7 +23,7 @@ import {
Zap,
} from "lucide-react";
-import { accountMenuItems, useAccounts } from "./AccountMenu";
+import { accountMenuItems, cloudRowLabel, useAccounts } from "./AccountMenu";
import { AccountMoveStatus, useAccountMove, type AccountMoveKind } from "./AccountMove";
import { InitialsAvatar } from "./Avatar";
import { DiscordIcon } from "./DiscordIcon";
@@ -603,7 +603,7 @@ export function SidebarProfileMenu({ iconOnly = false, rail = false, circle = fa
update: update?.item ?? null,
updateTop: simple ? simpleUpdateTop(update) : null,
move: move.items,
- account: cloudAccount ? t("settings.section.cloudAccount") : null,
+ account: cloudAccount ? cloudRowLabel(accounts.view) : null,
accounts: accountMenuItems(accounts),
...(account ? { simple: {
tools: toolMenuItems({