Skip to content

Commit

Permalink
feat: allow customization of bundleIdentifier for the new Electron 6+…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
aguynamedben committed Mar 3, 2020
1 parent d33065b commit 8b1cebc
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 9 deletions.
40 changes: 40 additions & 0 deletions packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
35 changes: 27 additions & 8 deletions packages/app-builder-lib/src/electron/electronMac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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`
Expand Down Expand Up @@ -249,4 +268,4 @@ function configureLocalhostAts(appPlist: any) {
exceptionDomains.localhost = allowHttp
exceptionDomains["127.0.0.1"] = allowHttp
}
}
}
30 changes: 30 additions & 0 deletions packages/app-builder-lib/src/options/macOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/out/mac/__snapshots__/macArchiveTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8b1cebc

Please sign in to comment.