Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(desktop): keep macOS background Node processes out of Dock

tianma-if7eb29159f3c0
diff --git a/apps/desktop/src/main/background-node.mjs b/apps/desktop/src/main/background-node.mjs
new file mode 100644
index 00000000..5b1372e2
--- /dev/null
+++ b/apps/desktop/src/main/background-node.mjs
@@ -0,0 +1,19 @@
+import { accessSync, constants } from "node:fs";
+import path from "node:path";
+
+// Running the main macOS app executable as Node can register a foreground
+// application with Launch Services. Electron's existing Helper bundle has
+// LSUIElement=true and provides the same Node runtime without a Dock entry.
+export function backgroundNodeExecutable(executablePath, platform = process.platform) {
+ if (platform !== "darwin") return executablePath;
+ const macos = path.dirname(executablePath);
+ const contents = path.dirname(macos);
+ if (path.basename(macos) !== "MacOS" || path.basename(contents) !== "Contents"
+ || !path.dirname(contents).endsWith(".app")) return executablePath;
+ const helperName = `${path.basename(executablePath)} Helper`;
+ const helper = path.join(contents, "Frameworks", `${helperName}.app`, "Contents", "MacOS", helperName);
+ // A malformed app bundle must fail visibly instead of silently bringing
+ // foreground processes back. Plain Node executables above stay supported.
+ accessSync(helper, constants.X_OK);
+ return helper;
+}
diff --git a/apps/desktop/src/main/background-node.test.mjs b/apps/desktop/src/main/background-node.test.mjs
new file mode 100644
index 00000000..06ea4b95
--- /dev/null
+++ b/apps/desktop/src/main/background-node.test.mjs
@@ -0,0 +1,50 @@
+import { test, expect } from "bun:test";
+import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import path from "node:path";
+import { createRequire } from "node:module";
+import { execFileSync, spawn } from "node:child_process";
+import { once } from "node:events";
+import { backgroundNodeExecutable } from "./background-node.mjs";
+
+test("keeps Windows, Linux and standalone Node runtimes unchanged", () => {
+ for (const [executable, platform] of [["C:\\EdgeEver\\EdgeEver.exe", "win32"], ["/opt/EdgeEver/edgeever", "linux"], ["/usr/bin/node", "darwin"]]) {
+ expect(backgroundNodeExecutable(executable, platform)).toBe(executable);
+ }
+});
+
+test("selects the bundled background Helper and rejects a broken app bundle", async () => {
+ const root = await mkdtemp(path.join(tmpdir(), "edgeever-background-node-"));
+ const executable = path.join(root, "Edge Ever.app/Contents/MacOS/Edge Ever");
+ const helper = path.join(root, "Edge Ever.app/Contents/Frameworks/Edge Ever Helper.app/Contents/MacOS/Edge Ever Helper");
+ try {
+ expect(() => backgroundNodeExecutable(executable, "darwin")).toThrow();
+ await mkdir(path.dirname(helper), { recursive: true });
+ await writeFile(helper, "#!/bin/sh\n", { mode: 0o755 });
+ expect(backgroundNodeExecutable(executable, "darwin")).toBe(helper);
+ } finally { await rm(root, { recursive: true, force: true }); }
+});
+
+test.skipIf(process.platform !== "darwin")("real Electron Helper runs npm and stays out of Dock", async () => {
+ const require = createRequire(import.meta.url);
+ const helper = backgroundNodeExecutable(require("electron"));
+ const npm = path.join(path.dirname(require.resolve("npm")), "bin/npm-cli.js");
+ const root = await mkdtemp(path.join(tmpdir(), "edgeever-background-npm-"));
+ let child;
+ try {
+ const fixture = path.join(root, "fixture");
+ await mkdir(fixture);
+ await writeFile(path.join(fixture, "package.json"), JSON.stringify({ name: "edgeever-background-fixture", version: "1.0.0" }));
+ const env = { ...process.env, ELECTRON_RUN_AS_NODE: "1" };
+ execFileSync(helper, [npm, "install", "--prefix", path.join(root, "installed"), "--offline", "--ignore-scripts", "--no-audit", "--no-fund", fixture], { env, timeout: 30_000, stdio: "pipe" });
+ child = spawn(helper, ["-e", "process.title = 'edgeever-background-fixture'; console.log('ready'); setInterval(() => {}, 1000)"], { env, stdio: ["ignore", "pipe", "pipe"] });
+ await once(child.stdout, "data");
+ // Query only this test process; never enumerate app names or command lines.
+ const policy = execFileSync("/usr/bin/osascript", ["-l", "JavaScript", "-e", `ObjC.import('AppKit'); var app = $.NSRunningApplication.runningApplicationWithProcessIdentifier(${child.pid}); app.isNil() ? -1 : Number(app.activationPolicy);`], { encoding: "utf8", timeout: 5_000 }).trim();
+ expect(["-1", "1", "2"]).toContain(policy);
+ expect(child.exitCode).toBeNull();
+ } finally {
+ if (child && child.exitCode === null) { child.kill(); await once(child, "exit"); }
+ await rm(root, { recursive: true, force: true });
+ }
+}, 40_000);
diff --git a/apps/desktop/src/main/index.mjs b/apps/desktop/src/main/index.mjs
index 1120d088..4f4a41e4 100644
--- a/apps/desktop/src/main/index.mjs
+++ b/apps/desktop/src/main/index.mjs
@@ -4,6 +4,7 @@ import { appendFile, mkdir, open, readdir, readFile, rename, rm, stat, unlink, w
import { basename, join } from "node:path";
import { Readable } from "node:stream";
import { execFile, spawn } from "node:child_process";
+import { backgroundNodeExecutable } from "./background-node.mjs";
import { fileURLToPath, pathToFileURL } from "node:url";
import { release as operatingSystemRelease } from "node:os";
import { BackupManager } from "./backup-manager.mjs";
@@ -2025,6 +2026,8 @@ const startApplication = async () => {
if (event.sender === mainWindow?.webContents && event.senderFrame === event.sender.mainFrame && typeof requestId === "string") aiDirect.cancel(requestId);
});
const acpRuntime = registerAcpIpc(ipcMain, createAcpHostRuntime({
+ executablePath: backgroundNodeExecutable(process.execPath),
+ mcpExecutablePath: backgroundNodeExecutable(process.execPath),
adapterStore: join(app.getPath("userData"), "acp-adapters"),
adapterFetchImpl: (url, init) => net.fetch(url, { ...init, credentials: "omit" }),
onUpdateDiagnostic: (details) => { void writeDiagnostic("acp.adapter-update-failed", details); },
diff --git a/scripts/verify-desktop-production-runtime.cjs b/scripts/verify-desktop-production-runtime.cjs
index 7ab2806b..25b05b4c 100644
--- a/scripts/verify-desktop-production-runtime.cjs
+++ b/scripts/verify-desktop-production-runtime.cjs
@@ -28,6 +28,8 @@ async function main() {
}
const manager = await import(pathToFileURL(join(archive, "src/main/acp-adapter-manager.mjs")).href);
assert.equal(typeof manager.createAcpAdapterManager, "function");
+ const { backgroundNodeExecutable } = await import(pathToFileURL(join(archive, "src/main/background-node.mjs")).href);
+ const nodeExecutable = backgroundNodeExecutable(process.execPath);
const npmCli = join(dirname(resolveDependency("npm")), "bin/npm-cli.js");
const npmRequire = createRequire(npmCli);
@@ -41,7 +43,7 @@ async function main() {
writeFileSync(join(fixture, "package.json"), JSON.stringify({ name: "edgeever-packaging-fixture", version, main: "index.js" }));
const tarball = join(root, `fixture-${version}.tgz`);
await tar.c({ gzip: true, cwd: join(root, "fixture"), file: tarball }, ["package"]);
- execFileSync(process.execPath, [npmCli, "install", "--prefix", join(root, "installed"),
+ execFileSync(nodeExecutable, [npmCli, "install", "--prefix", join(root, "installed"),
"--cache", join(root, "cache"), "--offline", "--ignore-scripts", "--no-audit", "--no-fund",
"--package-lock=false", tarball], {
cwd: root,