Skip to content

Commit aa38a56

Browse files
authored
fix: osx builds to allow nwjs launch (#717)
Signed-off-by: Brian Bothwell <sysrage@gmail.com>
1 parent 1a49aeb commit aa38a56

File tree

2 files changed

+41
-81
lines changed

2 files changed

+41
-81
lines changed

src/bld/osxCfg.js

Lines changed: 39 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from "node:fs/promises";
2+
import path from "node:path";
23

34
import plist from "plist";
45

@@ -9,89 +10,48 @@ import plist from "plist";
910
* @param {string} outDir The directory to hold build artifacts
1011
* @param {object} releaseInfo NW binary release metadata
1112
*/
12-
const setOsxConfig = async (pkg, outDir, releaseInfo) => {
13-
await fs.rename(`${outDir}/nwjs.app`, `${outDir}/${pkg.name}.app`);
13+
const setOsxConfig = async (pkg, outDir) => {
14+
// const setOsxConfig = async (pkg, outDir, releaseInfo) => {
15+
const outApp = path.resolve(outDir, `${pkg.name}.app`);
16+
await fs.rename(path.resolve(outDir, "nwjs.app"), outApp);
1417

1518
// Rename CFBundleDisplayName in Contents/Info.plist
16-
let contents_info_plist_path = `${outDir}/${pkg.name}.app/Contents/Info.plist`;
17-
let contents_info_plist_json = plist.parse(
18-
await fs.readFile(contents_info_plist_path, "utf-8"),
19-
);
20-
contents_info_plist_json.CFBundleDisplayName = pkg.name;
21-
let contents_info_plist = plist.build(contents_info_plist_json);
22-
await fs.writeFile(contents_info_plist_path, contents_info_plist);
19+
const contentsInfoPlistPath = path.resolve(outApp, "Contents/Info.plist");
20+
const contentsInfoPlistJson = plist.parse(await fs.readFile(contentsInfoPlistPath, "utf-8"));
21+
contentsInfoPlistJson.CFBundleDisplayName = pkg.name;
22+
const contentsInfoPlist = plist.build(contentsInfoPlistJson);
23+
await fs.writeFile(contentsInfoPlistPath, contentsInfoPlist);
2324

2425
// Rename CFBundleDisplayName in Contents/Resources/en.lproj/InfoPlist.strings
25-
26-
// Rename Helper apps in Contents/Framework.framework/Versions/n.n.n.n/Helpers
27-
let helper_app_path_alerts = (name = "nwjs") =>
28-
`${outDir}/${pkg.name}.app/Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/${name} Helper (Alerts).app`;
29-
let helper_app_path_gpu = (name = "nwjs") =>
30-
`${outDir}/${pkg.name}.app/Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/${name} Helper (GPU).app`;
31-
let helper_app_path_plugin = (name = "nwjs") =>
32-
`${outDir}/${pkg.name}.app/Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/${name} Helper (Plugin).app`;
33-
let helper_app_path_renderer = (name = "nwjs") =>
34-
`${outDir}/${pkg.name}.app/Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/${name} Helper (Renderer).app`;
35-
let helper_app_path = (name = "nwjs") =>
36-
`${outDir}/${pkg.name}.app/Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/${name} Helper.app`;
37-
await fs.rename(helper_app_path_alerts(), helper_app_path_alerts(pkg.name));
38-
await fs.rename(helper_app_path_gpu(), helper_app_path_gpu(pkg.name));
39-
await fs.rename(helper_app_path_plugin(), helper_app_path_plugin(pkg.name));
40-
await fs.rename(
41-
helper_app_path_renderer(),
42-
helper_app_path_renderer(pkg.name),
43-
);
44-
await fs.rename(helper_app_path(), helper_app_path(pkg.name));
45-
46-
let helper_app_alerts_plist_path = `${helper_app_path_alerts(
47-
pkg.name,
48-
)}/Contents/Info.plist`;
49-
let helper_app_gpu_plist_path = `${helper_app_path_gpu(
50-
pkg.name,
51-
)}/Contents/Info.plist`;
52-
let helper_app_plugin_plist_path = `${helper_app_path_plugin(
53-
pkg.name,
54-
)}/Contents/Info.plist`;
55-
let helper_app_render_plist_path = `${helper_app_path_renderer(
56-
pkg.name,
57-
)}/Contents/Info.plist`;
58-
let helper_app_plist_path = `${helper_app_path(
59-
pkg.name,
60-
)}/Contents/Info.plist`;
61-
62-
let helper_app_alerts_plist_json = plist.parse(
63-
await fs.readFile(helper_app_alerts_plist_path, "utf-8"),
64-
);
65-
let helper_app_gpu_plist_json = plist.parse(
66-
await fs.readFile(helper_app_gpu_plist_path, "utf-8"),
67-
);
68-
let helper_app_plugin_plist_json = plist.parse(
69-
await fs.readFile(helper_app_plugin_plist_path, "utf-8"),
70-
);
71-
let helper_app_render_plist_json = plist.parse(
72-
await fs.readFile(helper_app_render_plist_path, "utf-8"),
73-
);
74-
let helper_app_plist_json = plist.parse(
75-
await fs.readFile(helper_app_plist_path, "utf-8"),
76-
);
77-
78-
helper_app_alerts_plist_json.CFBundleDisplayName = pkg.name;
79-
helper_app_gpu_plist_json.CFBundleDisplayName = pkg.name;
80-
helper_app_render_plist_json.CFBundleDisplayName = pkg.name;
81-
helper_app_plugin_plist_json.CFBundleDisplayName = pkg.name;
82-
helper_app_plist_json.CFBundleDisplayName = pkg.name;
83-
84-
let helper_app_alerts_plist = plist.build(helper_app_alerts_plist_json);
85-
let helper_app_gpu_plist = plist.build(helper_app_gpu_plist_json);
86-
let helper_app_render_plist = plist.build(helper_app_render_plist_json);
87-
let helper_app_plugin_plist = plist.build(helper_app_plugin_plist_json);
88-
let helper_app_plist = plist.build(helper_app_plist_json);
89-
90-
await fs.writeFile(helper_app_alerts_plist_path, helper_app_alerts_plist);
91-
await fs.writeFile(helper_app_gpu_plist_path, helper_app_gpu_plist);
92-
await fs.writeFile(helper_app_plugin_plist_path, helper_app_plugin_plist);
93-
await fs.writeFile(helper_app_render_plist_path, helper_app_render_plist);
94-
await fs.writeFile(helper_app_plist_path, helper_app_plist);
26+
const contentsInfoPlistStringsPath = path.resolve(outApp, "Contents/Resources/en.lproj/InfoPlist.strings");
27+
const contentsInfoPlistStrings = await fs.readFile(contentsInfoPlistStringsPath, "utf-8");
28+
const newPlistStrings = contentsInfoPlistStrings.replace(/CFBundleGetInfoString = "nwjs /, `CFBundleGetInfoString = "${pkg.name} `);
29+
await fs.writeFile(contentsInfoPlistStringsPath, newPlistStrings);
30+
31+
// Add product_string property to package.json
32+
// const packageJsonPath = path.resolve(outApp, "Contents/Resources/app.nw/package.json");
33+
// pkg.product_string = pkg.name;
34+
// await fs.writeFile(packageJsonPath, JSON.stringify(pkg, null, 4));
35+
36+
// Update Helper apps
37+
// TODO: determine why this prevents app from launching
38+
// for (const helperName of [" (Alerts)", " (GPU)", " (Plugin)", " (Renderer)", ""]) {
39+
// const helperPath = (name = "nwjs") => path.resolve(
40+
// outApp,
41+
// `Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/`,
42+
// `${name} Helper${helperName}.app`
43+
// );
44+
45+
// // Rename Helper apps in Contents/Framework.framework/Versions/n.n.n.n/Helpers
46+
// await fs.rename(helperPath(), helperPath(pkg.name));
47+
48+
// // Update Helper app Info.plist files in Contents/Framework.framework/Versions/n.n.n.n/Helpers
49+
// const helperPlistPath = path.resolve(helperPath(pkg.name), "Contents/Info.plist");
50+
// const helperPlistJson = plist.parse(await fs.readFile(helperPlistPath, "utf-8"));
51+
// helperPlistJson.CFBundleDisplayName = pkg.name;
52+
// const helperPlist = plist.build(helperPlistJson);
53+
// await fs.writeFile(helperPlistPath, helperPlist);
54+
// }
9555
};
9656

9757
export { setOsxConfig };

src/bld/package.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const packager = async (srcDir, nwDir, outDir, platform, zip, releaseInfo) => {
2727
await cp(
2828
srcDir,
2929
`${outDir}/${
30-
platform !== "osx" ? "package.nw" : "nwjs.app/Contents/Resources/nw.app"
30+
platform !== "osx" ? "package.nw" : "nwjs.app/Contents/Resources/app.nw"
3131
}`,
3232
{
3333
recursive: true,
@@ -37,7 +37,7 @@ const packager = async (srcDir, nwDir, outDir, platform, zip, releaseInfo) => {
3737
log.debug("Get NW's package.json as a buffer");
3838
let buffer = await readFile(
3939
`${outDir}/${
40-
platform !== "osx" ? "package.nw" : "nwjs.app/Contents/Resources/nw.app"
40+
platform !== "osx" ? "package.nw" : "nwjs.app/Contents/Resources/app.nw"
4141
}/package.json`,
4242
);
4343
log.debug("Convert package.json buffer into JSON");

0 commit comments

Comments
 (0)