From 360194c627147583b2af26efacad43354db0f9c1 Mon Sep 17 00:00:00 2001 From: antelle Date: Mon, 1 Jun 2020 16:45:18 +0200 Subject: [PATCH] loading native modules from updated desktop archives --- desktop/app.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/desktop/app.js b/desktop/app.js index dd9b5b74..93b00192 100644 --- a/desktop/app.js +++ b/desktop/app.js @@ -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; }