Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(electron): resolve main paths in ESM runtime

vastsabfd975cb034b
diff --git a/apps/desktop/electron/main/agent-sidecar.ts b/apps/desktop/electron/main/agent-sidecar.ts
index c22befd4c..c149d48a5 100644
--- a/apps/desktop/electron/main/agent-sidecar.ts
+++ b/apps/desktop/electron/main/agent-sidecar.ts
@@ -5,6 +5,7 @@ import {
type StderrHandler,
} from "@pi-desktop/host-runtime";
import { redactValue } from "./logger";
+import { getModuleDirectory } from "./module-path";
export type {
LocalToolHandler,
@@ -18,13 +19,22 @@ export type {
function resolveSidecarEntry(): string {
const candidates = [
join(process.resourcesPath || "", "agent-runtime/sidecar.js"),
- join(__dirname, "../../../agent-runtime/dist/sidecar.js"),
- join(__dirname, "../../../../packages/agent-runtime/dist/sidecar.js"),
+ join(
+ getModuleDirectory(import.meta.url),
+ "../../../agent-runtime/dist/sidecar.js",
+ ),
+ join(
+ getModuleDirectory(import.meta.url),
+ "../../../../packages/agent-runtime/dist/sidecar.js",
+ ),
];
for (const c of candidates) {
if (c && existsSync(c)) return c;
}
- return join(__dirname, "../../../../packages/agent-runtime/dist/sidecar.js");
+ return join(
+ getModuleDirectory(import.meta.url),
+ "../../../../packages/agent-runtime/dist/sidecar.js",
+ );
}
function fallbackStderrLogger(text: string): void {
diff --git a/apps/desktop/electron/main/bootstrap/launcher.ts b/apps/desktop/electron/main/bootstrap/launcher.ts
index b2b423f0c..d44d8beec 100644
--- a/apps/desktop/electron/main/bootstrap/launcher.ts
+++ b/apps/desktop/electron/main/bootstrap/launcher.ts
@@ -1,5 +1,6 @@
import { app, BrowserWindow, globalShortcut, screen } from "electron";
import { join } from "node:path";
+import { getModuleDirectory } from "../module-path";
import {
APP_NAME,
IPC,
@@ -96,7 +97,7 @@ export function createLauncher({
autoHideMenuBar: true,
...(process.platform === "darwin" ? { type: "panel" as const } : {}),
webPreferences: {
- preload: join(__dirname, "../preload/index.cjs"),
+ preload: join(getModuleDirectory(import.meta.url), "../preload/index.cjs"),
contextIsolation: true,
nodeIntegration: false,
sandbox: true,
@@ -143,9 +144,10 @@ export function createLauncher({
url.searchParams.set("surface", "plugin-launcher");
await window.loadURL(url.toString());
} else {
- await window.loadFile(join(__dirname, "../renderer/index.html"), {
- query: { surface: "plugin-launcher" },
- });
+ await window.loadFile(
+ join(getModuleDirectory(import.meta.url), "../renderer/index.html"),
+ { query: { surface: "plugin-launcher" } },
+ );
}
return window;
} catch (error) {
diff --git a/apps/desktop/electron/main/bootstrap/window.ts b/apps/desktop/electron/main/bootstrap/window.ts
index d6664127c..74fef7e93 100644
--- a/apps/desktop/electron/main/bootstrap/window.ts
+++ b/apps/desktop/electron/main/bootstrap/window.ts
@@ -2,6 +2,7 @@ import { app, BrowserWindow, nativeTheme, screen, type Tray } from "electron";
import { execFileSync } from "node:child_process";
import { existsSync } from "node:fs";
import { join } from "node:path";
+import { getModuleDirectory } from "../module-path";
import {
APP_NAME,
builtinWindowBackground,
@@ -196,7 +197,7 @@ export async function createWindow({
}
: {}),
webPreferences: {
- preload: join(__dirname, "../preload/index.cjs"),
+ preload: join(getModuleDirectory(import.meta.url), "../preload/index.cjs"),
contextIsolation: true,
nodeIntegration: false,
sandbox: true,
@@ -2042,6 +2043,8 @@ export async function createWindow({
window.webContents.openDevTools({ mode: "detach" });
}
} else {
- await window.loadFile(join(__dirname, "../renderer/index.html"));
+ await window.loadFile(
+ join(getModuleDirectory(import.meta.url), "../renderer/index.html"),
+ );
}
}
diff --git a/apps/desktop/electron/main/builtin-skills.ts b/apps/desktop/electron/main/builtin-skills.ts
index f1687e745..636146358 100644
--- a/apps/desktop/electron/main/builtin-skills.ts
+++ b/apps/desktop/electron/main/builtin-skills.ts
@@ -3,6 +3,7 @@ import { join } from "node:path";
import { parseSkillFrontmatter } from "@pi-desktop/plugin-sdk";
import type { PluginSkillDef } from "@pi-desktop/agent-runtime";
import type { LoadedSkillDocument } from "./skill-document";
+import { getModuleDirectory } from "./module-path";
/**
* Skills PI-Desktop ships itself.
@@ -21,7 +22,7 @@ const IMAGE_GENERATION_SKILL_FILE = "image-generation.md";
/** electron-builder copies `resources/skills` to `<resources>/skills`. */
function resolveBuiltinSkillPath(fileName: string): string | null {
- const moduleDir = typeof __dirname === "string" ? __dirname : import.meta.dirname;
+ const moduleDir = getModuleDirectory(import.meta.url);
const candidates = [
join(process.resourcesPath || "", "skills", fileName),
join(moduleDir, "../../resources/skills", fileName),
diff --git a/apps/desktop/electron/main/host-process.ts b/apps/desktop/electron/main/host-process.ts
index 5b5a5f138..d2a5dc401 100644
--- a/apps/desktop/electron/main/host-process.ts
+++ b/apps/desktop/electron/main/host-process.ts
@@ -12,6 +12,7 @@ import {
} from "./linux-glibc";
import { DbSchemaTooNewError, parseSchemaTooNew } from "./host-boot-diagnostics";
import { redactValue } from "./logger";
+import { getModuleDirectory } from "./module-path";
export type {
HostNotificationHandler,
@@ -28,8 +29,14 @@ function resolveHostBinary(): string {
// packaged resources
join(process.resourcesPath || "", `bin/pi-desktop-host-core${exe}`),
// monorepo dev/build
- join(__dirname, `../../../../target/debug/pi-desktop-host-core${exe}`),
- join(__dirname, `../../../../target/release/pi-desktop-host-core${exe}`),
+ join(
+ getModuleDirectory(import.meta.url),
+ `../../../../target/debug/pi-desktop-host-core${exe}`,
+ ),
+ join(
+ getModuleDirectory(import.meta.url),
+ `../../../../target/release/pi-desktop-host-core${exe}`,
+ ),
];
for (const c of candidates) {
if (c && existsSync(c)) return c;
@@ -49,8 +56,8 @@ function resolveHostBinary(): string {
function resolveBuiltinPluginsDir(): string | null {
const candidates = [
join(process.resourcesPath || "", "plugins"),
- join(__dirname, "../../resources/plugins"),
- join(__dirname, "../../../resources/plugins"),
+ join(getModuleDirectory(import.meta.url), "../../resources/plugins"),
+ join(getModuleDirectory(import.meta.url), "../../../resources/plugins"),
];
for (const candidate of candidates) {
if (candidate && existsSync(candidate)) return candidate;
diff --git a/apps/desktop/electron/main/ipc/workspace-ipc.ts b/apps/desktop/electron/main/ipc/workspace-ipc.ts
index 3e5c4663b..19ca8c428 100644
--- a/apps/desktop/electron/main/ipc/workspace-ipc.ts
+++ b/apps/desktop/electron/main/ipc/workspace-ipc.ts
@@ -48,6 +48,7 @@ import type { AgentSidecar } from "../agent-sidecar";
import type { HostProcess } from "../host-process";
import type { Logger } from "../logger";
import type { ClipboardHistory } from "../clipboard-history";
+import { getModuleDirectory } from "../module-path";
import type { PluginRuntime } from "../plugin-runtime";
import type { IpcRegistrar } from "./types";
@@ -204,7 +205,9 @@ export function registerWorkspaceIpc({
const seed =
process.env.PI_DESKTOP_SEED_WORKSPACE ||
process.env.PI_DESKTOP_WORKSPACE ||
- (isDevelopmentBuild ? join(__dirname, "../../..") : "");
+ (isDevelopmentBuild
+ ? join(getModuleDirectory(import.meta.url), "../../..")
+ : "");
if (!res.workspace && seed) {
try {
res = (await host.call("workspace.set", { path: seed })) as {
diff --git a/apps/desktop/electron/main/live-voice/owner.ts b/apps/desktop/electron/main/live-voice/owner.ts
index 3079547be..bdeeee883 100644
--- a/apps/desktop/electron/main/live-voice/owner.ts
+++ b/apps/desktop/electron/main/live-voice/owner.ts
@@ -3,6 +3,7 @@ import { fileURLToPath } from "node:url";
import { resolve } from "node:path";
import type { WebContents } from "electron";
import type { LiveOwner } from "./call-service";
+import { getModuleDirectory } from "../module-path";
export function liveOwnerFromInvoke(event: IpcMainInvokeEvent, mainWindow: BrowserWindow | null): LiveOwner {
const frame = event.senderFrame;
@@ -52,7 +53,10 @@ export function isTrustedRendererUrl(value: string): boolean {
const url = new URL(value);
if (url.protocol === "file:") {
if (url.search || url.hash) return false;
- return resolve(fileURLToPath(url)) === resolve(__dirname, "../renderer/index.html");
+ return (
+ resolve(fileURLToPath(url)) ===
+ resolve(getModuleDirectory(import.meta.url), "../renderer/index.html")
+ );
}
if (url.protocol !== "http:") return false;
const configured = process.env.ELECTRON_RENDERER_URL;
diff --git a/apps/desktop/electron/main/module-path.ts b/apps/desktop/electron/main/module-path.ts
new file mode 100644
index 000000000..7313c05a7
--- /dev/null
+++ b/apps/desktop/electron/main/module-path.ts
@@ -0,0 +1,7 @@
+import { dirname } from "node:path";
+import { fileURLToPath } from "node:url";
+
+/** Resolve the filesystem directory for the current ES module URL. */
+export function getModuleDirectory(moduleUrl: string): string {
+ return dirname(fileURLToPath(moduleUrl));
+}
diff --git a/apps/desktop/electron/main/plugin-panel-host.ts b/apps/desktop/electron/main/plugin-panel-host.ts
index 1a139e07e..7a8f45bde 100644
--- a/apps/desktop/electron/main/plugin-panel-host.ts
+++ b/apps/desktop/electron/main/plugin-panel-host.ts
@@ -8,6 +8,7 @@ import {
} from "@pi-desktop/plugin-sdk";
import { builtinWindowBackground } from "@pi-desktop/shared";
import { suppressLinuxFramelessSystemMenu } from "./frameless-system-menu";
+import { getModuleDirectory } from "./module-path";
import { PanelSenders, pageGoneWithin, resolvePanelInvocation } from "./plugin-panel-senders";
import { PanelOperationSerializer } from "./plugin-panel-senders";
import {
@@ -496,7 +497,10 @@ export class PluginPanelHost {
...(widget ? { fullscreenable: false } : {}),
webPreferences: {
session: ses,
- preload: join(__dirname, "../preload/plugin-panel.js"),
+ preload: join(
+ getModuleDirectory(import.meta.url),
+ "../preload/plugin-panel.js",
+ ),
contextIsolation: true,
nodeIntegration: false,
sandbox: true,
diff --git a/apps/desktop/electron/main/plugin-runtime.ts b/apps/desktop/electron/main/plugin-runtime.ts
index 7417010e8..e2a2a39cf 100644
--- a/apps/desktop/electron/main/plugin-runtime.ts
+++ b/apps/desktop/electron/main/plugin-runtime.ts
@@ -13,6 +13,7 @@ import { open as openFile } from "node:fs/promises";
import { randomUUID } from "node:crypto";
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
import type { LoadedSkillDocument } from "./skill-document";
+import { getModuleDirectory } from "./module-path";
import {
busTopicAllowed,
isDeniedFsPath,
@@ -1782,7 +1783,9 @@ export class PluginRuntime {
),
);
- const entry = this.services.hostEntry ?? join(__dirname, "plugin-host-process.js");
+ const entry =
+ this.services.hostEntry ??
+ join(getModuleDirectory(import.meta.url), "plugin-host-process.js");
const spawn = this.services.spawnProcess ?? spawnUtilityProcess;
const child = await spawn({ pluginId: manifest.id, entry, pluginPath });
diff --git a/apps/desktop/electron/main/plugin-view-host.ts b/apps/desktop/electron/main/plugin-view-host.ts
index b55f79173..9375cd97f 100644
--- a/apps/desktop/electron/main/plugin-view-host.ts
+++ b/apps/desktop/electron/main/plugin-view-host.ts
@@ -1,5 +1,6 @@
import { session, shell, WebContentsView, type BrowserWindow } from "electron";
import { join } from "node:path";
+import { getModuleDirectory } from "./module-path";
import { parseAllowedExternalUrl } from "./safe-open-external";
import { PanelSenders, pageGoneWithin } from "./plugin-panel-senders";
import {
@@ -423,7 +424,10 @@ export class PluginViewHost {
const view = new WebContentsView({
webPreferences: {
session: ses,
- preload: join(__dirname, "../preload/plugin-panel.js"),
+ preload: join(
+ getModuleDirectory(import.meta.url),
+ "../preload/plugin-panel.js",
+ ),
contextIsolation: true,
nodeIntegration: false,
sandbox: true,
diff --git a/apps/desktop/test/development-branding.test.mjs b/apps/desktop/test/development-branding.test.mjs
index 8b3432822..ceafc25f3 100644
--- a/apps/desktop/test/development-branding.test.mjs
+++ b/apps/desktop/test/development-branding.test.mjs
@@ -126,15 +126,29 @@ test("macOS development launches from a branded host bundle", () => {
assert.match(devScriptSource, /CFBundleName", APP_NAME/);
assert.match(devScriptSource, /CFBundleExecutable", APP_NAME/);
assert.match(devScriptSource, /CFBundleIconFile", "icon\.icns"/);
+ assert.match(devScriptSource, /BRANDING_SCHEMA = "v4"/);
assert.match(
devScriptSource,
/copyFileSync\(iconPath, join\(resources, "icon\.icns"\)\)/,
);
+ assert.match(
+ devScriptSource,
+ /copyFileSync\(trayIconPath, join\(resources, "tray-icon\.png"\)\)/,
+ );
+ assert.match(
+ devScriptSource,
+ /copyFileSync\(trayIconMacPath, join\(resources, "tray-icon-mac\.png"\)\)/,
+ );
assert.match(devScriptSource, /verbatimSymlinks: true/);
assert.match(devScriptSource, /join\(ROOT, "\.cache", "electron-dev"\)/);
assert.doesNotMatch(devScriptSource, /node_modules.*Info\.plist/);
});
+test("Electron main resolves runtime paths from ES module URLs", () => {
+ assert.match(mainSource, /function getModuleDirectory\(moduleUrl: string\)/);
+ assert.doesNotMatch(mainSource, /\b__dirname\b/);
+});
+
test(
"development launcher can be imported without starting Electron",
async () => {
@@ -154,6 +168,8 @@ test(
const resources = join(contents, "Resources");
const executable = join(macos, "Electron");
const iconPath = join(root, "source.icns");
+ const trayIconPath = join(root, "tray-icon.png");
+ const trayIconMacPath = join(root, "tray-icon-mac.png");
const cacheRoot = join(root, "cache");
try {
@@ -161,6 +177,8 @@ test(
await mkdir(resources, { recursive: true });
await writeFile(executable, "electron-host");
await writeFile(iconPath, "canonical-icon");
+ await writeFile(trayIconPath, "generic-tray-icon");
+ await writeFile(trayIconMacPath, "macOS-tray-icon");
await writeFile(
join(contents, "Info.plist"),
`<?xml version="1.0" encoding="UTF-8"?>
@@ -179,6 +197,8 @@ test(
electronExecutable: executable,
electronVersion: "test-version",
iconPath,
+ trayIconPath,
+ trayIconMacPath,
cacheRoot,
sign: false,
};
@@ -195,9 +215,32 @@ test(
await readFile(join(brandedContents, "Resources", "icon.icns"), "utf8"),
"canonical-icon",
);
+ assert.equal(
+ await readFile(join(brandedContents, "Resources", "tray-icon.png"), "utf8"),
+ "generic-tray-icon",
+ );
+ assert.equal(
+ await readFile(
+ join(brandedContents, "Resources", "tray-icon-mac.png"),
+ "utf8",
+ ),
+ "macOS-tray-icon",
+ );
assert.match(plist, /<string>PI-Desktop<\/string>/);
assert.match(plist, /<string>net\.aiuo\.pi-desktop\.dev<\/string>/);
assert.equal(prepareMacDevelopmentBundle(options), brandedExecutable);
+
+ await writeFile(trayIconMacPath, "updated-macOS-tray-icon");
+ const updatedExecutable = prepareMacDevelopmentBundle(options);
+ assert.notEqual(updatedExecutable, brandedExecutable);
+ const updatedContents = join(updatedExecutable, "..", "..");
+ assert.equal(
+ await readFile(
+ join(updatedContents, "Resources", "tray-icon-mac.png"),
+ "utf8",
+ ),
+ "updated-macOS-tray-icon",
+ );
} finally {
await rm(root, { recursive: true, force: true });
}
diff --git a/apps/desktop/test/image-generation.test.mjs b/apps/desktop/test/image-generation.test.mjs
index 66e2d3acd..251d16d3b 100644
--- a/apps/desktop/test/image-generation.test.mjs
+++ b/apps/desktop/test/image-generation.test.mjs
@@ -4,7 +4,6 @@ import { createServer } from "node:http";
import { register } from "node:module";
import { tmpdir } from "node:os";
import { join } from "node:path";
-import { fileURLToPath } from "node:url";
import test from "node:test";
register(new URL("./helpers/ts-import-hooks.mjs", import.meta.url));
const { createImageGenerationTool } = await import(
@@ -106,21 +105,15 @@ test("edit inputs reject outside paths, traversal and non-image files", async (t
});
test("the default imagegen skill is discoverable and loads in an ordinary session", async () => {
- const previous = globalThis.__dirname;
- globalThis.__dirname = fileURLToPath(new URL("../electron/main/", import.meta.url));
- try {
- const { builtinSkills, loadBuiltinSkillBody } = await import(
- "../electron/main/builtin-skills.ts"
- );
- const skills = builtinSkills({});
- assert.equal(skills.find((skill) => skill.id === "pi-desktop/imagegen")?.name, "imagegen");
- assert.ok(!skills.some((skill) => skill.id === "pi-desktop/plugin-development"));
- const body = loadBuiltinSkillBody("pi-desktop/imagegen").body;
- assert.match(body, /GenerateImages/);
- assert.match(body, /previous result path/);
- assert.match(body, /Do not retry/);
- assert.equal(loadBuiltinSkillBody("../../outside"), null);
- } finally {
- globalThis.__dirname = previous;
- }
+ const { builtinSkills, loadBuiltinSkillBody } = await import(
+ "../electron/main/builtin-skills.ts"
+ );
+ const skills = builtinSkills({});
+ assert.equal(skills.find((skill) => skill.id === "pi-desktop/imagegen")?.name, "imagegen");
+ assert.ok(!skills.some((skill) => skill.id === "pi-desktop/plugin-development"));
+ const body = loadBuiltinSkillBody("pi-desktop/imagegen").body;
+ assert.match(body, /GenerateImages/);
+ assert.match(body, /previous result path/);
+ assert.match(body, /Do not retry/);
+ assert.equal(loadBuiltinSkillBody("../../outside"), null);
});
diff --git a/apps/desktop/test/plugin-work-panel-views.test.mjs b/apps/desktop/test/plugin-work-panel-views.test.mjs
index 70beab856..5644904d7 100644
--- a/apps/desktop/test/plugin-work-panel-views.test.mjs
+++ b/apps/desktop/test/plugin-work-panel-views.test.mjs
@@ -170,7 +170,10 @@ test("a docked view is as isolated as a detached panel window", () => {
assert.match(viewHostSource, /contextIsolation: true/);
assert.match(viewHostSource, /nodeIntegration: false/);
assert.match(viewHostSource, /webviewTag: false/);
- assert.match(viewHostSource, /preload: join\(__dirname, "\.\.\/preload\/plugin-panel\.js"\)/);
+ assert.match(
+ viewHostSource,
+ /preload: join\(\s*getModuleDirectory\(import\.meta\.url\),\s*"\.\.\/preload\/plugin-panel\.js",?\s*\)/,
+ );
// `window.open` would mint a chromeless window outside that policy.
assert.match(viewHostSource, /setWindowOpenHandler\(\(\{ url \}\) =>/);
assert.match(viewHostSource, /action: "deny"/);
diff --git a/docs/spec/03-runtime/07-process-model.md b/docs/spec/03-runtime/07-process-model.md
index e1117741b..972eca48b 100644
--- a/docs/spec/03-runtime/07-process-model.md
+++ b/docs/spec/03-runtime/07-process-model.md
@@ -290,6 +290,9 @@ the next launch rather than changing the NSIS installer or writing into
`scripts/dev-electron.mjs` resolves the development host through the
`electron` package entry, which downloads and extracts the binary on demand
at first dev boot
+- On macOS, `scripts/dev-electron.mjs` copies both tray icon assets into the
+ branded bundle's `Contents/Resources`, matching Electron's packaged resource
+ lookup used by the development process.
### Release
- package Electron app
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 8a6b02327..82f4403a1 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -755,14 +755,17 @@ identify the platform validation still needed.
development lane, workspace package build outputs are absent or older than
their TypeScript sources.
- **Steps**: 1) Launch PI-Desktop. In the development lane, use `pnpm dev`.
- 2) Observe main window appears.
+ 2) Observe main window appears. In the macOS development lane, confirm the
+ menu-bar tray icon appears.
- **Expected**: Development launch rebuilds all workspace dependencies before
host-core and Electron startup. Window first shows the branded startup splash
while bootstrap runs, then reveals the main shell in English with the current
locale catalog; no compile error, missing-menu runtime error, or crash;
- version info visible. Key lifecycle and error records are written to the
- categorized logs. GitHub auto-update is not started until after `ensureWindow`, and a hung
- feed cannot keep updater status on `checking` for Chromium's ~60s timeout.
+ version info visible. The macOS development bundle contains both tray icon
+ resources, and the tray starts without a missing-icon warning. Key lifecycle
+ and error records are written to the categorized logs. GitHub auto-update is
+ not started until after `ensureWindow`, and a hung feed cannot keep updater
+ status on `checking` for Chromium's ~60s timeout.
- **Specs linked**: `03-runtime/07-process-model.md`, `04-ux/01-ui-ia.md`,
`03-runtime/09-logging-and-observability.md`
- **Acceptance**: A (app startup)
diff --git a/scripts/dev-electron.mjs b/scripts/dev-electron.mjs
index 60c665ef0..b6272f6fb 100644
--- a/scripts/dev-electron.mjs
+++ b/scripts/dev-electron.mjs
@@ -18,7 +18,7 @@ import { fileURLToPath } from "node:url";
const APP_NAME = "PI-Desktop";
const DEV_BUNDLE_ID = "net.aiuo.pi-desktop.dev";
-const BRANDING_SCHEMA = "v3";
+const BRANDING_SCHEMA = "v4";
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const DESKTOP_ROOT = join(ROOT, "apps", "desktop");
@@ -46,15 +46,25 @@ export function prepareMacDevelopmentBundle({
electronExecutable,
electronVersion,
iconPath,
+ trayIconPath,
+ trayIconMacPath,
cacheRoot,
sign = true,
}) {
const sourceBundle = dirname(dirname(dirname(electronExecutable)));
- const iconHash = createHash("sha256")
- .update(readFileSync(iconPath))
- .digest("hex")
- .slice(0, 12);
- const cacheKey = `${electronVersion}-${iconHash}-${BRANDING_SCHEMA}`;
+ const brandingHash = createHash("sha256");
+ for (const [name, path] of [
+ ["application icon", iconPath],
+ ["tray icon", trayIconPath],
+ ["macOS tray icon", trayIconMacPath],
+ ]) {
+ if (!existsSync(path)) {
+ throw new Error(`Development bundle ${name} is missing: ${path}`);
+ }
+ brandingHash.update(name).update("\0").update(readFileSync(path));
+ }
+ const brandingHashPrefix = brandingHash.digest("hex").slice(0, 12);
+ const cacheKey = `${electronVersion}-${brandingHashPrefix}-${BRANDING_SCHEMA}`;
const targetRoot = join(cacheRoot, cacheKey);
const targetBundle = join(targetRoot, `${APP_NAME}.app`);
const targetExecutable = join(
@@ -64,10 +74,19 @@ export function prepareMacDevelopmentBundle({
APP_NAME,
);
const markerPath = join(targetRoot, "ready.json");
-
- if (existsSync(markerPath) && existsSync(targetExecutable)) {
+ const targetResources = join(targetBundle, "Contents", "Resources");
+ const targetTrayIcon = join(targetResources, "tray-icon.png");
+ const targetTrayIconMac = join(targetResources, "tray-icon-mac.png");
+
+ if (
+ existsSync(markerPath) &&
+ existsSync(targetExecutable) &&
+ existsSync(targetTrayIcon) &&
+ existsSync(targetTrayIconMac)
+ ) {
return targetExecutable;
}
+ if (existsSync(targetRoot)) rmSync(targetRoot, { recursive: true, force: true });
mkdirSync(cacheRoot, { recursive: true });
const stagingRoot = join(cacheRoot, `${cacheKey}.staging-${process.pid}`);
@@ -87,6 +106,8 @@ export function prepareMacDevelopmentBundle({
const brandedExecutable = join(macos, APP_NAME);
renameSync(sourceExecutable, brandedExecutable);
copyFileSync(iconPath, join(resources, "icon.icns"));
+ copyFileSync(trayIconPath, join(resources, "tray-icon.png"));
+ copyFileSync(trayIconMacPath, join(resources, "tray-icon-mac.png"));
const plistPath = join(contents, "Info.plist");
setPlistString(plistPath, "CFBundleDisplayName", APP_NAME);
@@ -112,7 +133,7 @@ export function prepareMacDevelopmentBundle({
writeFileSync(
join(stagingRoot, "ready.json"),
- `${JSON.stringify({ electronVersion, iconHash })}\n`,
+ `${JSON.stringify({ electronVersion, brandingHash: brandingHashPrefix })}\n`,
);
renameSync(stagingRoot, targetRoot);
return targetExecutable;
@@ -120,7 +141,9 @@ export function prepareMacDevelopmentBundle({
const cacheWonRace =
(error?.code === "EEXIST" || error?.code === "ENOTEMPTY") &&
existsSync(markerPath) &&
- existsSync(targetExecutable);
+ existsSync(targetExecutable) &&
+ existsSync(targetTrayIcon) &&
+ existsSync(targetTrayIconMac);
rmSync(stagingRoot, { recursive: true, force: true });
if (cacheWonRace) return targetExecutable;
throw error;
@@ -137,6 +160,8 @@ function run() {
electronExecutable: electron.executablePath,
electronVersion: electron.version,
iconPath: join(DESKTOP_ROOT, "build", "icon.icns"),
+ trayIconPath: join(DESKTOP_ROOT, "build", "icon.png"),
+ trayIconMacPath: join(DESKTOP_ROOT, "build", "tray-icon-mac.png"),
cacheRoot: join(ROOT, ".cache", "electron-dev"),
});
}