loading native modules from updated desktop archives

This commit is contained in:
antelle 2020-06-01 16:45:18 +02:00
parent 21768b1b59
commit 360194c627
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
1 changed files with 13 additions and 1 deletions

View File

@ -731,10 +731,22 @@ function reportStartProfile() {
function reqNative(mod) {
const fileName = `${mod}-${process.platform}-${process.arch}.node`;
const binding = require(`@keeweb/keeweb-native-modules/${fileName}`);
const mainAsarPath = process.mainModule.path;
const latestAsarPath = __dirname;
const pathInsideAsar = `node_modules/@keeweb/keeweb-native-modules/${fileName}`;
let fullPath = path.join(latestAsarPath, pathInsideAsar);
if (!fs.existsSync(fullPath)) {
fullPath = path.join(mainAsarPath, pathInsideAsar);
}
const binding = require(fullPath);
if (mod === 'usb') {
usbBinding = initUsb(binding);
}
return binding;
}