-
-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathelectron-builder.win-arm64.js
More file actions
105 lines (92 loc) · 2.71 KB
/
Copy pathelectron-builder.win-arm64.js
File metadata and controls
105 lines (92 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const fs = require("fs");
const path = require("path");
const baseBuild = require("./package.json").build;
const OFFICIAL_ELECTRON_VERSION = "39.2.7";
const PE_MACHINE_ARM64 = 0xaa64;
const ELECTRON_ASIO_BINARY_PATH = "native-modules/electron-asio/build/Release";
const WINDOW_AUDIO_PATH = "native-modules/window-audio-capture";
const WINDOW_AUDIO_BINARY_PATH = path.join(
__dirname,
WINDOW_AUDIO_PATH,
"build",
"Release",
"window_audio_capture.node",
);
const skipWindowAudio = process.env.WINDOW_AUDIO_CAPTURE_SKIP === "1";
const includeWindowAudio =
!skipWindowAudio && isArm64Pe(WINDOW_AUDIO_BINARY_PATH);
if (!skipWindowAudio && !includeWindowAudio) {
console.warn(
"[windows-arm64] ARM64 window audio module not found; packaging without process/window audio capture.",
);
}
function shouldExcludeNativeFileSet(fileSet) {
if (!fileSet || typeof fileSet !== "object") {
return false;
}
if (fileSet.from === ELECTRON_ASIO_BINARY_PATH) {
return true;
}
return (
!includeWindowAudio &&
typeof fileSet.from === "string" &&
fileSet.from.startsWith(WINDOW_AUDIO_PATH)
);
}
function isArm64Pe(filePath) {
if (!fs.existsSync(filePath)) {
return false;
}
try {
const data = fs.readFileSync(filePath);
if (data.length < 0x40 || data.toString("ascii", 0, 2) !== "MZ") {
return false;
}
const peOffset = data.readUInt32LE(0x3c);
return (
peOffset + 6 <= data.length &&
data.toString("ascii", peOffset, peOffset + 4) === "PE\0\0" &&
data.readUInt16LE(peOffset + 4) === PE_MACHINE_ARM64
);
} catch {
return false;
}
}
module.exports = {
...baseBuild,
// Windows x64 deliberately continues to use the custom Electron build from
// package.json. This standalone config is only loaded by build:win-arm64.
electronVersion: OFFICIAL_ELECTRON_VERSION,
electronDownload: {
mirror: "https://github.com/electron/electron/releases/download/",
customDir: `v${OFFICIAL_ELECTRON_VERSION}`,
},
// ASIO currently links a prebuilt x64 PortAudio library. Keep its JS API in
// the ARM64 package so feature detection remains graceful, but never package
// the incompatible native addon or DLL.
files: baseBuild.files.filter(
(fileSet) => !shouldExcludeNativeFileSet(fileSet),
),
win: {
...baseBuild.win,
target: [
{
target: "nsis",
arch: ["arm64"],
},
{
target: "portable",
arch: ["arm64"],
},
],
},
nsis: {
...baseBuild.nsis,
artifactName: "elecap-${version}-win-arm64-setup.${ext}",
},
portable: {
...baseBuild.portable,
artifactName: "elecap-${version}-win-arm64-portable.${ext}",
},
afterAllArtifactBuild: "./afterPackArm64.js",
};