hunter-open-sdk 2.0.0-beta.20 → 2.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/abilities/activate/index.js +5 -2
- package/lib/abilities/erase/index.js +5 -2
- package/lib/abilities/getGeneralReport/index.js +15 -4
- package/lib/abilities/getSaaSReport/index.js +5 -2
- package/lib/abilities/installApp/index.js +5 -2
- package/lib/abilities/reboot/index.js +5 -2
- package/lib/abilities/shutdown/index.js +5 -2
- package/lib/abilities/skip/index.js +5 -2
- package/lib/events/driver/winDriver.js +1 -1
- package/lib/index.js +2 -1
- package/lib/utils/utils.global.js +1 -1
- package/lib/utils/utils.initDll.js +5 -5
- package/lib/utils/utils.path.js +39 -5
- package/lib/utils/utils.worker.js +3 -3
- package/package.json +1 -1
- package/lib/events/driver/service.js +0 -36
|
@@ -34,15 +34,18 @@ class Activate {
|
|
|
34
34
|
}
|
|
35
35
|
initWorker() {
|
|
36
36
|
if (!this.worker) {
|
|
37
|
-
const workerPath = new _url.default.URL('file://' + (0, _utils2.
|
|
37
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
|
|
38
38
|
this.worker = new _webWorker.default(workerPath, {
|
|
39
39
|
type: 'module'
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
let entity = null;
|
|
45
45
|
function activate(params, callback) {
|
|
46
|
+
if (!entity) {
|
|
47
|
+
entity = new Activate();
|
|
48
|
+
}
|
|
46
49
|
const payload = (0, _utils.parsePayload)(params);
|
|
47
50
|
entity.exec(payload, callback);
|
|
48
51
|
}
|
|
@@ -34,15 +34,18 @@ class Erase {
|
|
|
34
34
|
}
|
|
35
35
|
initWorker() {
|
|
36
36
|
if (!this.worker) {
|
|
37
|
-
const workerPath = new _url.default.URL('file://' + (0, _utils2.
|
|
37
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
|
|
38
38
|
this.worker = new _webWorker.default(workerPath, {
|
|
39
39
|
type: 'module'
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
let entity = null;
|
|
45
45
|
function erase(params, callback) {
|
|
46
|
+
if (!entity) {
|
|
47
|
+
entity = new Erase();
|
|
48
|
+
}
|
|
46
49
|
const payload = (0, _utils.parsePayload)(params);
|
|
47
50
|
entity.exec(payload, callback);
|
|
48
51
|
}
|
|
@@ -21,7 +21,7 @@ class WorkerPool {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
_createWorker() {
|
|
24
|
-
const workerPath = new _url.default.URL('file://' + (0, _utils2.
|
|
24
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
|
|
25
25
|
return new _webWorker.default(workerPath, {
|
|
26
26
|
type: 'module'
|
|
27
27
|
});
|
|
@@ -53,12 +53,23 @@ class WorkerPool {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
let pool =
|
|
56
|
+
let pool = null;
|
|
57
57
|
function getGeneralReport(params, callback, options = {}) {
|
|
58
58
|
const cb = typeof callback === 'function' ? callback : _utils3.defaultCallback;
|
|
59
59
|
const payload = (0, _utils.parsePayload)(params);
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
const {
|
|
61
|
+
useMultiWorker = false,
|
|
62
|
+
poolSize = DEFAULT_POOL_SIZE
|
|
63
|
+
} = options;
|
|
64
|
+
if (!useMultiWorker) {
|
|
65
|
+
if (!pool || pool.poolSize !== 1) {
|
|
66
|
+
pool = new WorkerPool(1);
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
const targetSize = poolSize;
|
|
70
|
+
if (!pool || pool.poolSize !== targetSize) {
|
|
71
|
+
pool = new WorkerPool(targetSize);
|
|
72
|
+
}
|
|
62
73
|
}
|
|
63
74
|
pool.exec(payload, cb);
|
|
64
75
|
}
|
|
@@ -34,15 +34,18 @@ class GetSaaSReport {
|
|
|
34
34
|
}
|
|
35
35
|
initWorker() {
|
|
36
36
|
if (!this.worker) {
|
|
37
|
-
const workerPath = new _url.default.URL('file://' + (0, _utils2.
|
|
37
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
|
|
38
38
|
this.worker = new _webWorker.default(workerPath, {
|
|
39
39
|
type: 'module'
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
let entity = null;
|
|
45
45
|
function getSaaSReport(params, callback) {
|
|
46
|
+
if (!entity) {
|
|
47
|
+
entity = new GetSaaSReport();
|
|
48
|
+
}
|
|
46
49
|
const payload = (0, _utils.parsePayload)(params);
|
|
47
50
|
entity.exec(payload, callback);
|
|
48
51
|
}
|
|
@@ -34,15 +34,18 @@ class InstallApp {
|
|
|
34
34
|
}
|
|
35
35
|
initWorker() {
|
|
36
36
|
if (!this.worker) {
|
|
37
|
-
const workerPath = new _url.default.URL('file://' + (0, _utils2.
|
|
37
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
|
|
38
38
|
this.worker = new _webWorker.default(workerPath, {
|
|
39
39
|
type: 'module'
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
let entity = null;
|
|
45
45
|
function installApp(params, callback) {
|
|
46
|
+
if (!entity) {
|
|
47
|
+
entity = new InstallApp();
|
|
48
|
+
}
|
|
46
49
|
const payload = (0, _utils.parsePayload)(params);
|
|
47
50
|
entity.exec(payload, callback);
|
|
48
51
|
}
|
|
@@ -34,15 +34,18 @@ class Reboot {
|
|
|
34
34
|
}
|
|
35
35
|
initWorker() {
|
|
36
36
|
if (!this.worker) {
|
|
37
|
-
const workerPath = new _url.default.URL('file://' + (0, _utils2.
|
|
37
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
|
|
38
38
|
this.worker = new _webWorker.default(workerPath, {
|
|
39
39
|
type: "module"
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
let entity = null;
|
|
45
45
|
function reboot(params, callback) {
|
|
46
|
+
if (!entity) {
|
|
47
|
+
entity = new Reboot();
|
|
48
|
+
}
|
|
46
49
|
const payload = (0, _utils.parsePayload)(params);
|
|
47
50
|
entity.exec(payload, callback);
|
|
48
51
|
}
|
|
@@ -34,15 +34,18 @@ class Shutdown {
|
|
|
34
34
|
}
|
|
35
35
|
initWorker() {
|
|
36
36
|
if (!this.worker) {
|
|
37
|
-
const workerPath = new _url.default.URL('file://' + (0, _utils2.
|
|
37
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
|
|
38
38
|
this.worker = new _webWorker.default(workerPath, {
|
|
39
39
|
type: "module"
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
let entity = null;
|
|
45
45
|
function shutdown(params, callback) {
|
|
46
|
+
if (!entity) {
|
|
47
|
+
entity = new Shutdown();
|
|
48
|
+
}
|
|
46
49
|
const payload = (0, _utils.parsePayload)(params);
|
|
47
50
|
entity.exec(payload, callback);
|
|
48
51
|
}
|
|
@@ -34,15 +34,18 @@ class Skip {
|
|
|
34
34
|
}
|
|
35
35
|
initWorker() {
|
|
36
36
|
if (!this.worker) {
|
|
37
|
-
const workerPath = new _url.default.URL('file://' + (0, _utils2.
|
|
37
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
|
|
38
38
|
this.worker = new _webWorker.default(workerPath, {
|
|
39
39
|
type: 'module'
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
let entity = null;
|
|
45
45
|
function skip(params, callback) {
|
|
46
|
+
if (!entity) {
|
|
47
|
+
entity = new Skip();
|
|
48
|
+
}
|
|
46
49
|
const payload = (0, _utils.parsePayload)(params);
|
|
47
50
|
entity.exec(payload, callback);
|
|
48
51
|
}
|
package/lib/index.js
CHANGED
|
@@ -15,12 +15,13 @@ var _reboot = require("./abilities/reboot");
|
|
|
15
15
|
var _shutdown = require("./abilities/shutdown");
|
|
16
16
|
var _installApp = require("./abilities/installApp");
|
|
17
17
|
const Sentry = require('@sentry/browser');
|
|
18
|
+
|
|
19
|
+
// 初始化 Sentry 用于错误捕获
|
|
18
20
|
Sentry.init({
|
|
19
21
|
dsn: 'https://8a5296c59083430fbac0756f56ddbf5d@sentry.zhuanzhuan.com/2300',
|
|
20
22
|
tracesSampleRate: 1.0
|
|
21
23
|
});
|
|
22
24
|
console.log('Sentry initialized');
|
|
23
|
-
// 初始化
|
|
24
25
|
var _default = exports.default = {
|
|
25
26
|
registerEvent: _eventManager.registerEvent,
|
|
26
27
|
unregisterEvent: _eventManager.unregisterEvent,
|
|
@@ -122,7 +122,7 @@ const callHunterInspectionKit = (methodName, ...args) => {
|
|
|
122
122
|
*/
|
|
123
123
|
exports.callHunterInspectionKit = callHunterInspectionKit;
|
|
124
124
|
function abilityCallKit(cmd, payload) {
|
|
125
|
-
console.log(`调用【${cmd}】方法,参数:`, payload);
|
|
125
|
+
console.log(`调用【${cmd}】方法,参数:`, JSON.stringify(payload));
|
|
126
126
|
const {
|
|
127
127
|
biz = "",
|
|
128
128
|
params
|
|
@@ -21,21 +21,21 @@ const initHunterInspectionKit = () => {
|
|
|
21
21
|
let dllPath;
|
|
22
22
|
|
|
23
23
|
// 读取本地sdk的version
|
|
24
|
-
const versionPath =
|
|
24
|
+
const versionPath = (0, _utils3.getPathWithLocalResource)('version.online');
|
|
25
25
|
const version = _fs.default.readFileSync(versionPath, 'utf-8').trim();
|
|
26
26
|
if ((0, _utils.isMac)()) {
|
|
27
27
|
if ((0, _utils.isArm64)()) {
|
|
28
|
-
dllPath =
|
|
28
|
+
dllPath = (0, _utils3.getPathWithLocalResource)(`mac/libinspectionkit_arm64_${version}.dylib`);
|
|
29
29
|
}
|
|
30
30
|
if ((0, _utils.isAmd64)()) {
|
|
31
|
-
dllPath =
|
|
31
|
+
dllPath = (0, _utils3.getPathWithLocalResource)(`mac/libinspectionkit_amd64_${version}.dylib`);
|
|
32
32
|
}
|
|
33
33
|
} else {
|
|
34
|
-
dllPath =
|
|
34
|
+
dllPath = (0, _utils3.getPathWithLocalResource)(`dll/libinspectionkit_x64_${version}.dll`);
|
|
35
35
|
}
|
|
36
36
|
if (!(0, _utils.isDev)()) {
|
|
37
37
|
// 如果是生产模式 则替换app.asar 路径 为了在生产调用dll
|
|
38
|
-
dllPath = (0, _utils3.
|
|
38
|
+
dllPath = (0, _utils3.convertPathWithCurrentEnv)(dllPath);
|
|
39
39
|
}
|
|
40
40
|
const dllLib = _koffi.default.load(dllPath);
|
|
41
41
|
const dllKit = {
|
package/lib/utils/utils.path.js
CHANGED
|
@@ -3,29 +3,63 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.convertPathWithCurrentEnv = convertPathWithCurrentEnv;
|
|
7
7
|
exports.getCurrentNodePath = getCurrentNodePath;
|
|
8
8
|
exports.getPathWithCWD = getPathWithCWD;
|
|
9
|
+
exports.getPathWithElectornResource = getPathWithElectornResource;
|
|
10
|
+
exports.getPathWithLocalResource = getPathWithLocalResource;
|
|
9
11
|
var _path = _interopRequireDefault(require("path"));
|
|
10
12
|
var _process = _interopRequireDefault(require("process"));
|
|
11
13
|
var _utils = require("./utils.env");
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
15
|
/**
|
|
14
16
|
* 当前环境地址转换
|
|
15
|
-
* @param {*}
|
|
17
|
+
* @param {*} dirPath 目录路径
|
|
18
|
+
* @param {*} filePath 文件路径,默认为空字符串
|
|
16
19
|
* @returns
|
|
17
20
|
*/
|
|
18
|
-
function
|
|
21
|
+
function convertPathWithCurrentEnv(dirPath, filePath = '') {
|
|
19
22
|
let fixPath = dirPath;
|
|
20
23
|
if (!(0, _utils.isDev)()) {
|
|
21
|
-
fixPath = fixPath.replace('/app.asar/', '/app.asar.unpacked/').replace(
|
|
24
|
+
fixPath = fixPath.replace('/app.asar/', '/app.asar.unpacked/').replace('\\app.asar\\', '\\app.asar.unpacked\\');
|
|
22
25
|
}
|
|
23
|
-
return _path.default.
|
|
26
|
+
return _path.default.join(fixPath, filePath);
|
|
24
27
|
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 当前项目resources目录地址转换
|
|
31
|
+
* @param {*} dirPath
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
function getPathWithLocalResource(dirPath) {
|
|
35
|
+
const resourcesPath = _path.default.join(__dirname, '../resources');
|
|
36
|
+
return _path.default.join(resourcesPath, dirPath);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Electron资源目录地址转换
|
|
41
|
+
* @param {*} dirPath
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
function getPathWithElectornResource(dirPath) {
|
|
45
|
+
console.log('getPathWithElectornResource resourcesPath => ', _process.default.type || 'node', _process.default.resourcesPath);
|
|
46
|
+
return _path.default.join(_process.default.resourcesPath || '', dirPath);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 当前工作目录地址转换
|
|
51
|
+
* @param {*} dirPath
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
25
54
|
function getPathWithCWD(dirPath) {
|
|
26
55
|
const cwd = _process.default.cwd();
|
|
27
56
|
return _path.default.join(cwd, dirPath);
|
|
28
57
|
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 获取当前nodePath环境变量
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
29
63
|
function getCurrentNodePath() {
|
|
30
64
|
return _process.default.env.NODE_PATH || '';
|
|
31
65
|
}
|
|
@@ -8,12 +8,12 @@ exports.initWorkerNodePath = initWorkerNodePath;
|
|
|
8
8
|
const path = require('path');
|
|
9
9
|
const _module = require('module');
|
|
10
10
|
const {
|
|
11
|
-
|
|
11
|
+
getPathWithElectornResource,
|
|
12
12
|
getCurrentNodePath
|
|
13
13
|
} = require("./utils.path");
|
|
14
14
|
function getAsarNodePath() {
|
|
15
|
-
const asarRoot =
|
|
16
|
-
const unpackedRoot =
|
|
15
|
+
const asarRoot = getPathWithElectornResource('app.asar');
|
|
16
|
+
const unpackedRoot = getPathWithElectornResource('app.asar.unpacked');
|
|
17
17
|
const nodeModulesPaths = [path.join(asarRoot, 'node_modules'), path.join(unpackedRoot, 'node_modules')];
|
|
18
18
|
return nodeModulesPaths.join(path.delimiter);
|
|
19
19
|
}
|
package/package.json
CHANGED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _utils = require("../../utils/utils.env");
|
|
8
|
-
var _command = require("./command");
|
|
9
|
-
var _winDriver = require("./winDriver");
|
|
10
|
-
const path = require('path');
|
|
11
|
-
class Service {
|
|
12
|
-
// constructor () {}
|
|
13
|
-
setup(mainWindow) {
|
|
14
|
-
console.log('Service setup');
|
|
15
|
-
if ((0, _utils.isMac)()) {
|
|
16
|
-
if ((0, _utils.isDev)()) {
|
|
17
|
-
(0, _command.command)(path.join(process.cwd(), './extraResources/ightools'));
|
|
18
|
-
}
|
|
19
|
-
if ((0, _utils.isProd)()) {
|
|
20
|
-
(0, _command.command)('nohup ' + path.join(process.resourcesPath, './extraResources/ightools') + ' > /dev/null 2>&1 & > ' + path.join(process.resourcesPath, './log/ightools.log'));
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if ((0, _utils.isWin)()) {
|
|
24
|
-
(0, _winDriver.checkHasDriver)().then(res => {
|
|
25
|
-
console.log('------------checkHasDriver', res);
|
|
26
|
-
if (res) {
|
|
27
|
-
mainWindow.webContents.send('checkDriver', true);
|
|
28
|
-
} else {
|
|
29
|
-
mainWindow.webContents.send('checkDriver', false);
|
|
30
|
-
(0, _winDriver.downloadDriver)(mainWindow);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
var _default = exports.default = Service;
|