Skip to content

Commit

Permalink
fix: MacOS icon and unofficial MacOS arm build (#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayush C authored Jul 6, 2023
1 parent 740a462 commit eba33cc
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 52 deletions.
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [4.3.1] - 2023-07-07

## Changed

- Replace the icon at `nwjs.app/Contents/Resources/app.icns` with the icon at `options.app.icon` file path.

## Removed

- `xattr` package. The `com.apple.quarantine` flag should be handled by the developer.

## [4.3.0] - 2023-07-03

## Added
Expand Down
6 changes: 6 additions & 0 deletions doc/mode-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,9 @@ nwbuild({
srcDir: "nw/package.json web/**/*",
});
```

Note: If you are using the MacOS ARM unofficial builds, you will need to [remove the `com.apple.qurantine` flag](https://github.com/corwin-of-amber/nw.js/releases/tag/nw-v0.75.0):

```shell
sudo xattr -r -d com.apple.quarantine nwjs.app
```
2 changes: 2 additions & 0 deletions doc/mode-get.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ CLI usage:
nwbuild --mode=get --platform=osx --arch=arm64 --downloadUrl=https://github.com/corwin-of-amber/nw.js/releases/download --manifestUrl=https://raw.githubusercontent.com/nwutils/nw-builder/main/src/util/osx.arm.versions.json
```

Note: Make sure you have [`xattr`](https://ss64.com/osx/xattr.html) installed in your system. This is needed to remove the `com.apple.quarantine` property.

## Download from mirrors

China:
Expand Down
4 changes: 2 additions & 2 deletions 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
@@ -1,6 +1,6 @@
{
"name": "nw-builder",
"version": "4.3.0",
"version": "4.3.1",
"description": "Build NW.js desktop applications for MacOS, Windows and Linux.",
"keywords": [
"NW.js",
Expand Down
21 changes: 13 additions & 8 deletions src/bld/osxCfg.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { platform } from "node:process";
import fs from "node:fs/promises";
import { copyFile, rename, readFile, writeFile } from "node:fs/promises";
import { resolve } from "node:path";

import plist from "plist";
Expand All @@ -9,6 +9,7 @@ import { log } from "../log.js";
/**
* @typedef {object} OsxRc OSX resource configuration options
* @property {string} name The name of the application
* @property {string} icon The path to the icon file. It should be a .icns file.
* @property {string} LSApplicationCategoryType The category that best describes your app for the App Store.
* @property {string} CFBundleIdentifier A unique identifier for a bundle usually in reverse DNS format.
* @property {string} CFBundleName A user-visible short name for the bundle.
Expand All @@ -33,14 +34,19 @@ const setOsxConfig = async (app, outDir) => {
"MacOS apps built on Windows platform do not preserve all file permissions. See #716"
);
}

try {
const outApp = resolve(outDir, `${app.name}.app`);
await fs.rename(resolve(outDir, "nwjs.app"), outApp);
await rename(resolve(outDir, "nwjs.app"), outApp);
if (app.icon !== undefined) {
await copyFile(
resolve(app.icon),
resolve(outApp, "Contents", "Resources", "app.icns")
);
}

const infoPlistPath = resolve(outApp, "Contents/Info.plist");
const infoPlistJson = plist.parse(
await fs.readFile(infoPlistPath, "utf-8")
);
const infoPlistPath = resolve(outApp, "Contents", "Info.plist");
const infoPlistJson = plist.parse(await readFile(infoPlistPath, "utf-8"));

infoPlistJson.LSApplicationCategoryType = app.LSApplicationCategoryType;
infoPlistJson.CFBundleIdentifier = app.CFBundleIdentifier;
Expand All @@ -50,15 +56,14 @@ const setOsxConfig = async (app, outDir) => {
infoPlistJson.CFBundleVersion = app.CFBundleVersion;
infoPlistJson.CFBundleShortVersionString = app.CFBundleShortVersionString;
infoPlistJson.NSHumanReadableCopyright = app.NSHumanReadableCopyright;
infoPlistJson.CFBundleIconFile = app.CFBundleIconFile;

Object.keys(infoPlistJson).forEach((option) => {
if (infoPlistJson[option] === undefined) {
delete infoPlistJson[option];
}
});

await fs.writeFile(infoPlistPath, plist.build(infoPlistJson));
await writeFile(infoPlistPath, plist.build(infoPlistJson));
} catch (error) {
log.error(error);
}
Expand Down
3 changes: 0 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { getFiles } from "./util/files.js";
import { getVersionManifest } from "./util/versionManifest.js";
import { parse } from "./util/parse.js";
import { validate } from "./util/validate.js";
import { xattr } from "./util/xattr.js";

import { log, setLogLevel } from "./log.js";

Expand Down Expand Up @@ -182,8 +181,6 @@ const nwbuild = async (options) => {
}
}

await xattr(options.platform, options.arch, nwDir);

// Downloading binaries is required for run and build modes
// If mode is get, exit function since we have gotten the binaries
if (options.mode === "get") {
Expand Down
2 changes: 1 addition & 1 deletion src/util/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export const parse = async (options, pkg) => {

options.app = options.app ?? {};
options.app.name = options.app.name ?? pkg.name;
options.app.icon = options.app.icon ?? undefined;

// TODO(#737): move this out
if (options.platform === "linux") {
// linux desktop entry file configurations options
options.app.genericName = options.app.genericName ?? undefined;
options.app.noDisplay = options.app.noDisplay ?? undefined;
options.app.comment = options.app.comment ?? undefined;
options.app.icon = options.app.icon ?? undefined;
options.app.hidden = options.app.hidden ?? undefined;
options.app.onlyShowIn = options.app.onlyShowIn ?? undefined;
options.app.notShowIn = options.app.notShowIn ?? undefined;
Expand Down
30 changes: 0 additions & 30 deletions src/util/xattr.js

This file was deleted.

Binary file added test/fixture/app/icon.icns
Binary file not shown.
Binary file modified test/fixture/app/icon.ico
Binary file not shown.
Binary file added test/fixture/app/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions test/fixture/app/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"name": "nwapp",
"main": "index.html",
"version": "0.0.0",
"window": {
"icon": "icon.ico"
}
"version": "0.0.0"
}
11 changes: 8 additions & 3 deletions test/fixture/demo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import nwbuild from "nw-builder";

await nwbuild({
mode: "run",
version: "0.72.0",
mode: "build",
version: "latest",
srcDir: "app",
platform: "win",
platform: "osx",
arch: "arm64",
downloadUrl: "https://github.com/corwin-of-amber/nw.js/releases/download",
manifestUrl:
"https://raw.githubusercontent.com/nwutils/nw-builder/main/src/util/osx.arm.versions.json",
outDir: "out",
glob: false,
app: {
name: "demo",
icon: "app/icon.icns",
},
});

0 comments on commit eba33cc

Please sign in to comment.