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): sign the share extension before macOS notarization

tianma-if3e95eb31b1d0
diff --git a/apps/desktop/electron-builder.yml b/apps/desktop/electron-builder.yml
index 6db32c3c..41206036 100644
--- a/apps/desktop/electron-builder.yml
+++ b/apps/desktop/electron-builder.yml
@@ -50,13 +50,12 @@ extraResources:
filter:
- edgeever-sidecar
- edgeever-sidecar.exe
-# Top-level hook. electron-builder rejects afterSign under mac, and the
-# script itself returns immediately on Windows and Linux.
-afterSign: ./scripts/sign-share-extension.cjs
mac:
category: public.app-category.productivity
icon: assets/icon.icns
minimumSystemVersion: "13.0"
+ # PlugIns are skipped by the default signer, and afterSign runs too late to notarize.
+ sign: ./scripts/sign-share-extension.cjs
extraFiles:
- from: share-extension/dist/EdgeEverShare.appex
to: PlugIns/EdgeEverShare.appex
diff --git a/apps/desktop/scripts/sign-share-extension.cjs b/apps/desktop/scripts/sign-share-extension.cjs
index 5218fc34..b22f11b9 100644
--- a/apps/desktop/scripts/sign-share-extension.cjs
+++ b/apps/desktop/scripts/sign-share-extension.cjs
@@ -1,37 +1,52 @@
const { spawnSync } = require("node:child_process");
const { existsSync } = require("node:fs");
+const { createRequire } = require("node:module");
const { join } = require("node:path");
-const signingIdentity = (appPath) => {
- const result = spawnSync("codesign", ["-dvv", appPath], { encoding: "utf8" });
- const details = `${result.stdout || ""}\n${result.stderr || ""}`;
- const authority = details.match(/^Authority=(.*)$/m)?.[1]?.trim();
- if (!authority || authority === "-" || authority.startsWith("Signature=")) return "-";
- return authority;
-};
+const builderRequire = createRequire(require.resolve("electron-builder/package.json"));
+const { sign } = builderRequire("@electron/osx-sign");
-const codesign = (identity, args) => {
- const command = ["--force", "--sign", identity, "--generate-entitlement-der"];
- if (process.env.CSC_KEYCHAIN) command.push("--keychain", process.env.CSC_KEYCHAIN);
- if (identity !== "-") command.push("--timestamp");
- command.push(...args);
- const result = spawnSync("codesign", command, { encoding: "utf8" });
+const codesign = (args) => {
+ const result = spawnSync("codesign", args, { encoding: "utf8" });
if (result.status !== 0) {
throw new Error(result.stderr || result.stdout || "codesign failed");
}
};
-// electron-builder signs nested code with the Electron helper entitlements.
-// The share extension has to keep its own sandbox entitlements instead.
-module.exports = async function signShareExtension(context) {
- if (context.electronPlatformName !== "darwin") return;
- const appPath = join(context.appOutDir, `${context.packager.appInfo.productFilename}.app`);
- const appexPath = join(appPath, "Contents", "PlugIns", "EdgeEverShare.appex");
+const signingIdentity = (identity) => {
+ if (typeof identity === "string" && identity) return identity;
+ if (identity && typeof identity === "object") return identity.hash || identity.name || "";
+ return "";
+};
+
+// electron-builder skips Contents/PlugIns, and it notarizes before afterSign.
+// This replaces mac.sign so the share extension is Developer ID signed, timestamped,
+// and hardened before notarization. The outer app is sealed again afterwards.
+module.exports = async function signMacApp(opts) {
+ await sign(opts);
+ const appexPath = join(opts.app, "Contents", "PlugIns", "EdgeEverShare.appex");
if (!existsSync(appexPath)) {
throw new Error(`macOS share extension is missing from the app bundle: ${appexPath}`);
}
- const identity = signingIdentity(appPath);
+ const identity = signingIdentity(opts.identity);
+ if (!identity) {
+ throw new Error("macOS share extension cannot be signed without a Developer ID identity");
+ }
const entitlements = join(__dirname, "..", "share-extension", "EdgeEverShare.entitlements");
- codesign(identity, ["--entitlements", entitlements, appexPath]);
- codesign(identity, ["--preserve-metadata=entitlements,requirements,flags,runtime", appPath]);
+ const shared = ["--force", "--sign", identity, "--timestamp"];
+ if (opts.keychain) shared.push("--keychain", opts.keychain);
+ codesign([
+ ...shared,
+ "--options",
+ "runtime",
+ "--generate-entitlement-der",
+ "--entitlements",
+ entitlements,
+ appexPath,
+ ]);
+ codesign([
+ ...shared,
+ "--preserve-metadata=entitlements,requirements,flags,runtime",
+ opts.app,
+ ]);
};
diff --git a/scripts/desktop-build-workflow.test.mjs b/scripts/desktop-build-workflow.test.mjs
index 57d8a8e7..fe930b74 100644
--- a/scripts/desktop-build-workflow.test.mjs
+++ b/scripts/desktop-build-workflow.test.mjs
@@ -29,7 +29,12 @@ describe("desktop release workflow", () => {
expect(desktopBuilderConfig).toContain("schemes:\n - edgeever");
expect(desktopBuilderConfig).not.toContain("edgeever-app");
expect(desktopBuilderConfig).toContain("PlugIns/EdgeEverShare.appex");
- expect(desktopBuilderConfig).toContain("afterSign: ./scripts/sign-share-extension.cjs");
+ expect(desktopBuilderConfig).toContain("sign: ./scripts/sign-share-extension.cjs");
+ expect(desktopBuilderConfig).not.toContain("afterSign:");
+ const shareSigner = readFileSync(new URL("../apps/desktop/scripts/sign-share-extension.cjs", import.meta.url), "utf8");
+ expect(shareSigner).toContain("await sign(opts)");
+ expect(shareSigner).toContain('"runtime"');
+ expect(shareSigner).toContain('"--timestamp"');
});
test("gates Draft release assets on the full project suite in Ubuntu", () => {