1
1
import { asArray , copyOrLinkFile , getPlatformIconFileName , InvalidConfigurationError , log , unlinkIfExists } from "builder-util"
2
2
import { rename , utimes } from "fs/promises"
3
3
import * as path from "path"
4
+ import * as fs from "fs"
4
5
import { filterCFBundleIdentifier } from "../appInfo"
5
6
import { AsarIntegrity } from "../asar/integrity"
6
7
import { MacPackager } from "../macPackager"
7
8
import { normalizeExt } from "../platformPackager"
8
- import { executeAppBuilderAndWriteJson , executeAppBuilderAsJson } from "../util/appBuilder "
9
+ import { savePlistFile , parsePlistFile , PlistObject , PlistValue } from "../util/plist "
9
10
import { createBrandingOpts } from "./ElectronFramework"
10
11
11
12
function doRename ( basePath : string , oldName : string , newName : string ) {
@@ -22,11 +23,11 @@ function moveHelpers(helperSuffixes: Array<string>, frameworksPath: string, appN
22
23
}
23
24
24
25
function getAvailableHelperSuffixes (
25
- helperEHPlist : string | null ,
26
- helperNPPlist : string | null ,
27
- helperRendererPlist : string | null ,
28
- helperPluginPlist : string | null ,
29
- helperGPUPlist : string | null
26
+ helperEHPlist : PlistObject | null ,
27
+ helperNPPlist : PlistObject | null ,
28
+ helperRendererPlist : PlistObject | null ,
29
+ helperPluginPlist : PlistObject | null ,
30
+ helperGPUPlist : PlistObject | null
30
31
) {
31
32
const result = [ " Helper" ]
32
33
if ( helperEHPlist != null ) {
@@ -69,38 +70,26 @@ export async function createMacApp(packager: MacPackager, appOutDir: string, asa
69
70
const helperGPUPlistFilename = path . join ( frameworksPath , `${ electronBranding . productName } Helper (GPU).app` , "Contents" , "Info.plist" )
70
71
const helperLoginPlistFilename = path . join ( loginItemPath , `${ electronBranding . productName } Login Helper.app` , "Contents" , "Info.plist" )
71
72
72
- const plistContent : Array < any > = await executeAppBuilderAsJson ( [
73
- "decode-plist" ,
74
- "-f" ,
75
- appPlistFilename ,
76
- "-f" ,
77
- helperPlistFilename ,
78
- "-f" ,
79
- helperEHPlistFilename ,
80
- "-f" ,
81
- helperNPPlistFilename ,
82
- "-f" ,
83
- helperRendererPlistFilename ,
84
- "-f" ,
85
- helperPluginPlistFilename ,
86
- "-f" ,
87
- helperGPUPlistFilename ,
88
- "-f" ,
89
- helperLoginPlistFilename ,
90
- ] )
73
+ const safeParsePlistFile = async ( filePath : string ) : Promise < PlistObject | null > => {
74
+ if ( ! fs . existsSync ( filePath ) ) {
75
+ return null
76
+ }
77
+ return await parsePlistFile ( filePath )
78
+ }
91
79
92
- if ( plistContent [ 0 ] == null ) {
80
+ const appPlist = ( await safeParsePlistFile ( appPlistFilename ) ) !
81
+ if ( appPlist == null ) {
93
82
throw new Error ( "corrupted Electron dist" )
94
83
}
95
84
96
- const appPlist = plistContent [ 0 ] !
97
- const helperPlist = plistContent [ 1 ] !
98
- const helperEHPlist = plistContent [ 2 ]
99
- const helperNPPlist = plistContent [ 3 ]
100
- const helperRendererPlist = plistContent [ 4 ]
101
- const helperPluginPlist = plistContent [ 5 ]
102
- const helperGPUPlist = plistContent [ 6 ]
103
- const helperLoginPlist = plistContent [ 7 ]
85
+ // Replace the multiple parsePlistFile calls with:
86
+ const helperPlist = await safeParsePlistFile ( helperPlistFilename )
87
+ const helperEHPlist = await safeParsePlistFile ( helperEHPlistFilename )
88
+ const helperNPPlist = await safeParsePlistFile ( helperNPPlistFilename )
89
+ const helperRendererPlist = await safeParsePlistFile ( helperRendererPlistFilename )
90
+ const helperPluginPlist = await safeParsePlistFile ( helperPluginPlistFilename )
91
+ const helperGPUPlist = await safeParsePlistFile ( helperGPUPlistFilename )
92
+ const helperLoginPlist = await safeParsePlistFile ( helperLoginPlistFilename )
104
93
105
94
const buildMetadata = packager . config
106
95
@@ -133,10 +122,12 @@ export async function createMacApp(packager: MacPackager, appOutDir: string, asa
133
122
configureLocalhostAts ( appPlist )
134
123
}
135
124
136
- helperPlist . CFBundleExecutable = `${ appFilename } Helper`
137
- helperPlist . CFBundleDisplayName = `${ appInfo . productName } Helper`
138
- helperPlist . CFBundleIdentifier = helperBundleIdentifier
139
- helperPlist . CFBundleVersion = appPlist . CFBundleVersion
125
+ if ( helperPlist != null ) {
126
+ helperPlist . CFBundleExecutable = `${ appFilename } Helper`
127
+ helperPlist . CFBundleDisplayName = `${ appInfo . productName } Helper`
128
+ helperPlist . CFBundleIdentifier = helperBundleIdentifier
129
+ helperPlist . CFBundleVersion = appPlist . CFBundleVersion
130
+ }
140
131
141
132
/**
142
133
* Configure bundleIdentifier for Electron 5+ Helper processes
@@ -222,39 +213,55 @@ export async function createMacApp(packager: MacPackager, appOutDir: string, asa
222
213
)
223
214
224
215
// `CFBundleDocumentTypes` may be defined in `mac.extendInfo`, so we need to merge it in that case
225
- appPlist . CFBundleDocumentTypes = [ ...( appPlist . CFBundleDocumentTypes || [ ] ) , ...documentTypes ]
216
+ appPlist . CFBundleDocumentTypes = [ ...( ( appPlist . CFBundleDocumentTypes as PlistValue [ ] ) || [ ] ) , ...documentTypes ]
226
217
}
227
218
228
- if ( asarIntegrity != null ) {
229
- appPlist . ElectronAsarIntegrity = asarIntegrity
219
+ const toPlistObject = ( asarIntegrity : AsarIntegrity ) : PlistObject => {
220
+ const result : PlistObject = { }
221
+ for ( const [ filePath , headerHash ] of Object . entries ( asarIntegrity ) ) {
222
+ result [ filePath ] = {
223
+ algorithm : headerHash . algorithm ,
224
+ hash : headerHash . hash ,
225
+ }
226
+ }
227
+ return result
230
228
}
231
229
232
- const plistDataToWrite : any = {
233
- [ appPlistFilename ] : appPlist ,
234
- [ helperPlistFilename ] : helperPlist ,
230
+ if ( asarIntegrity != null ) {
231
+ appPlist . ElectronAsarIntegrity = toPlistObject ( asarIntegrity )
235
232
}
233
+
236
234
if ( helperEHPlist != null ) {
237
- plistDataToWrite [ helperEHPlistFilename ] = helperEHPlist
235
+ await savePlistFile ( helperEHPlistFilename , helperEHPlist )
238
236
}
237
+
239
238
if ( helperNPPlist != null ) {
240
- plistDataToWrite [ helperNPPlistFilename ] = helperNPPlist
239
+ await savePlistFile ( helperNPPlistFilename , helperNPPlist )
241
240
}
241
+
242
242
if ( helperRendererPlist != null ) {
243
- plistDataToWrite [ helperRendererPlistFilename ] = helperRendererPlist
243
+ await savePlistFile ( helperRendererPlistFilename , helperRendererPlist )
244
244
}
245
+
245
246
if ( helperPluginPlist != null ) {
246
- plistDataToWrite [ helperPluginPlistFilename ] = helperPluginPlist
247
+ await savePlistFile ( helperPluginPlistFilename , helperPluginPlist )
247
248
}
249
+
248
250
if ( helperGPUPlist != null ) {
249
- plistDataToWrite [ helperGPUPlistFilename ] = helperGPUPlist
251
+ await savePlistFile ( helperGPUPlistFilename , helperGPUPlist )
250
252
}
253
+
251
254
if ( helperLoginPlist != null ) {
252
- plistDataToWrite [ helperLoginPlistFilename ] = helperLoginPlist
255
+ await savePlistFile ( helperLoginPlistFilename , helperLoginPlist )
256
+ }
257
+
258
+ await savePlistFile ( appPlistFilename , appPlist )
259
+ if ( helperPlist != null ) {
260
+ await savePlistFile ( helperPlistFilename , helperPlist )
253
261
}
254
262
255
263
await Promise . all ( [
256
- executeAppBuilderAndWriteJson ( [ "encode-plist" ] , plistDataToWrite ) ,
257
- doRename ( path . join ( contentsPath , "MacOS" ) , electronBranding . productName , appPlist . CFBundleExecutable ) ,
264
+ doRename ( path . join ( contentsPath , "MacOS" ) , electronBranding . productName , appPlist . CFBundleExecutable as string ) ,
258
265
unlinkIfExists ( path . join ( appOutDir , "LICENSE" ) ) ,
259
266
unlinkIfExists ( path . join ( appOutDir , "LICENSES.chromium.html" ) ) ,
260
267
] )
0 commit comments