hunter-open-sdk 0.0.12 → 0.0.14
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/events/driver/winDriver.js +12 -4
- package/lib/getGeneralReport/index.js +2 -1
- package/lib/registerEvent/index.js +96 -43
- package/lib/resources/dll/{libinspectionkit_x64_0.0.5.dll → libinspectionkit_x64_0.0.6.dll} +0 -0
- package/lib/resources/mac/{libinspectionkit_amd64_0.0.5.dylib → libinspectionkit_amd64_0.0.6.dylib} +0 -0
- package/lib/resources/mac/{libinspectionkit_arm64_0.0.5.dylib → libinspectionkit_arm64_0.0.6.dylib} +0 -0
- package/lib/resources/version.online +1 -1
- package/lib/utils/utils.global.js +102 -0
- package/lib/utils/utils.initDll.js +3 -2
- package/package.json +1 -1
|
@@ -68,10 +68,13 @@ var checkCache = function checkCache() {
|
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
// 轮询检测是否存在进程
|
|
71
|
+
var processCheckTimer = null;
|
|
71
72
|
var checkProcessTimer = function checkProcessTimer() {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
// 清除之前的定时器
|
|
74
|
+
if (processCheckTimer) {
|
|
75
|
+
clearTimeout(processCheckTimer);
|
|
76
|
+
}
|
|
77
|
+
processCheckTimer = setTimeout( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
75
78
|
var hasDriver;
|
|
76
79
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
77
80
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -84,9 +87,14 @@ var checkProcessTimer = function checkProcessTimer() {
|
|
|
84
87
|
_context.next = 6;
|
|
85
88
|
break;
|
|
86
89
|
}
|
|
87
|
-
|
|
90
|
+
// 检测到驱动,清除定时器并返回
|
|
91
|
+
if (processCheckTimer) {
|
|
92
|
+
clearTimeout(processCheckTimer);
|
|
93
|
+
processCheckTimer = null;
|
|
94
|
+
}
|
|
88
95
|
return _context.abrupt("return");
|
|
89
96
|
case 6:
|
|
97
|
+
// 继续轮询检测
|
|
90
98
|
checkProcessTimer();
|
|
91
99
|
case 7:
|
|
92
100
|
case "end":
|
|
@@ -4,8 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _utils = require("../utils/utils.global");
|
|
7
8
|
var GetGeneralReport = function GetGeneralReport(params, callBack) {
|
|
8
|
-
var reportRes =
|
|
9
|
+
var reportRes = (0, _utils.callHunterInspectionKit)('InspectionKit', params, 'saas_report', params);
|
|
9
10
|
if (reportRes) {
|
|
10
11
|
var reportResObj = JSON.parse(reportRes);
|
|
11
12
|
var Code = reportResObj.Code,
|
|
@@ -10,6 +10,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
10
10
|
var _utils = require("../utils/utils");
|
|
11
11
|
var _utils2 = require("../utils/utils.initDll");
|
|
12
12
|
var _winDriver = require("../events/driver/winDriver");
|
|
13
|
+
var _utils3 = require("../utils/utils.global");
|
|
13
14
|
var usbmux = require('usbmux');
|
|
14
15
|
var path = require('path');
|
|
15
16
|
var request = require("request");
|
|
@@ -18,6 +19,10 @@ var fs = require('fs');
|
|
|
18
19
|
// saas回调
|
|
19
20
|
var saasCallBack;
|
|
20
21
|
|
|
22
|
+
// 驱动安装状态
|
|
23
|
+
var isDriverInstalling = false;
|
|
24
|
+
var isDriverReady = false;
|
|
25
|
+
|
|
21
26
|
// 初始化dll
|
|
22
27
|
(0, _utils2.HunterInspectionKit)();
|
|
23
28
|
|
|
@@ -60,7 +65,7 @@ var DevicePair = /*#__PURE__*/function () {
|
|
|
60
65
|
cmd: 'trust_status',
|
|
61
66
|
udid: udid
|
|
62
67
|
});
|
|
63
|
-
devicePair =
|
|
68
|
+
devicePair = (0, _utils3.callHunterInspectionKit)('TheForceKit', JSON.stringify(paramsObj));
|
|
64
69
|
if (!devicePair) {
|
|
65
70
|
_context.next = 15;
|
|
66
71
|
break;
|
|
@@ -163,7 +168,7 @@ var updateDllFileCheck = function updateDllFileCheck() {
|
|
|
163
168
|
label: (0, _utils.isWin)() ? 'Windows' : 'Mac',
|
|
164
169
|
params: {}
|
|
165
170
|
};
|
|
166
|
-
var updateRes =
|
|
171
|
+
var updateRes = (0, _utils3.callHunterInspectionKit)('TheForceKit', JSON.stringify(updateParams));
|
|
167
172
|
if (updateRes) {
|
|
168
173
|
var updateResObj = JSON.parse(updateRes);
|
|
169
174
|
var Code = updateResObj.Code,
|
|
@@ -192,11 +197,67 @@ var updateDllFileCheck = function updateDllFileCheck() {
|
|
|
192
197
|
}
|
|
193
198
|
}
|
|
194
199
|
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* 检查并安装驱动
|
|
203
|
+
*/
|
|
204
|
+
var checkAndInstallDriver = function checkAndInstallDriver() {
|
|
205
|
+
if (!(0, _utils.isWin)()) {
|
|
206
|
+
isDriverReady = true; // Mac不需要驱动,直接设置为就绪
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
(0, _winDriver.checkHasDriver)().then(function (res) {
|
|
210
|
+
if (res) {
|
|
211
|
+
isDriverReady = true; // 已有驱动,设置为就绪
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 没有驱动,开始下载安装
|
|
216
|
+
isDriverInstalling = true;
|
|
217
|
+
(0, _winDriver.downloadDriver)(function (percent) {
|
|
218
|
+
saasCallBack({
|
|
219
|
+
data: {
|
|
220
|
+
eventName: 'type_need_install_driver',
|
|
221
|
+
eventCode: 0,
|
|
222
|
+
eventContent: JSON.stringify({
|
|
223
|
+
percent: percent // 下载进度
|
|
224
|
+
})
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}).then(function () {
|
|
228
|
+
// 成功
|
|
229
|
+
console.log('驱动下载并安装成功');
|
|
230
|
+
isDriverInstalling = false;
|
|
231
|
+
isDriverReady = true;
|
|
232
|
+
saasCallBack({
|
|
233
|
+
data: {
|
|
234
|
+
eventName: 'type_install_driver_result',
|
|
235
|
+
eventCode: 0 // 0 成功 -1 失败
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}).catch(function (err) {
|
|
239
|
+
// 失败
|
|
240
|
+
console.error('驱动下载或安装失败', err);
|
|
241
|
+
isDriverInstalling = false;
|
|
242
|
+
saasCallBack({
|
|
243
|
+
data: {
|
|
244
|
+
eventName: 'type_install_driver_result',
|
|
245
|
+
eventCode: -1 // 0 成功 -1 失败
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
}).catch(function (err) {
|
|
250
|
+
console.error('驱动检测失败', err);
|
|
251
|
+
});
|
|
252
|
+
};
|
|
195
253
|
var RegisterEvent = function RegisterEvent(params, callBack) {
|
|
196
254
|
saasCallBack = callBack;
|
|
197
255
|
|
|
198
256
|
// 检查是否需要更新dll
|
|
199
257
|
updateDllFileCheck();
|
|
258
|
+
|
|
259
|
+
// 在插线之前就检测驱动状态
|
|
260
|
+
checkAndInstallDriver();
|
|
200
261
|
new usbmux.createListener().on('attached', /*#__PURE__*/function () {
|
|
201
262
|
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(udid) {
|
|
202
263
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
@@ -208,7 +269,7 @@ var RegisterEvent = function RegisterEvent(params, callBack) {
|
|
|
208
269
|
}
|
|
209
270
|
return _context2.abrupt("return");
|
|
210
271
|
case 2:
|
|
211
|
-
//
|
|
272
|
+
// 插入设备通知
|
|
212
273
|
saasCallBack({
|
|
213
274
|
data: {
|
|
214
275
|
eventName: 'type_usb_device_result',
|
|
@@ -218,46 +279,38 @@ var RegisterEvent = function RegisterEvent(params, callBack) {
|
|
|
218
279
|
});
|
|
219
280
|
if ((0, _utils.isWin)()) {
|
|
220
281
|
// windows检查驱动 mac不需要
|
|
221
|
-
//
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
data: {
|
|
254
|
-
eventName: 'type_install_driver_result',
|
|
255
|
-
eventCode: -1 // 0 成功 -1 失败
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
});
|
|
282
|
+
// 检查驱动是否就绪
|
|
283
|
+
if (isDriverReady) {
|
|
284
|
+
// 驱动就绪,直接进行配对
|
|
285
|
+
DevicePair(udid, params);
|
|
286
|
+
} else if (isDriverInstalling) {
|
|
287
|
+
// 驱动正在安装中,通知用户等待
|
|
288
|
+
saasCallBack({
|
|
289
|
+
data: {
|
|
290
|
+
eventName: 'type_usb_device_result',
|
|
291
|
+
udid: udid,
|
|
292
|
+
eventCode: -2,
|
|
293
|
+
// -2 表示驱动安装中,请等待
|
|
294
|
+
eventContent: JSON.stringify({
|
|
295
|
+
message: '驱动正在安装中,请稍后重试'
|
|
296
|
+
})
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
} else {
|
|
300
|
+
// 驱动未安装,重新触发安装流程
|
|
301
|
+
checkAndInstallDriver();
|
|
302
|
+
saasCallBack({
|
|
303
|
+
data: {
|
|
304
|
+
eventName: 'type_usb_device_result',
|
|
305
|
+
udid: udid,
|
|
306
|
+
eventCode: -3,
|
|
307
|
+
// -3 表示需要安装驱动
|
|
308
|
+
eventContent: JSON.stringify({
|
|
309
|
+
message: '需要安装驱动,正在处理中'
|
|
310
|
+
})
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
261
314
|
} else {
|
|
262
315
|
// 有驱动,直接运行脚本
|
|
263
316
|
DevicePair(udid, params);
|
|
Binary file
|
package/lib/resources/mac/{libinspectionkit_amd64_0.0.5.dylib → libinspectionkit_amd64_0.0.6.dylib}
RENAMED
|
Binary file
|
package/lib/resources/mac/{libinspectionkit_arm64_0.0.5.dylib → libinspectionkit_arm64_0.0.6.dylib}
RENAMED
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.6
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.setGlobalProperty = exports.hasGlobalProperty = exports.getHunterInspectionKit = exports.getGlobalProperty = exports.getGlobalObject = exports.deleteGlobalProperty = exports.callHunterInspectionKit = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* 全局对象兼容性处理工具
|
|
9
|
+
* 兼容Electron主进程(global)和渲染进程(window)环境
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 获取全局对象
|
|
14
|
+
* @returns {Object} 全局对象
|
|
15
|
+
*/
|
|
16
|
+
var getGlobalObject = exports.getGlobalObject = function getGlobalObject() {
|
|
17
|
+
if (typeof global !== 'undefined') {
|
|
18
|
+
return global;
|
|
19
|
+
}
|
|
20
|
+
if (typeof window !== 'undefined') {
|
|
21
|
+
return window;
|
|
22
|
+
}
|
|
23
|
+
// 如果都不存在,返回一个空对象(理论上不会发生)
|
|
24
|
+
return {};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 设置全局属性
|
|
29
|
+
* @param {string} key 属性名
|
|
30
|
+
* @param {any} value 属性值
|
|
31
|
+
*/
|
|
32
|
+
var setGlobalProperty = exports.setGlobalProperty = function setGlobalProperty(key, value) {
|
|
33
|
+
var globalObj = getGlobalObject();
|
|
34
|
+
globalObj[key] = value;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 获取全局属性
|
|
39
|
+
* @param {string} key 属性名
|
|
40
|
+
* @param {any} defaultValue 默认值
|
|
41
|
+
* @returns {any} 属性值
|
|
42
|
+
*/
|
|
43
|
+
var getGlobalProperty = exports.getGlobalProperty = function getGlobalProperty(key) {
|
|
44
|
+
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
45
|
+
var globalObj = getGlobalObject();
|
|
46
|
+
return globalObj[key] !== undefined ? globalObj[key] : defaultValue;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 检查全局属性是否存在
|
|
51
|
+
* @param {string} key 属性名
|
|
52
|
+
* @returns {boolean} 是否存在
|
|
53
|
+
*/
|
|
54
|
+
var hasGlobalProperty = exports.hasGlobalProperty = function hasGlobalProperty(key) {
|
|
55
|
+
var globalObj = getGlobalObject();
|
|
56
|
+
return key in globalObj;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 删除全局属性
|
|
61
|
+
* @param {string} key 属性名
|
|
62
|
+
*/
|
|
63
|
+
var deleteGlobalProperty = exports.deleteGlobalProperty = function deleteGlobalProperty(key) {
|
|
64
|
+
var globalObj = getGlobalObject();
|
|
65
|
+
delete globalObj[key];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 安全地获取HunterInspectionKit对象
|
|
70
|
+
* @returns {Object|null} HunterInspectionKit对象,如果不存在则返回null
|
|
71
|
+
*/
|
|
72
|
+
var getHunterInspectionKit = exports.getHunterInspectionKit = function getHunterInspectionKit() {
|
|
73
|
+
var kit = getGlobalProperty('HunterInspectionKit');
|
|
74
|
+
if (!kit) {
|
|
75
|
+
console.warn('HunterInspectionKit未初始化,请先调用HunterInspectionKit()函数');
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return kit;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 安全地调用HunterInspectionKit的方法
|
|
83
|
+
* @param {string} methodName 方法名
|
|
84
|
+
* @param {...any} args 参数
|
|
85
|
+
* @returns {any|null} 方法返回值,如果调用失败则返回null
|
|
86
|
+
*/
|
|
87
|
+
var callHunterInspectionKit = exports.callHunterInspectionKit = function callHunterInspectionKit(methodName) {
|
|
88
|
+
var kit = getHunterInspectionKit();
|
|
89
|
+
if (!kit || typeof kit[methodName] !== 'function') {
|
|
90
|
+
console.error("HunterInspectionKit.".concat(methodName, "\u65B9\u6CD5\u4E0D\u5B58\u5728\u6216\u672A\u521D\u59CB\u5316"));
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
95
|
+
args[_key - 1] = arguments[_key];
|
|
96
|
+
}
|
|
97
|
+
return kit[methodName].apply(kit, args);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error("\u8C03\u7528HunterInspectionKit.".concat(methodName, "\u5931\u8D25:"), error);
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.HunterInspectionKit = void 0;
|
|
7
7
|
var _utils = require("./utils");
|
|
8
|
+
var _utils2 = require("./utils.global");
|
|
8
9
|
var ffi = require('ffi-napi');
|
|
9
10
|
var path = require('path');
|
|
10
11
|
var fs = require('fs');
|
|
@@ -39,6 +40,6 @@ var HunterInspectionKit = exports.HunterInspectionKit = function HunterInspectio
|
|
|
39
40
|
'InspectionKit': ['string', ['string', 'string', 'string']],
|
|
40
41
|
'TheForceKit': ['string', ['string']]
|
|
41
42
|
});
|
|
42
|
-
//
|
|
43
|
-
|
|
43
|
+
// 挂载到全局对象,兼容主进程和渲染进程
|
|
44
|
+
(0, _utils2.setGlobalProperty)('HunterInspectionKit', kitFn);
|
|
44
45
|
};
|