From f79954b23e96eb2888244f3ca789b1ee2d36c7a8 Mon Sep 17 00:00:00 2001 From: Sanchit Rk <0xsanchit@gmail.com> Date: Fri, 13 Nov 2026 13:00:05 +0530 Subject: [PATCH] fix(desktop): name a repo run CodeWork Local and give each build its own data folder Running from the repo, Electron took the package name, so the app and its data folder were `@codeworksh/desktop`. Main now names an unpackaged run "CodeWork Local" (the repo launcher's Dock name matches) and sets Electron's userData to one folder per build in Application Support: `codework` for latest, `codeworkcanary`, `codeworkdev` and `codeworklocal`. `channel()` in manifest.ts gives the channel for these folders and for the app server's database path. Co-Authored-By: Claude Opus 5.5 --- apps/desktop/scripts/start-electron.mjs | 5 +++-- apps/desktop/src/main.ts | 11 ++++++++++- apps/desktop/src/manifest.ts | 3 +++ apps/desktop/src/server.ts | 4 ++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/apps/desktop/scripts/start-electron.mjs b/apps/desktop/scripts/start-electron.mjs index 21182c3f..746eaa61 100644 --- a/apps/desktop/scripts/start-electron.mjs +++ b/apps/desktop/scripts/start-electron.mjs @@ -6,7 +6,8 @@ import { fileURLToPath } from "node:url"; const desktopDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const electronBinary = createRequire(import.meta.url)("electron"); -const APP_NAME = "CodeWork"; +// The name main gives an unpackaged run (src/main.ts), so the Dock and the menu agree. +const APP_NAME = "CodeWork Local"; // Its own identity, so a local run never shares data or Dock state with an installed channel. const APP_ID = "sh.codework.desktop.local"; @@ -17,7 +18,7 @@ function brandedElectron() { const target = path.join(desktopDir, ".electron-runtime", `${APP_NAME}.app`); const marker = path.join(desktopDir, ".electron-runtime", "source"); const binary = path.join(target, "Contents", "MacOS", "Electron"); - const stamp = `${source}\n${APP_ID}`; + const stamp = `${source}\n${APP_ID}\n${APP_NAME}`; if (existsSync(marker) && readFileSync(marker, "utf8") === stamp) return binary; rmSync(target, { recursive: true, force: true }); diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index 0eb1b990..161106db 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -2,9 +2,18 @@ import { app, BrowserWindow, dialog, ipcMain, net, protocol, shell } from "elect import { readFile, stat } from "node:fs/promises"; import path from "node:path"; import { HOME_CHANNEL, PICK_FOLDER_CHANNEL, REVEAL_CHANNEL } from "./ipc.ts"; -import { manifest } from "./manifest.ts"; +import { channel, manifest } from "./manifest.ts"; import { startServer } from "./server.ts"; +// Running from the repo Electron would take the package name (`@codeworksh/desktop`); a packaged +// build is named by its productName. Each build keeps Electron's own data in a folder of its own, +// named like the app: `codework` for latest, `codeworkcanary`, `codeworkdev`, `codeworklocal`. +if (!app.isPackaged) app.setName("CodeWork Local"); +app.setPath( + "userData", + path.join(app.getPath("appData"), channel() === "latest" ? "codework" : `codework${channel()}`), +); + const SCHEME = app.isPackaged ? "codework" : "codework-dev"; const HOST = "app"; const APP_URL = `${SCHEME}://${HOST}/`; diff --git a/apps/desktop/src/manifest.ts b/apps/desktop/src/manifest.ts index d15506e6..fe3b6281 100644 --- a/apps/desktop/src/manifest.ts +++ b/apps/desktop/src/manifest.ts @@ -8,3 +8,6 @@ export const manifest = () => readonly appId: string; readonly channel: "latest" | "dev" | "canary"; }; + +/** Where this build comes from: its release channel when packaged, `local` running from the repo. */ +export const channel = () => (app.isPackaged ? manifest().channel : "local"); diff --git a/apps/desktop/src/server.ts b/apps/desktop/src/server.ts index 95f399f6..e64dceac 100644 --- a/apps/desktop/src/server.ts +++ b/apps/desktop/src/server.ts @@ -3,7 +3,7 @@ import { spawn } from "node:child_process"; import path from "node:path"; import { createInterface } from "node:readline"; import { SERVER_CHANNEL } from "./ipc.ts"; -import { manifest } from "./manifest.ts"; +import { channel } from "./manifest.ts"; // The server bundle: in the app's Resources when packaged, else beside this app in the workspace. const ENTRY = app.isPackaged @@ -22,7 +22,7 @@ export function startServer(): Promise { ...process.env, ELECTRON_RUN_AS_NODE: "1", // The app server keeps app.db in the CodeWork home under desktop/; from the repo, `local`. - CODEWORK_CHANNEL: app.isPackaged ? manifest().channel : "local", + CODEWORK_CHANNEL: channel(), }, stdio: ["ignore", "pipe", "inherit"], });