From 8b1cebca3cc2e076c1bb95687938cfbecad4334b Mon Sep 17 00:00:00 2001 From: Ben Standefer Date: Tue, 3 Mar 2020 01:42:34 -0800 Subject: [PATCH] feat: allow customization of bundleIdentifier for the new Electron 6+ renderer processes (#4692) * Allow Electron 6+ Renderer helper bundle ID to be specified This is still a WIP, but this worked with my app when setting these values in the "mac" section: "helperBundleId": "io.hypertools.Command-E.helperBase", "helperRendererBundleId": "io.hypertools.Command-E.helper", There's still a bit of nastiness in that with this configuration the other helpers (GPU, Plugin) get unnecessarily weird bundle IDs such as io.hypertools.Command-E.helperBase, but I can clean up how these are generated so it's more consistent. Maybe with Electron 6 it makes more sense to allow users to specific `helperBundleIdBase`, which in my case would be set to "io.hypertools.Command-E.helper" and allow helpers with no override to have a sane, consistent base instead of piggybacking on helperBundleId. Let me know what you think. I did confirm that macOS permission pop up key on the Bundle Identifier, not on name or anything else. * Update comments, formatting to be consistent with project * Keep project formatting consistent * Fix typo * Formatting * Fix typo with relevant Electron versions * Remove change to test file * Update snapshot size properties I based these updates on the expected output on this failing test: https://app.circleci.com/jobs/github/electron-userland/electron-builder/2854 I presume my change affects some of the snapshots. Apologies if this is not a kosher way to address the problem, I'm not well-versed in how testing of electron-builder works. * Update snapshot with new type error (added properties) Close #4691 --- packages/app-builder-lib/scheme.json | 40 +++++++++++++++++++ .../src/electron/electronMac.ts | 35 ++++++++++++---- .../app-builder-lib/src/options/macOptions.ts | 30 ++++++++++++++ .../mac/__snapshots__/macArchiveTest.js.snap | 2 +- 4 files changed, 98 insertions(+), 9 deletions(-) diff --git a/packages/app-builder-lib/scheme.json b/packages/app-builder-lib/scheme.json index 4176df2b45a..9c53d39cba9 100644 --- a/packages/app-builder-lib/scheme.json +++ b/packages/app-builder-lib/scheme.json @@ -2112,6 +2112,46 @@ "string" ] }, + "helperRendererBundleId": { + "default": "${appBundleIdentifier}.helper.Renderer", + "description": "The bundle identifier to use in the Renderer helper's plist.", + "type": [ + "null", + "string" + ] + }, + "helperPluginBundleId": { + "default": "${appBundleIdentifier}.helper.Plugin", + "description": "The bundle identifier to use in the Plugin helper's plist.", + "type": [ + "null", + "string" + ] + }, + "helperGPUBundleId": { + "default": "${appBundleIdentifier}.helper.GPU", + "description": "The bundle identifier to use in the GPU helper's plist.", + "type": [ + "null", + "string" + ] + }, + "helperEHBundleId": { + "default": "${appBundleIdentifier}.helper.EH", + "description": "The bundle identifier to use in the EH helper's plist.", + "type": [ + "null", + "string" + ] + }, + "helperNPBundleId": { + "default": "${appBundleIdentifier}.helper.NP", + "description": "The bundle identifier to use in the NP helper's plist.", + "type": [ + "null", + "string" + ] + }, "icon": { "default": "build/icon.icns", "description": "The path to application icon.", diff --git a/packages/app-builder-lib/src/electron/electronMac.ts b/packages/app-builder-lib/src/electron/electronMac.ts index f059e387402..263084b01c6 100644 --- a/packages/app-builder-lib/src/electron/electronMac.ts +++ b/packages/app-builder-lib/src/electron/electronMac.ts @@ -81,6 +81,14 @@ export async function createMacApp(packager: MacPackager, appOutDir: string, asa } const buildMetadata = packager.config!! + + /** + * Configure bundleIdentifier for the generic Electron Helper process + * + * This was the only Helper in Electron 5 and before. Allow users to configure + * the bundleIdentifier for continuity. + */ + const oldHelperBundleId = (buildMetadata as any)["helper-bundle-id"] if (oldHelperBundleId != null) { log.warn("build.helper-bundle-id is deprecated, please set as build.mac.helperBundleId") @@ -99,27 +107,38 @@ export async function createMacApp(packager: MacPackager, appOutDir: string, asa helperPlist.CFBundleIdentifier = helperBundleIdentifier helperPlist.CFBundleVersion = appPlist.CFBundleVersion - function configureHelper(helper: any, postfix: string) { + /** + * Configure bundleIdentifier for Electron 5+ Helper processes + * + * In Electron 6, parts of the generic Electron Helper process were split into + * individual helper processes. Allow users to configure the bundleIdentifiers + * for continuity, specifically because macOS keychain access relies on + * bundleIdentifiers not changing (i.e. across versions of Electron). + */ + + function configureHelper(helper: any, postfix: string, userProvidedBundleIdentifier?: string | null) { helper.CFBundleExecutable = `${appFilename} Helper ${postfix}` helper.CFBundleDisplayName = `${appInfo.productName} Helper ${postfix}` - helper.CFBundleIdentifier = `${helperBundleIdentifier}.${postfix.replace(/[^a-z0-9]/gim, "")}` + helper.CFBundleIdentifier = userProvidedBundleIdentifier + ? filterCFBundleIdentifier(userProvidedBundleIdentifier) + : `${helperBundleIdentifier}.${postfix.replace(/[^a-z0-9]/gim, "")}` helper.CFBundleVersion = appPlist.CFBundleVersion } if (helperRendererPlist != null) { - configureHelper(helperRendererPlist, "(Renderer)") + configureHelper(helperRendererPlist, "(Renderer)", packager.platformSpecificBuildOptions.helperRendererBundleId) } if (helperPluginPlist != null) { - configureHelper(helperPluginPlist, "(Plugin)") + configureHelper(helperPluginPlist, "(Plugin)", packager.platformSpecificBuildOptions.helperPluginBundleId) } if (helperGPUPlist != null) { - configureHelper(helperGPUPlist, "(GPU)") + configureHelper(helperGPUPlist, "(GPU)", packager.platformSpecificBuildOptions.helperGPUBundleId) } if (helperEHPlist != null) { - configureHelper(helperEHPlist, "EH") + configureHelper(helperEHPlist, "EH", packager.platformSpecificBuildOptions.helperEHBundleId) } if (helperNPPlist != null) { - configureHelper(helperNPPlist, "NP") + configureHelper(helperNPPlist, "NP", packager.platformSpecificBuildOptions.helperNPBundleId) } if (helperLoginPlist != null) { helperLoginPlist.CFBundleExecutable = `${appFilename} Login Helper` @@ -249,4 +268,4 @@ function configureLocalhostAts(appPlist: any) { exceptionDomains.localhost = allowHttp exceptionDomains["127.0.0.1"] = allowHttp } -} \ No newline at end of file +} diff --git a/packages/app-builder-lib/src/options/macOptions.ts b/packages/app-builder-lib/src/options/macOptions.ts index fb1a04a92cb..e09edf2c9e2 100644 --- a/packages/app-builder-lib/src/options/macOptions.ts +++ b/packages/app-builder-lib/src/options/macOptions.ts @@ -70,6 +70,36 @@ export interface MacConfiguration extends PlatformSpecificBuildOptions { */ readonly helperBundleId?: string | null + /** + * The bundle identifier to use in the Renderer helper's plist. + * @default ${appBundleIdentifier}.helper.Renderer + */ + readonly helperRendererBundleId?: string | null + + /** + * The bundle identifier to use in the Plugin helper's plist. + * @default ${appBundleIdentifier}.helper.Plugin + */ + readonly helperPluginBundleId?: string | null + + /** + * The bundle identifier to use in the GPU helper's plist. + * @default ${appBundleIdentifier}.helper.GPU + */ + readonly helperGPUBundleId?: string | null + + /** + * The bundle identifier to use in the EH helper's plist. + * @default ${appBundleIdentifier}.helper.EH + */ + readonly helperEHBundleId?: string | null + + /** + * The bundle identifier to use in the NP helper's plist. + * @default ${appBundleIdentifier}.helper.NP + */ + readonly helperNPBundleId?: string | null + /** * Whether to sign app for development or for distribution. * @default distribution diff --git a/test/out/mac/__snapshots__/macArchiveTest.js.snap b/test/out/mac/__snapshots__/macArchiveTest.js.snap index 66f7c31e14e..55d8bffb6c1 100644 --- a/test/out/mac/__snapshots__/macArchiveTest.js.snap +++ b/test/out/mac/__snapshots__/macArchiveTest.js.snap @@ -104,7 +104,7 @@ Object { exports[`invalid target 1`] = ` "Invalid configuration object. electron-builder 0.0.0-semantic-release has been initialised using a configuration object that does not match the API schema. - configuration.mac should be one of these: - object { appId?, artifactName?, asar?, asarUnpack?, binaries?, bundleShortVersion?, bundleVersion?, category?, compression?, cscInstallerKeyPassword?, cscInstallerLink?, cscKeyPassword?, cscLink?, darkModeSupport?, detectUpdateChannel?, electronLanguages?, electronUpdaterCompatibility?, entitlements?, entitlementsInherit?, extendInfo?, extraDistFiles?, extraFiles?, extraResources?, fileAssociations?, files?, forceCodeSigning?, gatekeeperAssess?, generateUpdatesFilesForAllChannels?, hardenedRuntime?, helperBundleId?, icon?, identity?, minimumSystemVersion?, protocols?, provisioningProfile?, publish?, releaseInfo?, requirements?, target?, type? } | null + object { appId?, artifactName?, asar?, asarUnpack?, binaries?, bundleShortVersion?, bundleVersion?, category?, compression?, cscInstallerKeyPassword?, cscInstallerLink?, cscKeyPassword?, cscLink?, darkModeSupport?, detectUpdateChannel?, electronLanguages?, electronUpdaterCompatibility?, entitlements?, entitlementsInherit?, extendInfo?, extraDistFiles?, extraFiles?, extraResources?, fileAssociations?, files?, forceCodeSigning?, gatekeeperAssess?, generateUpdatesFilesForAllChannels?, hardenedRuntime?, helperBundleId?, helperRendererBundleId?, helperPluginBundleId?, helperGPUBundleId?, helperEHBundleId?, helperNPBundleId?, icon?, identity?, minimumSystemVersion?, protocols?, provisioningProfile?, publish?, releaseInfo?, requirements?, target?, type? } | null -> Options related to how build macOS targets. Details: * configuration.mac.target[0] should be an object: