Skip to content

Commit

Permalink
chore(bld): migrate from rcedit with resedit (#1094)
Browse files Browse the repository at this point in the history
* Remove Wine installation warning

---------

Co-authored-by: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com>
Co-authored-by: The Jared Wilcurt <TheJaredWilcurt@users.noreply.github.com>
  • Loading branch information
3 people authored May 22, 2024
1 parent 715097f commit 03a55b9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 104 deletions.
111 changes: 30 additions & 81 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
Expand Up @@ -65,7 +65,7 @@
"glob": "^10.3.15",
"node-gyp": "^10.1.0",
"plist": "^3.1.0",
"rcedit": "^4.0.1",
"resedit": "^2.0.2",
"semver": "^7.6.2",
"tar": "^7.1.0",
"yargs": "^17.7.2",
Expand Down
52 changes: 30 additions & 22 deletions src/bld.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import fsm from "node:fs/promises";
import process from "node:process";

import compressing from "compressing";
import rcedit from "rcedit";
import * as resedit from "resedit";
// pe-library is a direct dependency of resedit
import * as peLibrary from 'pe-library';
import plist from "plist";

import util from "./util.js"
Expand Down Expand Up @@ -103,7 +105,7 @@ import util from "./util.js"
*
* @async
* @function
* @param {BuildOptions} options - Build options
* @param {BuildOptions} options - Build options
* @return {Promise<void>}
*/
async function bld({
Expand Down Expand Up @@ -311,28 +313,34 @@ const setWinConfig = async ({ app, outDir }) => {
}
});

const rcEditOptions = {
"file-version": app.version,
"product-version": app.version,
"version-string": versionString,
};

const outDirAppExe = path.resolve(outDir, `${app.name}.exe`);
await fsm.rename(path.resolve(outDir, "nw.exe"), outDirAppExe);
const exe = peLibrary.NtExecutable.from(await fsm.readFile(outDirAppExe));
const res = peLibrary.NtExecutableResource.from(exe);
if (app.icon) {
rcEditOptions.icon = app.icon;
}

try {
const outDirAppExe = path.resolve(outDir, `${app.name}.exe`);
await fsm.rename(path.resolve(outDir, "nw.exe"), outDirAppExe);
await rcedit(outDirAppExe, rcEditOptions);
} catch (error) {
if (process.platform !== "win32") {
console.warn(
"Ensure WINE is installed or build your application on Windows platform",
);
}
throw error;
const iconBuffer = await fsm.readFile(path.resolve(app.icon));
const iconFile = resedit.Data.IconFile.from(iconBuffer);
// English (United States)
const EN_US = 1033;
resedit.Resource.IconGroupEntry.replaceIconsForResource(
res.entries,
// This is the name of the icon group nw.js uses that gets shown in file exlorers
'IDR_MAINFRAME',
EN_US,
iconFile.icons.map(i => i.data)
);
}
const [vi] = resedit.Resource.VersionInfo.fromEntries(res.entries);
const [major, minor, patch] = app.version.split(".");
vi.setFileVersion(major, minor, patch, 0, EN_US);
vi.setStringValues({
lang: EN_US,
codepage: 1200
}, versionString);
vi.outputToResourceEntries(res.entries);
res.outputResource(exe);
const outBuffer = Buffer.from(exe.generate());
await fsm.writeFile(outDirAppExe, outBuffer);
};

const setOsxConfig = async ({ outDir, app }) => {
Expand Down

0 comments on commit 03a55b9

Please sign in to comment.