Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/desktop/scripts/start-electron.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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 });
Expand Down
11 changes: 10 additions & 1 deletion apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}/`;
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
4 changes: 2 additions & 2 deletions apps/desktop/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,7 +22,7 @@ export function startServer(): Promise<string> {
...process.env,
ELECTRON_RUN_AS_NODE: "1",
// The app server keeps app.db in the CodeWork home under desktop/<channel>; from the repo, `local`.
CODEWORK_CHANNEL: app.isPackaged ? manifest().channel : "local",
CODEWORK_CHANNEL: channel(),
},
stdio: ["ignore", "pipe", "inherit"],
});
Expand Down