Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Always-on home: keep lending's login item, remove only the switch's own
milind-sonid35bc03c68ef
diff --git a/electron/always-on-home.mjs b/electron/always-on-home.mjsindex 27450ed420..79cb99c453 100644--- a/electron/always-on-home.mjs+++ b/electron/always-on-home.mjs@@ -11,19 +11,21 @@ export const ALWAYS_ON_BLOCKER = "prevent-app-suspension";export const ALWAYS_ON_LOOK_MS = 60_000;const UPDATES = new Set(["by-itself", "restart", "package", "none"]);-/** The saved switch: `{ v: 1, on, addedLogin }`; anything else reads as off. `addedLogin`: turning it on added the login item. */+/** The saved switch: `{ v: 1, on, addedLogin, declined? }`; anything else reads as off. `addedLogin`: turning it on+ * added the login item; `declined`: what Windows had saved about the person turning Open at login off before that. */export function parseAlwaysOn(value) {if (!value || typeof value !== "object" || value.v !== 1) return { v: 1, on: false, addedLogin: false };- return { v: 1, on: value.on === true, addedLogin: value.on === true && value.addedLogin === true };+ const addedLogin = value.on === true && value.addedLogin === true;+ return { v: 1, on: value.on === true, addedLogin, ...(addedLogin && typeof value.declined === "boolean" ? { declined: value.declined } : {}) };}/**- * `loginItem`: open-at-login.mjs's item (`available`, `chosen`, `choose`). `blocker`: Electron's powerSaveBlocker.- * `isOnBattery()`: powerMonitor's word. `updates()`: how an update arrives with nobody at the computer (updater.mjs- * `unattendedUpdates`). `platform`: process.platform. `loginNeeded()`: lending still wants the app to start at login, so- * turning the switch off leaves the login item.+ * `loginItem`: open-at-login.mjs's item. `blocker`: Electron's powerSaveBlocker. `isOnBattery()`: powerMonitor's word.+ * `updates()`: how an update arrives with nobody at the computer (updater.mjs `unattendedUpdates`). `platform`:+ * process.platform. `lending()`: lending has anything lent now, the same test lending's own login item follows, so turning+ * the switch off hands the item it added to lending instead of removing it.*/-export function createAlwaysOnHome({ file, loginItem, blocker, isOnBattery, updates = () => "none", loginNeeded = () => false, platform = process.platform, log = () => {}, lookMs = ALWAYS_ON_LOOK_MS }) {+export function createAlwaysOnHome({ file, loginItem, blocker, isOnBattery, updates = () => "none", lending = () => false, platform = process.platform, log = () => {}, lookMs = ALWAYS_ON_LOOK_MS }) {let saved = read();let blockerId = null;let timer = null;@@ -43,7 +45,12 @@ export function createAlwaysOnHome({ file, loginItem, blocker, isOnBattery, upda}}const battery = () => { try { return isOnBattery() === true; } catch { return false; } };- const loginOn = () => { try { return loginItem.chosen() === true; } catch { return false; } };+ const loginOn = () => { try { return loginItem.starts() === true; } catch { return false; } };+ const lendingNow = () => { try { return lending() === true; } catch { return false; } };+ const tryLogin = (what, run) => { try { run(); } catch (error) { log(`always-on home: login item (${what}): ${error?.message ?? error}`); } };+ loginItem.hold(saved.on);+ // The person changed Open at login themselves while the switch was on: it is theirs now, and off leaves it as they set it.+ loginItem.whenChosen(() => { if (saved.on && saved.addedLogin) write({ v: 1, on: true, addedLogin: false }); });function look() {const hold = saved.on && !battery();@@ -76,14 +83,20 @@ export function createAlwaysOnHome({ file, loginItem, blocker, isOnBattery, updaset(on) {const want = on === true;if (want === saved.on) { look(); return state(); }- let addedLogin = false;- try {- if (want && !loginOn()) { loginItem.choose(true); addedLogin = true; }- else if (!want && saved.addedLogin && loginOn() && !loginNeeded()) loginItem.choose(false);- } catch (error) {- log(`always-on home: login item: ${error?.message ?? error}`);+ if (want) {+ // Whatever already starts the app at login (the person's item, or lending's) is kept as it is and counts as on.+ loginItem.hold(true);+ let added = null;+ if (!loginOn()) tryLogin("add", () => { added = { declined: loginItem.homeAdd() }; });+ write({ v: 1, on: true, addedLogin: added !== null, ...(typeof added?.declined === "boolean" ? { declined: added.declined } : {}) });+ } else {+ const lent = lendingNow();+ if (saved.addedLogin) tryLogin("release", () => loginItem.homeRelease({ declined: saved.declined ?? null, lending: lent }));+ loginItem.hold(false);+ // Lending may have stopped while the switch kept its item: its own bookkeeping takes it away now.+ tryLogin("follow", () => loginItem.follow(lent));+ write({ v: 1, on: false, addedLogin: false });}- write({ v: 1, on: want, addedLogin });look();return state();},diff --git a/electron/always-on-home.node-test.mjs b/electron/always-on-home.node-test.mjsindex 7f8a9a57fd..a7bd687859 100644--- a/electron/always-on-home.node-test.mjs+++ b/electron/always-on-home.node-test.mjs@@ -6,11 +6,21 @@ import test from "node:test";import { ALWAYS_ON_BLOCKER, createAlwaysOnHome, installAlwaysOnHome, parseAlwaysOn } from "./always-on-home.mjs";+/** A login item that is simply on or off, recording what the switch asked of it. */+function simpleLogin(world, available = true) {+ return {+ available: () => available, chosen: () => world.login, starts: () => world.login, hold: () => {}, whenChosen: () => {}, follow: () => {},+ choose: (on) => { world.chose.push(on); world.login = on; },+ homeAdd: () => { world.chose.push(true); world.login = true; return null; },+ homeRelease: () => { world.chose.push(false); world.login = false; },+ };+}+function fixture(t, { login = false, battery = false, available = true, updates = "by-itself", platform = "darwin" } = {}) {const dir = mkdtempSync(path.join(tmpdir(), "omb-always-on-"));t.after(() => rmSync(dir, { recursive: true, force: true }));const world = { login, battery, chose: [], held: new Set(), started: [], nextId: 1 };- const loginItem = { available: () => available, chosen: () => world.login, choose: (on) => { world.chose.push(on); world.login = on; } };+ const loginItem = simpleLogin(world, available);const blocker = {start: (type) => { const id = world.nextId++; world.started.push(type); world.held.add(id); return id; },stop: (id) => { world.held.delete(id); },@@ -72,19 +82,6 @@ test("off undoes only what on changed: a login item the person set up stays", (tassert.equal(theirs.world.login, true);});-test("off leaves the login item while lending still needs the app to start at login", (t) => {- const f = fixture(t);- let lending = false;- const home = createAlwaysOnHome({ file: f.file, loginItem: { available: () => true, chosen: () => f.world.login, choose: (on) => { f.world.chose.push(on); f.world.login = on; } },- blocker: { start: () => 1, stop: () => {}, isStarted: () => true }, isOnBattery: () => false, loginNeeded: () => lending });- home.set(true);- lending = true;- home.set(false);- assert.deepEqual(f.world.chose, [true], "nothing removed while lending wants it");- assert.equal(f.world.login, true);- home.stop();-});-test("the switch survives a restart, and a fresh launch holds the computer awake again", (t) => {const f = fixture(t);f.home.set(true);@@ -102,7 +99,7 @@ test("a damaged file reads as off, and a failing login item still saves the choiconst f = fixture(t);writeFileSync(f.file, "{not json");assert.equal(f.make().on(), false);- const home = createAlwaysOnHome({ file: f.file, loginItem: { available: () => true, chosen: () => false, choose: () => { throw new Error("denied"); } },+ const home = createAlwaysOnHome({ file: f.file, loginItem: { ...simpleLogin(f.world), homeAdd: () => { throw new Error("denied"); } },blocker: { start: () => 1, stop: () => {}, isStarted: () => true }, isOnBattery: () => false });const state = home.set(true);assert.equal(state.on, true);@@ -120,7 +117,7 @@ test("Settings' channels go through main's guard, and set takes only true as on"const handlers = new Map(), guarded = [];let changed = 0;const home = installAlwaysOnHome({ ipcMain: { handle: (channel, handler) => handlers.set(channel, handler) }, guard: (channel, handler) => { guarded.push(channel); return handler; },- changed: () => changed++, file: f.file, loginItem: { available: () => true, chosen: () => f.world.login, choose: (on) => { f.world.login = on; } },+ changed: () => changed++, file: f.file, loginItem: simpleLogin(f.world),blocker: { start: () => 1, stop: () => {}, isStarted: () => false }, isOnBattery: () => false });assert.deepEqual(guarded, ["always-on-home:state", "always-on-home:set"]);assert.equal((await handlers.get("always-on-home:set")({}, "true")).on, false, "a string is not a yes");diff --git a/electron/always-on-login.node-test.mjs b/electron/always-on-login.node-test.mjsnew file mode 100644index 0000000000..6740b8514f--- /dev/null+++ b/electron/always-on-login.node-test.mjs@@ -0,0 +1,186 @@+// The always-on home's switch with the real login item (open-at-login.mjs) and lending's own use of it, against fakes of+// each system's login items: macOS keeps one item with no arguments, Windows one Run entry per name (read as on only for+// the arguments asked about), Linux one autostart file.+import assert from "node:assert/strict";+import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";+import { tmpdir } from "node:os";+import path from "node:path";+import test from "node:test";++import { createAlwaysOnHome } from "./always-on-home.mjs";+import { createOpenAtLogin, HIDDEN_ARG } from "./open-at-login.mjs";++const blocker = { start: () => 1, stop() {}, isStarted: () => true };+const CHOSEN = "OpenMausBot at login";++function world(t, platform) {+ const dir = mkdtempSync(path.join(tmpdir(), "omb-always-on-login-"));+ t.after(() => rmSync(dir, { recursive: true, force: true }));+ const items = new Map();+ let macOn = false;+ const app = platform === "win32"+ ? {+ isPackaged: true,+ getLoginItemSettings: (asked = {}) => ({+ openAtLogin: [...items.values()].some(item => JSON.stringify(item.args) === JSON.stringify(asked.args ?? [])),+ launchItems: [...items].map(([name, item]) => ({ name, args: item.args, enabled: true })),+ }),+ setLoginItemSettings: ({ openAtLogin, args = [], name = "app" }) => { if (openAtLogin) items.set(name, { args }); else items.delete(name); },+ }+ : { isPackaged: true, getLoginItemSettings: () => ({ openAtLogin: macOn }), setLoginItemSettings: ({ openAtLogin }) => { macOn = openAtLogin; } };+ const loginFile = path.join(dir, "open-at-login.json");+ const login = createOpenAtLogin({ app, file: loginFile, platform, home: dir, env: { XDG_CONFIG_HOME: path.join(dir, "config") }, execPath: "/opt/omb/omb" });+ let lent = false;+ const make = () => createAlwaysOnHome({ file: path.join(dir, "always-on-home.json"), loginItem: login, blocker, isOnBattery: () => false, lending: () => lent, platform, lookMs: 3_600_000 });+ const autostart = path.join(dir, "config", "autostart", "openmausbot.desktop");+ return {+ login, items, make, home: make(),+ /** Lending starts or stops: its own login item follows, as main's sharing onChange does. */+ lend(on) { lent = on; login.follow(on); },+ macOn: () => macOn,+ names: () => [...items.keys()].sort(),+ declined: () => { try { return JSON.parse(readFileSync(loginFile, "utf8")).declined; } catch { return undefined; } },+ autostart: () => (existsSync(autostart) ? readFileSync(autostart, "utf8") : null),+ };+}+const marked = text => text !== null && text.includes("X-OpenMausBot-Lending=true") && text.includes(HIDDEN_ARG);++test("Windows: off removes only the switch's own entry, so lending can add its hidden one afterwards", t => {+ const w = world(t, "win32");+ assert.equal(w.home.set(true).openAtLogin, true);+ assert.deepEqual(w.names(), [CHOSEN]);+ w.home.set(false);+ assert.deepEqual(w.names(), []);+ w.lend(true);+ assert.deepEqual(w.names(), ["app"], "lending's entry, as if the switch had never been on");+ assert.deepEqual(w.items.get("app").args, [HIDDEN_ARG]);+});++test("Windows: the person's earlier Off is put back when the switch goes off", t => {+ const w = world(t, "win32");+ w.login.choose(false);+ assert.equal(w.declined(), true);+ w.home.set(true);+ assert.deepEqual(w.names(), [CHOSEN]);+ assert.equal(w.declined(), false);+ w.home.set(false);+ assert.equal(w.declined(), true);+ w.lend(true);+ assert.deepEqual(w.names(), [], "lending still adds nothing, as before the switch");+});++test("Windows: off while lending leaves lending's entry; on while lending adds none of its own", t => {+ const w = world(t, "win32");+ w.home.set(true);+ w.lend(true);+ assert.deepEqual(w.names(), [CHOSEN, "app"]);+ w.home.set(false);+ assert.deepEqual(w.names(), ["app"]);+ w.lend(false);+ assert.deepEqual(w.names(), []);++ const v = world(t, "win32");+ v.lend(true);+ assert.equal(v.home.set(true).openAtLogin, true, "lending's entry already starts the app: counted as on");+ assert.deepEqual(v.names(), ["app"]);+ v.lend(false);+ assert.deepEqual(v.names(), ["app"], "while the switch is on, lending stopping leaves the entry");+ v.home.set(false);+ assert.deepEqual(v.names(), [], "off: lending's own bookkeeping takes it away");+});++test("Windows: the person's own change while the switch is on is kept at off", t => {+ const w = world(t, "win32");+ w.home.set(true);+ w.login.choose(false);+ w.home.set(false);+ assert.equal(w.declined(), true, "their Off stays");+ w.lend(true);+ assert.deepEqual(w.names(), []);++ const v = world(t, "win32");+ v.home.set(true);+ v.login.choose(false);+ v.login.choose(true);+ v.home.set(false);+ assert.deepEqual(v.names(), [CHOSEN], "their On stays");+});++test("macOS: on and off with lending to a server of the person's own leaves lending's login item", t => {+ const m = world(t, "darwin");+ m.lend(true);+ assert.equal(m.home.set(true).openAtLogin, true);+ assert.equal(m.login.chosen(), false, "still lending's, not taken over");+ m.home.set(false);+ assert.equal(m.macOn(), true);+ m.lend(false);+ assert.equal(m.macOn(), false);+});++test("macOS: off while lending hands the item to lending, which removes it once it stops", t => {+ const m = world(t, "darwin");+ m.home.set(true);+ assert.equal(m.macOn(), true);+ m.lend(true);+ m.home.set(false);+ assert.deepEqual([m.macOn(), m.login.chosen()], [true, false]);+ m.lend(false);+ assert.deepEqual([m.macOn(), m.login.chosen()], [false, false]);+});++test("macOS: lending stopping while the switch is on leaves the item; off then takes it away", t => {+ const m = world(t, "darwin");+ m.lend(true);+ m.home.set(true);+ m.lend(false);+ assert.equal(m.macOn(), true);+ assert.equal(m.make().state().openAtLogin, true, "after a restart too");+ m.home.set(false);+ assert.equal(m.macOn(), false);+});++test("macOS: the person's own login item stays, and so does one they chose while the switch was on", t => {+ const m = world(t, "darwin");+ m.login.choose(true);+ m.home.set(true);+ m.home.set(false);+ assert.deepEqual([m.macOn(), m.login.chosen()], [true, true]);++ const n = world(t, "darwin");+ n.home.set(true);+ n.login.choose(false);+ n.login.choose(true);+ n.home.set(false);+ assert.deepEqual([n.macOn(), n.login.chosen()], [true, true]);++ const o = world(t, "darwin");+ o.home.set(true);+ o.home.set(false);+ assert.equal(o.macOn(), false, "the item the switch added goes");+});++test("Linux: the switch's own entry goes at off; lending's marked file is never overwritten, and is handed back", t => {+ const l = world(t, "linux");+ l.home.set(true);+ assert.equal(marked(l.autostart()), false);+ assert.ok(l.autostart()?.includes("Exec="));+ l.home.set(false);+ assert.equal(l.autostart(), null);++ const k = world(t, "linux");+ k.lend(true);+ k.home.set(true);+ assert.equal(marked(k.autostart()), true, "lending's file stays lending's");+ k.lend(false);+ assert.equal(marked(k.autostart()), true, "kept while the switch is on");+ k.home.set(false);+ assert.equal(k.autostart(), null);++ const j = world(t, "linux");+ j.home.set(true);+ j.lend(true);+ j.home.set(false);+ assert.equal(marked(j.autostart()), true, "off while lending: now lending's");+ j.lend(false);+ assert.equal(j.autostart(), null);+});diff --git a/electron/computer-sharing.d.mts b/electron/computer-sharing.d.mtsindex 3b48f2dfba..4d0d70cd3d 100644--- a/electron/computer-sharing.d.mts+++ b/electron/computer-sharing.d.mts@@ -176,6 +176,7 @@ export function createComputerSharing(options: {/** Lending's last requests have been answered or have timed out; a Cloud's answer can re-issue its session cookie. */goodbyesDone(): Promise<unknown>;lendingToCloud(): boolean;+ lendingSomewhere(): boolean;/** A server is using this computer now: a job running on it, or its browsing going through this computer. */busy(): boolean;saveCloud(env: Workspace, input: { folders: unknown; screen?: boolean; internet?: boolean; chrome?: boolean; terminal?: boolean }, version?: number): Promise<CloudLendingState>;diff --git a/electron/computer-sharing.mjs b/electron/computer-sharing.mjsindex 74a8419767..d88a093668 100644--- a/electron/computer-sharing.mjs+++ b/electron/computer-sharing.mjs@@ -901,6 +901,8 @@ export function createComputerSharing({ file, fetch: fetchImpl, environments, lo},/** Lending to My Cloud is running, so it calls My Cloud whenever it is awake. */lendingToCloud: () => [...running.keys()].some(id => Boolean(records[id]?.cloud)),+ /** Anything is lent now (to a Cloud or a server of the person's own, running or not): what its login item follows. */+ lendingSomewhere: () => summary().lending.length > 0,/** A server is using this computer now: a job running on it, or its browsing going through this computer. */busy: () => summary().busy !== null,saveCloud,diff --git a/electron/main.mjs b/electron/main.mjsindex 5e63682a7b..603fa3c0b1 100644--- a/electron/main.mjs+++ b/electron/main.mjs@@ -1456,7 +1456,7 @@ function reconnectCloud(origin) {return signInCloudSession({ origin, mine: other ? origin : myCloud(), pair: () => ensureCloudAccount().pairHome(other?.id ?? null), fetch: (...args) => session.defaultSession.fetch(...args) });}const loginItem = createOpenAtLogin({ app, file: path.join(app.getPath("userData"), "open-at-login.json"), home: os.homedir() });-installOpenAtLogin({ ipcMain, guard: localOrHome, loginItem, changed: refreshApplicationMenu }); const alwaysOnHome = installAlwaysOnHome({ ipcMain, guard: localOnly, loginItem, changed: refreshApplicationMenu, file: path.join(app.getPath("userData"), "always-on-home.json"), blocker: powerSaveBlocker, isOnBattery: () => powerMonitor.isOnBatteryPower(), updates: unattendedUpdates, loginNeeded: () => Boolean(computerSharing?.lendingToCloud()), log: slog });+installOpenAtLogin({ ipcMain, guard: localOrHome, loginItem, changed: refreshApplicationMenu }); const alwaysOnHome = installAlwaysOnHome({ ipcMain, guard: localOnly, loginItem, changed: refreshApplicationMenu, file: path.join(app.getPath("userData"), "always-on-home.json"), blocker: powerSaveBlocker, isOnBattery: () => powerMonitor.isOnBatteryPower(), updates: unattendedUpdates, lending: () => computerSharing?.lendingSomewhere() === true, log: slog });let hiddenStart = false;async function openCloudSettings() {diff --git a/electron/open-at-login.d.mts b/electron/open-at-login.d.mtsindex 914ce2d388..fc5246926c 100644--- a/electron/open-at-login.d.mts+++ b/electron/open-at-login.d.mts@@ -1,6 +1,10 @@export declare const HIDDEN_ARG: string;export declare function autostartEntry(exec: string, options?: { lending?: boolean }): string;-type LoginItem = { follow(on: boolean): void; startedHidden(): boolean; available(): boolean; chosen(): boolean; choose(on: boolean): void };+type LoginItem = {+ follow(on: boolean): void; startedHidden(): boolean; available(): boolean; chosen(): boolean; choose(on: boolean): void;+ whenChosen(listener: () => void): void; hold(on: boolean): void; starts(): boolean; homeAdd(): boolean | null;+ homeRelease(options?: { declined?: boolean | null; lending?: boolean }): void;+};export declare function createOpenAtLogin(options: {app: {isPackaged: boolean;diff --git a/electron/open-at-login.mjs b/electron/open-at-login.mjsindex 41a13a84fc..c9df06b1fb 100644--- a/electron/open-at-login.mjs+++ b/electron/open-at-login.mjs@@ -23,6 +23,8 @@ export function autostartEntry(exec, { lending = true } = {}) {* `follow(on)` keeps the login item in step with lending; `startedHidden()` says this launch came from it.* `chosen()` and `choose(on)`: the person's own login item, which opens the window and which lending never removes; on* Windows, whether Windows starts the app at sign-in at all, as its Startup apps list shows.+ * The always-on home (always-on-home.mjs) has its own calls: `hold(on)` keeps the item while lending stops, `homeAdd()`+ * adds the person's kind of item, and `homeRelease()` takes away only that one, or gives it to lending.*/export function createOpenAtLogin({ app, file, platform = process.platform, env = process.env, home, argv = process.argv, execPath = process.execPath }) {const autostart = path.join(env.XDG_CONFIG_HOME || path.join(home, ".config"), "autostart", "openmausbot.desktop");@@ -35,9 +37,29 @@ export function createOpenAtLogin({ app, file, platform = process.platform, env* each with its name, arguments and whether Task Manager has it enabled. */const windowsStartsApp = () => (app.getLoginItemSettings().launchItems ?? []).filter(item => item.enabled !== false);const ours = () => { try { return fs.readFileSync(autostart, "utf8").includes(MARK); } catch { return false; } };- return {+ let holding = false;+ let whenChosen = () => {};+ function choose(on) {+ if (!app.isPackaged) return;+ if (platform === "linux") {+ if (on) {+ fs.mkdirSync(path.dirname(autostart), { recursive: true });+ fs.writeFileSync(autostart, autostartEntry(env.APPIMAGE || execPath, { lending: false }));+ } else if (!ours()) fs.rmSync(autostart, { force: true });+ return;+ }+ if (platform === "win32") {+ if (on) app.setLoginItemSettings({ openAtLogin: true, args: [], name: CHOSEN_NAME });+ else for (const item of windowsStartsApp()) app.setLoginItemSettings({ openAtLogin: false, args: item.args ?? [], name: item.name });+ store({ declined: !on });+ return;+ }+ app.setLoginItemSettings({ openAtLogin: on });+ remember(false);+ }+ const login = {follow(on) {- if (!app.isPackaged) return;+ if (!app.isPackaged || (!on && holding)) return;try {if (platform === "linux") {if (on && !fs.existsSync(autostart)) {@@ -66,23 +88,49 @@ export function createOpenAtLogin({ app, file, platform = process.platform, envreturn app.getLoginItemSettings().openAtLogin === true && !added();} catch { return false; }},+ /** The person's own choice, from Settings or the app menu. */choose(on) {+ choose(on);+ whenChosen();+ },+ /** Called after each `choose`: the person has taken the item over from the always-on home. */+ whenChosen(listener) { whenChosen = listener; },+ /** While the always-on home is on, lending stopping leaves the item, whoever added it. */+ hold(on) { holding = on === true; },+ /** Anything starts the app at login: the person's item, lending's or the home's. */+ starts() {+ try {+ if (platform === "linux") return fs.existsSync(autostart);+ if (platform === "win32") return windowsStartsApp().length > 0;+ return app.getLoginItemSettings().openAtLogin === true;+ } catch { return false; }+ },+ /** The home adds the person's kind of item; it returns what Windows had saved about the person turning it off (null+ * elsewhere), for `homeRelease` to put back. */+ homeAdd() {+ const declined = platform === "win32" ? saved().declined === true : null;+ choose(true);+ return declined;+ },+ /** Takes away only the item `homeAdd` added (on Windows its own entry, and the saved word put back), or, while+ * `lending`, gives it to lending, which then removes it once it stops. */+ homeRelease({ declined = null, lending = false } = {}) {if (!app.isPackaged) return;if (platform === "linux") {- if (on) {- fs.mkdirSync(path.dirname(autostart), { recursive: true });- fs.writeFileSync(autostart, autostartEntry(env.APPIMAGE || execPath, { lending: false }));- } else if (!ours()) fs.rmSync(autostart, { force: true });+ if (!fs.existsSync(autostart) || ours()) return;+ if (lending) fs.writeFileSync(autostart, autostartEntry(env.APPIMAGE || execPath));+ else fs.rmSync(autostart, { force: true });return;}if (platform === "win32") {- if (on) app.setLoginItemSettings({ openAtLogin: true, args: [], name: CHOSEN_NAME });- else for (const item of windowsStartsApp()) app.setLoginItemSettings({ openAtLogin: false, args: item.args ?? [], name: item.name });- store({ declined: !on });+ app.setLoginItemSettings({ openAtLogin: false, args: [], name: CHOSEN_NAME });+ if (typeof declined === "boolean") store({ declined });+ if (lending) login.follow(true);return;}- app.setLoginItemSettings({ openAtLogin: on });- remember(false);+ if (app.getLoginItemSettings().openAtLogin !== true || added()) return;+ if (lending) remember(true);+ else app.setLoginItemSettings({ openAtLogin: false });},startedHidden() {if (platform === "darwin") {@@ -91,6 +139,7 @@ export function createOpenAtLogin({ app, file, platform = process.platform, envreturn argv.includes(HIDDEN_ARG);},};+ return login;}/** Settings' switch, on this computer's own page or My Cloud's page once it is home (`guard`); `changed` redraws the