Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customization of bundleIdentifier for the new Electron 6+ renderer processes #4692

Merged
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
6 changes: 3 additions & 3 deletions test/out/__snapshots__/BuildTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,10 @@ Object {
"size": 765,
},
"chownr.js": Object {
"size": 3548,
"size": 4275,
},
"package.json": Object {
"size": 402,
"size": 452,
},
},
},
Expand Down Expand Up @@ -1063,7 +1063,7 @@ Object {
"size": 1069,
},
"index.js": Object {
"size": 5127,
"size": 5192,
},
"package.json": Object {
"size": 525,
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