Skip to content

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

Menus: stop offering this computer as a place once an own server is home

erywim1b683831a562
diff --git a/electron/environments.cjs b/electron/environments.cjs
index 93d465acd3..ffb893a0d6 100644
--- a/electron/environments.cjs
+++ b/electron/environments.cjs
@@ -76,14 +76,14 @@ function workspaceSenderAllowed(event, contents, state, localOrigin) {
* `places`: the one line saying which side has which bots, shown first; `copyToCloud`: the send line under the list. `foldSublabels`: where menus show no sublabels (Windows, Linux), My Cloud's status line
* joins its name instead of vanishing. `locals`: the workspaces of this computer's own (local-profiles.mjs), each opened by
* `onLocal(id)` (`shown`: the one on screen); `onNewLocal`: a new one, named on this computer's own page. */
-function workspaceMenuTemplate(state, { onSwitch, onConnect, onForget, onAddCloud, sublabels = {}, iconFor = null, places = null, copyToCloud = null, foldSublabels = false, homeOrigin = null, locals = [], onLocal = null, onNewLocal = null, text = englishText }) {
+function workspaceMenuTemplate(state, { onSwitch, onConnect, onForget, onAddCloud, sublabels = {}, iconFor = null, places = null, copyToCloud = null, foldSublabels = false, homeOrigin = null, localPlace = true, locals = [], onLocal = null, onNewLocal = null, text = englishText }) {
const active = activeEnvironment(state), { t } = text;
const own = onLocal ? locals.map((local) => ({ id: `workspace-local-${local.id}`, label: local.label, type: "radio", checked: local.shown === true, click: () => onLocal(local.id) })) : [];
const fresh = onNewLocal ? [{ id: "workspace-new-local", label: t("native.menu.newLocal"), click: onNewLocal }] : [];
if (homeOrigin) return homeMenuTemplate(state, { onSwitch, onForget, sublabels, iconFor, foldSublabels, homeOrigin, own, fresh, t });
return [
...(places ? [{ id: "workspace-places", label: places, enabled: false }, { type: "separator" }] : []),
- { id: "workspace-local", label: t("place.local"), type: "radio", checked: !active && !own.some((item) => item.checked), ...(iconFor && cleanColor(state.localColor) ? { icon: iconFor(state.localColor) } : {}), click: () => onSwitch(LOCAL_ID) },
+ ...(localPlace ? [{ id: "workspace-local", label: t("place.local"), type: "radio", checked: !active && !own.some((item) => item.checked), ...(iconFor && cleanColor(state.localColor) ? { icon: iconFor(state.localColor) } : {}), click: () => onSwitch(LOCAL_ID) }] : []),
...own,
...[...state.environments].sort((a, b) => listedPlace(b) - listedPlace(a)).map((entry) => {
const icon = iconFor && cleanColor(entry.color) ? iconFor(entry.color) : null;
diff --git a/electron/environments.node-test.mjs b/electron/environments.node-test.mjs
index d81323b5e2..8e24be5f25 100644
--- a/electron/environments.node-test.mjs
+++ b/electron/environments.node-test.mjs
@@ -113,6 +113,13 @@ test("native workspace choices use saved IDs and connect opens settings without
assert.equal(state.activeId, "cloud");
});
+test("with an own server as home, this computer is not offered as a place", () => {
+ const state = { environments: [{ id: "aliyun", name: "Aliyun", origin: "https://aliyun.example" }], activeId: "aliyun" };
+ const items = env.workspaceMenuTemplate(state, { onSwitch() {}, onConnect() {}, onForget() {}, localPlace: false });
+ assert.equal(items.some((item) => item.id === "workspace-local"), false);
+ assert.equal(items.find((item) => item.id === "workspace-aliyun").checked, true);
+});
+
test("Add a Cloud… sits just under the saved servers only where main offers it, and My Cloud's line can say Always on", () => {
const state = { environments: [{ id: "cloud", name: "My Cloud", origin: "https://omb-u-1.fly.dev" }, { id: "office", name: "Office", origin: "https://office.example" }], activeId: "local" };
const calls = [];
diff --git a/electron/main.mjs b/electron/main.mjs
index 17b10163ec..8560213927 100644
--- a/electron/main.mjs
+++ b/electron/main.mjs
@@ -1513,7 +1513,7 @@ function refreshApplicationMenu() {
onOpenSettings: () => { if (mainWindow && !mainWindow.isDestroyed()) mainWindow.webContents.send("app:open-settings"); },
openAtLogin: loginItem.available() ? { checked: loginItem.chosen(), onToggle: on => { loginItem.choose(on); refreshApplicationMenu(); } } : null,
...cloudMenuOptions(),
- home: homeWindow.cloudOrigin() ? { origin: homeWindow.cloudOrigin(), onBack: () => void showHome({ place: "cloud" }) } : null, t: nativeT,
+ home: homeWindow.cloudOrigin() ? { origin: homeWindow.cloudOrigin(), onBack: () => void showHome({ place: "cloud" }) } : null, localPlace: !(ownHome?.origin()), t: nativeT,
}),
);
}
@@ -2687,7 +2687,7 @@ ipcMain.handle("workspaces:menu", workspaceOnly(async (event, from) => {
onConnect: () => void workspaceMenuAction(openWorkspaceSettings),
onForget: (id) => void workspaceMenuAction(() => forgetEnvironment(id)),
...cloudMenuOptions(from === "howto" ? "app_howto" : "app_menu"),
- ...(await placesMenuOptions({ homeOrigin: homeWindow.cloudOrigin(), cloud: cloudHomeEntry(), home: oneHome.away() || ownHome?.away() === true, platform: process.platform, port: SERVER_PORT, text: nativeText })), text: nativeText, locals: localProfiles.places({ activeLocal: environmentsState.activeId === LOCAL_ID }).map(local => ({ id: local.id, label: local.name ?? nativeT(process.platform === "darwin" ? "rail.thisMac" : "rail.thisPc"), shown: local.active === true })), onLocal: id => void workspaceMenuAction(async () => { if ((await localProfiles.open(id)) === false) throw new Error(nativeT("native.places.profileFailed")); }), ...(localProfiles.creatable() && senderIsLocal(event) ? { onNewLocal: () => event.sender.send("workspaces:new-local") } : {}),
+ ...(await placesMenuOptions({ homeOrigin: homeWindow.cloudOrigin(), cloud: cloudHomeEntry(), home: oneHome.away() || ownHome?.away() === true, platform: process.platform, port: SERVER_PORT, text: nativeText })), localPlace: !(ownHome?.origin()), text: nativeText, locals: localProfiles.places({ activeLocal: environmentsState.activeId === LOCAL_ID }).map(local => ({ id: local.id, label: local.name ?? nativeT(process.platform === "darwin" ? "rail.thisMac" : "rail.thisPc"), shown: local.active === true })), onLocal: id => void workspaceMenuAction(async () => { if ((await localProfiles.open(id)) === false) throw new Error(nativeT("native.places.profileFailed")); }), ...(localProfiles.creatable() && senderIsLocal(event) ? { onNewLocal: () => event.sender.send("workspaces:new-local") } : {}),
}));
await new Promise((resolve) => menu.popup({ window: mainWindow, callback: resolve }));
} finally {
diff --git a/electron/menu.mjs b/electron/menu.mjs
index 0cb4c277ab..fa3718a0bb 100644
--- a/electron/menu.mjs
+++ b/electron/menu.mjs
@@ -84,7 +84,7 @@ const whereItLives = (environment) => (environment.kind === "local" ? environmen
* @param {{ checked: boolean, onToggle: (on: boolean) => void } | null} [input.openAtLogin] Open at Login, in the app
* menu on macOS and the File menu elsewhere; absent when this build cannot add a login item.
*/
-export function buildApplicationMenu({ environments, activeId, onSwitch, onAddFromClipboard, onConnect, onForget, onOpenSettings, onOrganizationSignIn, onAddCloud, sublabels = {}, home = null, openAtLogin = null, t = nativeText.englishText.t }) {
+export function buildApplicationMenu({ environments, activeId, onSwitch, onAddFromClipboard, onConnect, onForget, onOpenSettings, onOrganizationSignIn, onAddCloud, sublabels = {}, home = null, localPlace = true, openAtLogin = null, t = nativeText.englishText.t }) {
const isMac = process.platform === "darwin";
const active = environments.find((e) => e.id === activeId) ?? null;
const others = home ? environments.filter((e) => e.origin !== home.origin && e.kind !== "local") : [];
@@ -103,7 +103,7 @@ export function buildApplicationMenu({ environments, activeId, onSwitch, onAddFr
const server = home ? homeServer : {
label: t("native.menu.server"),
submenu: [
- { label: t("place.local"), type: "radio", checked: !active, click: () => onSwitch("local") },
+ ...(localPlace ? [{ label: t("place.local"), type: "radio", checked: !active, click: () => onSwitch("local") }] : []),
...environments.map((e) => ({
label: `${e.name} — ${Object.hasOwn(sublabels, e.id) ? sublabels[e.id] : whereItLives(e)}`,
type: "radio",