Skip to content

Commit

Permalink
macos support (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmanchhabra authored Nov 13, 2022
1 parent dfae361 commit d30754d
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 9 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ npm install nw-builder
## Usage

```javascript
import nwbuild from "nw-builder";
import { nwbuild } from "nw-builder";

nwbuild({
srcDir: "./nwapp",
Expand All @@ -37,10 +37,6 @@ nwbuild({
});
```

## Team

This project was created by [Steffen Müller](https://github.com/steffenmllr) and has been maintained by [Gabe Paez](https://github.com/gabepaez), [Andy Trevorah](https://github.com/trevorah), [Adam Lynch](https://github.com/adam-lynch) and [Rémy Boulanouar](https://github.com/DblK) in the past. This project is currently maintained by [Ayushman Chhabra](https://github.com/ayushmxn).

## Contributing

1. Pick and install a Node version manager
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"archiver": "^5.3.1",
"cli-progress": "^3.11.2",
"extract-zip": "^2.0.1",
"plist": "^3.0.5",
"plist": "^3.0.6",
"progress": "^2.0.3",
"rcedit": "^3.0.1",
"tar": "^6.1.11",
Expand Down
89 changes: 89 additions & 0 deletions src/bld/osxCfg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import fs from "node:fs/promises";

import plist from "plist";

const setOsxConfig = async (pkg, outDir) => {
// Rename CFBundleDisplayName in Contents/Info.plist
let contents_info_plist_path = `${outDir}/nwjs.app/Contents/Info.plist`;
let contents_info_plist_json = plist.parse(
await fs.readFile(contents_info_plist_path, "utf-8"),
);
contents_info_plist_json.CFBundleDisplayName = pkg.name;
let contents_info_plist = plist.build(contents_info_plist_json);
await fs.writeFile(contents_info_plist_path, contents_info_plist);

// Rename CFBundleDisplayName in Contents/Resources/en.lproj/InfoPlist.strings

// Rename Helper apps in Contents/Framework.framework/Versions/n.n.n.n/Helpers
let chromium_version = "107.0.5304.88";
let helper_app_path_alerts = (name = "nwjs") =>
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${chromium_version}/Helpers/${name} Helper (Alerts).app`;
let helper_app_path_gpu = (name = "nwjs") =>
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${chromium_version}/Helpers/${name} Helper (GPU).app`;
let helper_app_path_plugin = (name = "nwjs") =>
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${chromium_version}/Helpers/${name} Helper (Plugin).app`;
let helper_app_path_renderer = (name = "nwjs") =>
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${chromium_version}/Helpers/${name} Helper (Renderer).app`;
let helper_app_path = (name = "nwjs") =>
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${chromium_version}/Helpers/${name} Helper.app`;
await fs.rename(helper_app_path_alerts(), helper_app_path_alerts(pkg.name));
await fs.rename(helper_app_path_gpu(), helper_app_path_gpu(pkg.name));
await fs.rename(helper_app_path_plugin(), helper_app_path_plugin(pkg.name));
await fs.rename(
helper_app_path_renderer(),
helper_app_path_renderer(pkg.name),
);
await fs.rename(helper_app_path(), helper_app_path(pkg.name));

let helper_app_alerts_plist_path = `${helper_app_path_alerts(
pkg.name,
)}/Contents/Info.plist`;
let helper_app_gpu_plist_path = `${helper_app_path_gpu(
pkg.name,
)}/Contents/Info.plist`;
let helper_app_plugin_plist_path = `${helper_app_path_plugin(
pkg.name,
)}/Contents/Info.plist`;
let helper_app_render_plist_path = `${helper_app_path_renderer(
pkg.name,
)}/Contents/Info.plist`;
let helper_app_plist_path = `${helper_app_path(
pkg.name,
)}/Contents/Info.plist`;

let helper_app_alerts_plist_json = plist.parse(
await fs.readFile(helper_app_alerts_plist_path, "utf-8"),
);
let helper_app_gpu_plist_json = plist.parse(
await fs.readFile(helper_app_gpu_plist_path, "utf-8"),
);
let helper_app_plugin_plist_json = plist.parse(
await fs.readFile(helper_app_plugin_plist_path, "utf-8"),
);
let helper_app_render_plist_json = plist.parse(
await fs.readFile(helper_app_render_plist_path, "utf-8"),
);
let helper_app_plist_json = plist.parse(
await fs.readFile(helper_app_plist_path, "utf-8"),
);

helper_app_alerts_plist_json.CFBundleDisplayName = pkg.name;
helper_app_gpu_plist_json.CFBundleDisplayName = pkg.name;
helper_app_render_plist_json.CFBundleDisplayName = pkg.name;
helper_app_plugin_plist_json.CFBundleDisplayName = pkg.name;
helper_app_plist_json.CFBundleDisplayName = pkg.name;

let helper_app_alerts_plist = plist.build(helper_app_alerts_plist_json);
let helper_app_gpu_plist = plist.build(helper_app_gpu_plist_json);
let helper_app_render_plist = plist.build(helper_app_render_plist_json);
let helper_app_plugin_plist = plist.build(helper_app_plugin_plist_json);
let helper_app_plist = plist.build(helper_app_plist_json);

await fs.writeFile(helper_app_alerts_plist_path, helper_app_alerts_plist);
await fs.writeFile(helper_app_gpu_plist_path, helper_app_gpu_plist);
await fs.writeFile(helper_app_plugin_plist_path, helper_app_plugin_plist);
await fs.writeFile(helper_app_render_plist_path, helper_app_render_plist);
await fs.writeFile(helper_app_plist_path, helper_app_plist);
};

export { setOsxConfig };
4 changes: 4 additions & 0 deletions src/bld/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from "node:fs";

import { compress } from "./compress.js";
import { setLinuxConfig } from "./linuxCfg.js";
import { setOsxConfig } from "./osxCfg.js";
import { setWinConfig } from "./winCfg.js";

const packager = async (srcDir, nwDir, outDir, platform, zip) => {
Expand Down Expand Up @@ -31,6 +32,9 @@ const packager = async (srcDir, nwDir, outDir, platform, zip) => {
case "win":
setWinConfig(pkg, outDir);
break;
case "osx":
setOsxConfig(pkg, outDir);
break;
default:
break;
}
Expand Down
1 change: 0 additions & 1 deletion test/demo/bld.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ nwbuild({
platform: "linux",
arch: "x64",
outDir: "./build",
zip: true,
});
3 changes: 2 additions & 1 deletion test/demo/nwapp/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "nwdemo",
"main": "index.html",
"product_string": "nwdemo",
"nwbuild": {
"srcDir": "./nwapp",
"version": "0.70.1",
"flavour": "sdk",
"platform": "linux",
"platform": "osx",
"arch": "x64",
"outDir": "./build",
"run": true
Expand Down

0 comments on commit d30754d

Please sign in to comment.