-
Notifications
You must be signed in to change notification settings - Fork 0
/
fiftLib.js
34 lines (26 loc) · 1.09 KB
/
fiftLib.js
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
const ffi = require('ffi');
const path = require('path');
const ArrayType = require('ref-array');
const StringArray = ArrayType('CString');
const { platform } = process;
let fiftlibLoc = null;
// Hack for electron asar package
const basePath = __dirname.replace('app.asar', 'app.asar.unpacked');
if (platform === 'darwin') {
fiftlibLoc = path.join(basePath, '/lib/libfiftlib.dylib');
} else if (platform === 'win32') {
fiftlibLoc = path.join(basePath, '/lib/fiftlib.dll');
// add ./lib to dll directory (for windows we need linked libraries)
process.env.PATH = process.env.PATH === '' ? path.join(basePath, '/lib') : `${process.env.PATH};${path.join(basePath, '/lib')}`;
} else if (platform === 'linux') {
fiftlibLoc = path.join(basePath, '/lib/libfiftlib.so');
} else {
throw new Error('unsupported platform for libfift');
}
const init = () => {
const callback = ffi.Function('void', [StringArray, 'CString']);
return ffi.Library(fiftlibLoc, {
run: ['void', ['CString', 'CString', StringArray, 'int', StringArray, 'int', StringArray, 'int', callback]],
});
};
module.exports = init;