Skip to content

Commit d0e5f91

Browse files
authored
Merge pull request TurboWarp#532 from TurboWarp/update-binaries
Update NW.js and Electron
2 parents 00c7f5b + 3d7a9bc commit d0e5f91

8 files changed

Lines changed: 1669 additions & 20 deletions

File tree

.github/workflows/generate-electron-binaries.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ on:
55

66
jobs:
77
generate:
8-
runs-on: macos-latest
8+
strategy:
9+
matrix:
10+
os: [macos-latest, windows-latest]
11+
12+
runs-on: ${{ matrix.os }}
913

1014
steps:
1115
- uses: actions/checkout@v3
@@ -28,3 +32,15 @@ jobs:
2832
with:
2933
name: electron-macos
3034
path: electron-bin/temp/macos/*.zip
35+
36+
- name: Generate Windows
37+
if: runner.os == 'Windows'
38+
run: |
39+
cd electron-bin
40+
node generate-windows.js
41+
- name: Upload Windows
42+
if: runner.os == 'Windows'
43+
uses: actions/upload-artifact@v3
44+
with:
45+
name: electron-windows
46+
path: electron-bin/temp/windows/*.zip

electron-bin/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
These are scripts used to generate Electron binaries.
1+
# Electron binaries
2+
3+
These are scripts used to generate the Electron binaries used by the packager.
4+
5+
Electron version is defined in version.json.
26

37
## macOS
48

@@ -11,3 +15,19 @@ node generate-macos.js
1115
```
1216

1317
Output will be stored in temp/macos.
18+
19+
## Windows
20+
21+
For Windows, we change the icon of the executable to avoid misusing the Electron trademark.
22+
23+
Script should work on non-Windows systems if Wine is installed.
24+
25+
```
26+
node generate-windows.js
27+
```
28+
29+
Output will be stored in temp/windows.
30+
31+
## Linux
32+
33+
On Linux we use the exact binaries provided by the Electron project.

electron-bin/generate-windows.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const {downloadArtifact} = require('@electron/get');
2+
const rcedit = require('rcedit');
3+
const path = require('path');
4+
const fs = require('fs');
5+
const zlib = require('zlib');
6+
const rimraf = require('rimraf');
7+
const extractZip = require('extract-zip');
8+
const archiver = require('archiver');
9+
const crypto = require('crypto');
10+
11+
const {electronVersion} = require('./version.json');
12+
13+
const newIconPath = path.join(__dirname, '..', 'src', 'packager', 'images', 'default-icon.ico');
14+
15+
const download = (arch) => downloadArtifact({
16+
version: electronVersion,
17+
artifactName: 'electron',
18+
platform: 'win32',
19+
arch
20+
});
21+
22+
const getTempFile = (name) => path.join(__dirname, 'temp', 'windows', name);
23+
24+
const extract = async (from, name) => {
25+
const to = getTempFile(name);
26+
fs.mkdirSync(path.join(to, '..'), {recursive: true});
27+
rimraf.sync(to);
28+
await extractZip(from, {dir: to});
29+
return to;
30+
};
31+
32+
const compress = (from, to) => new Promise((resolve, reject) => {
33+
const archive = archiver('zip', {
34+
zlib: {
35+
level: zlib.constants.Z_BEST_COMPRESSION
36+
}
37+
});
38+
const outStream = fs.createWriteStream(to);
39+
outStream.on('error', (err) => reject(err));
40+
outStream.on('close', () => resolve());
41+
archive.directory(from, false);
42+
archive.pipe(outStream);
43+
archive.finalize();
44+
});
45+
46+
const run = async (arch) => {
47+
console.log(`Downloading ${arch}`);
48+
const downloadPath = await download(arch);
49+
50+
console.log('Extracting');
51+
const extractedPath = await extract(downloadPath, arch);
52+
53+
console.log('Running rcedit');
54+
const executablePath = path.join(extractedPath, 'electron.exe');
55+
await rcedit(executablePath, {
56+
icon: newIconPath,
57+
// Replace Electron's version with something generic
58+
'version-string': '1.0.0',
59+
'file-version': '1.0.0',
60+
'product-version': '1.0.0'
61+
});
62+
63+
console.log('Compressing');
64+
const outputPath = getTempFile(`electron-v${electronVersion}-win32-${arch}.zip`);
65+
await compress(extractedPath, outputPath);
66+
console.log(`Output: ${outputPath}`);
67+
68+
const outputFileData = fs.readFileSync(outputPath);
69+
console.log(`Size: ${outputFileData.length} bytes`)
70+
71+
const sha256 = crypto.createHash('sha256').update(outputFileData).digest('hex');
72+
console.log(`SHA-256: ${sha256}`);
73+
};
74+
75+
run('ia32')
76+
.then(() => run('x64'))
77+
.catch((err) => {
78+
console.error(err);
79+
process.exit(1);
80+
});

0 commit comments

Comments
 (0)