Skip to content

Commit

Permalink
Added ad-hoc code signing on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschwendener committed Jul 8, 2024
1 parent 15f95f7 commit c1dad65
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 20 deletions.
36 changes: 36 additions & 0 deletions build/macos/codeSign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { execSync } = require("child_process");
const { existsSync } = require("fs");
const { join } = require("path");

/**
* @param {import("electron-builder").AfterPackContext} context
* @returns void
*/
const codeSign = (context) => {
const { appOutDir, packager } = context;

const appName = packager.appInfo.productFilename;
const appPath = join(appOutDir, `${appName}.app`);

if (!existsSync(appPath)) {
throw new Error(`App not found at path: ${appPath}`);
}

console.log("Performing ad-hoc signing...");

try {
// Remove existing signature if any
execSync(`codesign --remove-signature "${appPath}"`, { stdio: "inherit" });

// Perform ad-hoc signing
execSync(`codesign --force --deep -s - "${appPath}"`, { stdio: "inherit" });

console.log("Ad-hoc signing completed successfully");
} catch (error) {
console.error("Error during ad-hoc signing:", error.message);
throw error;
}
};

module.exports = codeSign;
58 changes: 38 additions & 20 deletions electron-builder.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @type {import('electron-builder').Configuration}
* @see https://www.electron.build/configuration/configuration
*/
module.exports = {
const baseConfig = {
asar: true,
asarUnpack: ["**/node_modules/sharp/**/*", "**/node_modules/@img/**/*"],
productName: "Ueli",
Expand All @@ -14,27 +14,45 @@ module.exports = {
extraMetadata: {
version: process.env.VITE_APP_VERSION,
},
mac: {
category: "public.app-category.utilities",
icon: "assets/Build/app-icon-dark.png",
target: [{ target: "dmg" }, { target: "zip" }],
},
win: {
icon: "assets/Build/app-icon-dark-transparent.png",
target: [{ target: "msi" }, { target: "nsis" }, { target: "zip" }, { target: "appx" }],
};

/**
* @type {Record<NodeJS.Platform, import('electron-builder').Configuration>}
*/
const platformSpecificConfig = {
darwin: {
...baseConfig,
afterPack: "./build/macos/codeSign.js",
mac: {
category: "public.app-category.utilities",
icon: "assets/Build/app-icon-dark.png",
target: [{ target: "dmg" }, { target: "zip" }],
},
},
appx: {
applicationId: "OliverSchwendener.Ueli",
backgroundColor: "#1F1F1F",
displayName: "Ueli",
identityName: "1915OliverSchwendener.Ueli",
publisher: "CN=AD6BF16D-50E3-4FD4-B769-78A606AFF75E",
publisherDisplayName: "Oliver Schwendener",
languages: ["en-US", "de-CH"],
win32: {
...baseConfig,
appx: {
applicationId: "OliverSchwendener.Ueli",
backgroundColor: "#1F1F1F",
displayName: "Ueli",
identityName: "1915OliverSchwendener.Ueli",
publisher: "CN=AD6BF16D-50E3-4FD4-B769-78A606AFF75E",
publisherDisplayName: "Oliver Schwendener",
languages: ["en-US", "de-CH"],
},
win: {
icon: "assets/Build/app-icon-dark-transparent.png",
target: [{ target: "msi" }, { target: "nsis" }, { target: "zip" }, { target: "appx" }],
},
},
linux: {
icon: "assets/Build/app-icon-dark.png",
category: "Utility",
target: [{ target: "AppImage" }, { target: "deb" }, { target: "zip" }],
...baseConfig,
linux: {
icon: "assets/Build/app-icon-dark.png",
category: "Utility",
target: [{ target: "AppImage" }, { target: "deb" }, { target: "zip" }],
},
},
};

module.exports = platformSpecificConfig[process.platform];

0 comments on commit c1dad65

Please sign in to comment.