@@ -217,11 +217,35 @@ function extractApp(zip: string, outDir: string) {
217217 return NodePath . join ( outDir , app ) ;
218218}
219219
220- // Only the bundle's file and display name change. Electron finds its helper apps from
221- // CFBundleName, and the data folder and keychain item follow the build's branding.
220+ // Electron finds its helpers as "<CFBundleName> Helper*.app", so they are renamed together.
221+ // The data folder and keychain item follow the build's branding, so installs keep their data .
222222function renameApp ( app : string ) {
223- const plist = NodePath . join ( app , "Contents" , "Info.plist" ) ;
224- run ( "plutil" , [ "-replace" , "CFBundleDisplayName" , "-string" , APP_NAME , plist ] ) ;
223+ const contents = NodePath . join ( app , "Contents" ) ;
224+ const setNames = ( plist : string , name : string ) => {
225+ run ( "plutil" , [ "-replace" , "CFBundleName" , "-string" , name , plist ] ) ;
226+ run ( "plutil" , [ "-replace" , "CFBundleDisplayName" , "-string" , name , plist ] ) ;
227+ } ;
228+ const mainPlist = NodePath . join ( contents , "Info.plist" ) ;
229+ const builtName = run ( "plutil" , [ "-extract" , "CFBundleName" , "raw" , mainPlist ] ) ;
230+ setNames ( mainPlist , APP_NAME ) ;
231+ const frameworks = NodePath . join ( contents , "Frameworks" ) ;
232+ for ( const helper of NodeFS . readdirSync ( frameworks ) ) {
233+ if ( ! helper . startsWith ( `${ builtName } Helper` ) || ! helper . endsWith ( ".app" ) ) continue ;
234+ const helperName = helper . slice ( 0 , - ".app" . length ) ;
235+ const renamedHelper = `${ APP_NAME } ${ helperName . slice ( builtName . length ) } ` ;
236+ const helperContents = NodePath . join ( frameworks , helper , "Contents" ) ;
237+ NodeFS . renameSync (
238+ NodePath . join ( helperContents , "MacOS" , helperName ) ,
239+ NodePath . join ( helperContents , "MacOS" , renamedHelper ) ,
240+ ) ;
241+ const helperPlist = NodePath . join ( helperContents , "Info.plist" ) ;
242+ run ( "plutil" , [ "-replace" , "CFBundleExecutable" , "-string" , renamedHelper , helperPlist ] ) ;
243+ setNames ( helperPlist , renamedHelper ) ;
244+ NodeFS . renameSync (
245+ NodePath . join ( frameworks , helper ) ,
246+ NodePath . join ( frameworks , `${ renamedHelper } .app` ) ,
247+ ) ;
248+ }
225249 const renamed = NodePath . join ( NodePath . dirname ( app ) , `${ APP_NAME } .app` ) ;
226250 NodeFS . renameSync ( app , renamed ) ;
227251 return renamed ;
0 commit comments