|
| 1 | +import fs from "node:fs/promises"; |
| 2 | + |
| 3 | +import plist from "plist"; |
| 4 | + |
| 5 | +const setOsxConfig = async (pkg, outDir) => { |
| 6 | + // Rename CFBundleDisplayName in Contents/Info.plist |
| 7 | + let contents_info_plist_path = `${outDir}/nwjs.app/Contents/Info.plist`; |
| 8 | + let contents_info_plist_json = plist.parse( |
| 9 | + await fs.readFile(contents_info_plist_path, "utf-8"), |
| 10 | + ); |
| 11 | + contents_info_plist_json.CFBundleDisplayName = pkg.name; |
| 12 | + let contents_info_plist = plist.build(contents_info_plist_json); |
| 13 | + await fs.writeFile(contents_info_plist_path, contents_info_plist); |
| 14 | + |
| 15 | + // Rename CFBundleDisplayName in Contents/Resources/en.lproj/InfoPlist.strings |
| 16 | + |
| 17 | + // Rename Helper apps in Contents/Framework.framework/Versions/n.n.n.n/Helpers |
| 18 | + let chromium_version = "107.0.5304.88"; |
| 19 | + let helper_app_path_alerts = (name = "nwjs") => |
| 20 | + `${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${chromium_version}/Helpers/${name} Helper (Alerts).app`; |
| 21 | + let helper_app_path_gpu = (name = "nwjs") => |
| 22 | + `${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${chromium_version}/Helpers/${name} Helper (GPU).app`; |
| 23 | + let helper_app_path_plugin = (name = "nwjs") => |
| 24 | + `${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${chromium_version}/Helpers/${name} Helper (Plugin).app`; |
| 25 | + let helper_app_path_renderer = (name = "nwjs") => |
| 26 | + `${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${chromium_version}/Helpers/${name} Helper (Renderer).app`; |
| 27 | + let helper_app_path = (name = "nwjs") => |
| 28 | + `${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${chromium_version}/Helpers/${name} Helper.app`; |
| 29 | + await fs.rename(helper_app_path_alerts(), helper_app_path_alerts(pkg.name)); |
| 30 | + await fs.rename(helper_app_path_gpu(), helper_app_path_gpu(pkg.name)); |
| 31 | + await fs.rename(helper_app_path_plugin(), helper_app_path_plugin(pkg.name)); |
| 32 | + await fs.rename( |
| 33 | + helper_app_path_renderer(), |
| 34 | + helper_app_path_renderer(pkg.name), |
| 35 | + ); |
| 36 | + await fs.rename(helper_app_path(), helper_app_path(pkg.name)); |
| 37 | + |
| 38 | + let helper_app_alerts_plist_path = `${helper_app_path_alerts( |
| 39 | + pkg.name, |
| 40 | + )}/Contents/Info.plist`; |
| 41 | + let helper_app_gpu_plist_path = `${helper_app_path_gpu( |
| 42 | + pkg.name, |
| 43 | + )}/Contents/Info.plist`; |
| 44 | + let helper_app_plugin_plist_path = `${helper_app_path_plugin( |
| 45 | + pkg.name, |
| 46 | + )}/Contents/Info.plist`; |
| 47 | + let helper_app_render_plist_path = `${helper_app_path_renderer( |
| 48 | + pkg.name, |
| 49 | + )}/Contents/Info.plist`; |
| 50 | + let helper_app_plist_path = `${helper_app_path( |
| 51 | + pkg.name, |
| 52 | + )}/Contents/Info.plist`; |
| 53 | + |
| 54 | + let helper_app_alerts_plist_json = plist.parse( |
| 55 | + await fs.readFile(helper_app_alerts_plist_path, "utf-8"), |
| 56 | + ); |
| 57 | + let helper_app_gpu_plist_json = plist.parse( |
| 58 | + await fs.readFile(helper_app_gpu_plist_path, "utf-8"), |
| 59 | + ); |
| 60 | + let helper_app_plugin_plist_json = plist.parse( |
| 61 | + await fs.readFile(helper_app_plugin_plist_path, "utf-8"), |
| 62 | + ); |
| 63 | + let helper_app_render_plist_json = plist.parse( |
| 64 | + await fs.readFile(helper_app_render_plist_path, "utf-8"), |
| 65 | + ); |
| 66 | + let helper_app_plist_json = plist.parse( |
| 67 | + await fs.readFile(helper_app_plist_path, "utf-8"), |
| 68 | + ); |
| 69 | + |
| 70 | + helper_app_alerts_plist_json.CFBundleDisplayName = pkg.name; |
| 71 | + helper_app_gpu_plist_json.CFBundleDisplayName = pkg.name; |
| 72 | + helper_app_render_plist_json.CFBundleDisplayName = pkg.name; |
| 73 | + helper_app_plugin_plist_json.CFBundleDisplayName = pkg.name; |
| 74 | + helper_app_plist_json.CFBundleDisplayName = pkg.name; |
| 75 | + |
| 76 | + let helper_app_alerts_plist = plist.build(helper_app_alerts_plist_json); |
| 77 | + let helper_app_gpu_plist = plist.build(helper_app_gpu_plist_json); |
| 78 | + let helper_app_render_plist = plist.build(helper_app_render_plist_json); |
| 79 | + let helper_app_plugin_plist = plist.build(helper_app_plugin_plist_json); |
| 80 | + let helper_app_plist = plist.build(helper_app_plist_json); |
| 81 | + |
| 82 | + await fs.writeFile(helper_app_alerts_plist_path, helper_app_alerts_plist); |
| 83 | + await fs.writeFile(helper_app_gpu_plist_path, helper_app_gpu_plist); |
| 84 | + await fs.writeFile(helper_app_plugin_plist_path, helper_app_plugin_plist); |
| 85 | + await fs.writeFile(helper_app_render_plist_path, helper_app_render_plist); |
| 86 | + await fs.writeFile(helper_app_plist_path, helper_app_plist); |
| 87 | +}; |
| 88 | + |
| 89 | +export { setOsxConfig }; |
0 commit comments