Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,34 @@ module.exports = {
}
},

packageAfterCopy(_forgeConfig, buildPath, _electronVersion, platform, arch) {
// koffi is only loaded on Windows (see src/app/nativeWindows.ts), so there is no
// reason to ship the native module on other platforms.
if (platform !== 'win32') {
return
}

// koffi (native FFI) is kept out of the webpack bundle (see webpack.main.config.js externals),
// so webpack does not copy it into the package. Copy it into the packaged app's node_modules
// so require('koffi') resolves at runtime. koffi ships a prebuilt binary for every platform
// under build/koffi/<platform>_<arch>/koffi.node — copy only the one we are packaging to keep
// the app lean. The .node is unpacked from the asar archive via packagerConfig.asar.unpack.
const koffiSource = path.join(__dirname, 'node_modules', 'koffi')
const koffiTarget = path.join(buildPath, 'node_modules', 'koffi')
const prebuiltsPrefix = `build${path.sep}koffi${path.sep}`
const keepTriplet = `${platform}_${arch}`
fs.cpSync(koffiSource, koffiTarget, {
recursive: true,
filter: (source) => {
const relative = path.relative(koffiSource, source)
if (relative.startsWith(prebuiltsPrefix)) {
return relative.slice(prebuiltsPrefix.length).split(path.sep)[0] === keepTriplet
}
return true
},
})
},

postStart() {
console.log(`Started with built-in Nextcloud Talk v${talkPackageJson.version} on path: ${TALK_PATH}`)
},
Expand Down Expand Up @@ -207,7 +235,10 @@ module.exports = {
name: BUILD_CONFIG.applicationName,
icon: path.join(__dirname, './img/icons/icon'),
appCopyright: BUILD_CONFIG.copyright,
asar: true,
// Unpack the koffi native FFI module (its prebuilt .node cannot run from inside the asar archive)
asar: {
unpack: '**/node_modules/koffi/**',
},

// Windows
win32metadata: {
Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"core-js": "^3.49.0",
"electron-squirrel-startup": "^1.0.1",
"howler": "^2.2.4",
"koffi": "^2.16.3",
"mri": "^1.2.0",
"pinia": "^4.0.2",
"semver": "^7.8.5",
Expand Down
Loading