Skip to content

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

fix(desktop): start when the Documents folder can't be found

Zhaowei Gu01dd26b6d53e
diff --git a/electron/cloud-sync-main.mjs b/electron/cloud-sync-main.mjs
index 7ea08d2ad1..538ddf72e2 100644
--- a/electron/cloud-sync-main.mjs
+++ b/electron/cloud-sync-main.mjs
@@ -10,6 +10,11 @@ import { lendingForFiles } from "./lent-folders.mjs";
const TOKEN_MS = 30 * 60_000;
+// Electron 43 throws when Windows can't resolve the Documents known folder, e.g. one redirected to a drive or share that is gone.
+function documentsDir(app) {
+ try { return app.getPath("documents"); } catch { return path.join(app.getPath("home"), "Documents"); }
+}
+
/** Whose Files this folder keeps: the first account to use it, as it was before there could be several. Another account's
* are in a folder of their own, so a folder one account shares is never registered on another's Cloud. */
export function filesFolderOf(root, accountId, read = (file) => { try { return JSON.parse(fs.readFileSync(file, "utf8")).accountId ?? null; } catch { return null; } },
@@ -27,7 +32,7 @@ export function installCloudFiles({ app, ipcMain, dialog, shell, powerMonitor, f
const root = path.join(app.getPath("userData"), stateDir);
const open = (dir) => makeService({ t,
settingsFile: path.join(dir, "settings.json"), stateFile: path.join(dir, "state.db"),
- documentsDir: app.getPath("documents"), homeDir: app.getPath("home"), localDataDir, cloudOrigin, fetch, ...(power ? { power } : {}),
+ documentsDir: documentsDir(app), homeDir: app.getPath("home"), localDataDir, cloudOrigin, fetch, ...(power ? { power } : {}),
trashItem: (file) => shell.trashItem(file), markDownloaded: createDownloadMarker(),
onChange: (state) => send("files:state-changed", state),
lending, planDisk: () => { try { return cloudPlanDisk(cloudAccount().state()); } catch { return null; } },
diff --git a/electron/cloud-sync-main.node-test.mjs b/electron/cloud-sync-main.node-test.mjs
index c582a72c3e..b708869e27 100644
--- a/electron/cloud-sync-main.node-test.mjs
+++ b/electron/cloud-sync-main.node-test.mjs
@@ -64,6 +64,23 @@ test("Files channels answer this computer's own window only, and share only a fo
assert.doesNotThrow(() => installed.close());
});
+test("Files starts when the Documents folder can't be found, and keeps bot outputs in the home folder's Documents", async (t) => {
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), "omb-files-documents-")));
+ const handlers = new Map(), opened = [];
+ const installed = installCloudFiles({
+ app: { getPath: (name) => { if (name === "documents") throw new Error("Failed to get 'documents' path"); return join(dir, name); } },
+ ipcMain: { handle: (channel, handler) => handlers.set(channel, handler) }, dialog: {},
+ shell: { trashItem: async () => {}, openPath: async (folder) => { opened.push(folder); return ""; } }, powerMonitor: { on: () => {} },
+ fetch: async () => { throw new Error("offline"); }, localWorkspaceOnly: (_channel, handler) => handler, send: () => {}, cloudOrigin: () => null,
+ cloudAccount: () => ({ openDashboard: async () => {} }), localDataDir: join(dir, "home", ".openmausbot"),
+ });
+ t.after(() => { installed.close(); rmSync(dir, { recursive: true, force: true }); });
+ const outputs = join(dir, "home", "Documents", "MausBot");
+ assert.equal((await handlers.get("files:state")({})).outputs.dir, outputs);
+ await handlers.get("files:open")({}, { outputs: true });
+ assert.deepEqual(opened, [outputs]);
+});
+
test("a folder added on the Files page is lent, read only, and Stop sharing takes it back from lending", async (t) => {
const dir = realpathSync(mkdtempSync(join(tmpdir(), "omb-files-lend-")));
const picked = join(dir, "home", "Clients");