hunter-open-sdk 1.1.2-beta.2 → 2.0.0-beta.11
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/README.md +5 -0
- package/lib/abilities/activate/index.js +54 -0
- package/lib/abilities/activate/worker.js +24 -0
- package/lib/abilities/erase/index.js +54 -0
- package/lib/abilities/erase/worker.js +24 -0
- package/lib/abilities/getGeneralReport/index.js +54 -0
- package/lib/abilities/getGeneralReport/worker.js +27 -0
- package/lib/abilities/getSaaSReport/index.js +54 -0
- package/lib/abilities/getSaaSReport/worker.js +19 -0
- package/lib/abilities/skip/index.js +54 -0
- package/lib/abilities/skip/worker.js +24 -0
- package/lib/events/driver/command.js +8 -9
- package/lib/events/driver/service.js +24 -35
- package/lib/events/driver/winDriver.js +121 -188
- package/lib/getAndroidSn/index.js +134 -198
- package/lib/helper/deviceHelper.js +19 -37
- package/lib/index.js +12 -6
- package/lib/registerEvent/index.js +149 -247
- package/lib/resources/dll/{libinspectionkit_x64_0.0.7.dll → libinspectionkit_x64_0.2.0.dll} +0 -0
- package/lib/resources/mac/{libinspectionkit_arm64_0.0.7.dylib → libinspectionkit_amd64_0.2.0.dylib} +0 -0
- package/lib/resources/mac/libinspectionkit_arm64_0.2.0.dylib +0 -0
- package/lib/resources/version.online +1 -1
- package/lib/utils/utils.command.js +8 -9
- package/lib/utils/utils.common.js +14 -0
- package/lib/utils/{utils.js → utils.env.js} +19 -18
- package/lib/utils/utils.global.js +164 -40
- package/lib/utils/utils.initDll.js +15 -13
- package/lib/utils/utils.path.js +24 -6
- package/lib/utils/utils.process.js +23 -0
- package/lib/utils/utils.sn.js +31 -47
- package/package.json +7 -8
- package/lib/getGeneralReport/index.js +0 -76
- package/lib/getGeneralReport/worker.js +0 -20
- package/lib/getSaaSReport/index.js +0 -76
- package/lib/getSaaSReport/worker.js +0 -20
- package/lib/resources/mac/libinspectionkit_amd64_0.0.7.dylib +0 -0
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.setGlobalProperty = exports.hasGlobalProperty = exports.getSaaSReportCallKit = exports.getHunterInspectionKit = exports.getGlobalProperty = exports.getGlobalObject = exports.getGeneralReportCallKit = exports.deleteGlobalProperty = exports.callHunterInspectionKit = void 0;
|
|
6
|
+
exports.skipCallKit = exports.setGlobalProperty = exports.hasGlobalProperty = exports.getSaaSReportCallKit = exports.getHunterInspectionKit = exports.getGlobalProperty = exports.getGlobalObject = exports.getGeneralReportCallKit = exports.eraseCallKit = exports.deleteGlobalProperty = exports.callHunterInspectionKit = exports.activateCallKit = void 0;
|
|
7
7
|
var _utils = require("../utils/utils.initDll");
|
|
8
8
|
/**
|
|
9
9
|
* 全局对象兼容性处理工具
|
|
10
10
|
* 兼容Electron主进程(global)和渲染进程(window)环境
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
const Sentry = require("@sentry/browser");
|
|
13
13
|
/**
|
|
14
14
|
* 获取全局对象
|
|
15
15
|
* @returns {Object} 全局对象
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
const getGlobalObject = () => {
|
|
18
18
|
if (typeof global !== 'undefined') {
|
|
19
19
|
return global;
|
|
20
20
|
}
|
|
@@ -30,8 +30,9 @@ var getGlobalObject = exports.getGlobalObject = function getGlobalObject() {
|
|
|
30
30
|
* @param {string} key 属性名
|
|
31
31
|
* @param {any} value 属性值
|
|
32
32
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
exports.getGlobalObject = getGlobalObject;
|
|
34
|
+
const setGlobalProperty = (key, value) => {
|
|
35
|
+
const globalObj = getGlobalObject();
|
|
35
36
|
globalObj[key] = value;
|
|
36
37
|
};
|
|
37
38
|
|
|
@@ -41,9 +42,9 @@ var setGlobalProperty = exports.setGlobalProperty = function setGlobalProperty(k
|
|
|
41
42
|
* @param {any} defaultValue 默认值
|
|
42
43
|
* @returns {any} 属性值
|
|
43
44
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
exports.setGlobalProperty = setGlobalProperty;
|
|
46
|
+
const getGlobalProperty = (key, defaultValue = undefined) => {
|
|
47
|
+
const globalObj = getGlobalObject();
|
|
47
48
|
return globalObj[key] !== undefined ? globalObj[key] : defaultValue;
|
|
48
49
|
};
|
|
49
50
|
|
|
@@ -52,8 +53,9 @@ var getGlobalProperty = exports.getGlobalProperty = function getGlobalProperty(k
|
|
|
52
53
|
* @param {string} key 属性名
|
|
53
54
|
* @returns {boolean} 是否存在
|
|
54
55
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
exports.getGlobalProperty = getGlobalProperty;
|
|
57
|
+
const hasGlobalProperty = key => {
|
|
58
|
+
const globalObj = getGlobalObject();
|
|
57
59
|
return key in globalObj;
|
|
58
60
|
};
|
|
59
61
|
|
|
@@ -61,8 +63,9 @@ var hasGlobalProperty = exports.hasGlobalProperty = function hasGlobalProperty(k
|
|
|
61
63
|
* 删除全局属性
|
|
62
64
|
* @param {string} key 属性名
|
|
63
65
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
exports.hasGlobalProperty = hasGlobalProperty;
|
|
67
|
+
const deleteGlobalProperty = key => {
|
|
68
|
+
const globalObj = getGlobalObject();
|
|
66
69
|
delete globalObj[key];
|
|
67
70
|
};
|
|
68
71
|
|
|
@@ -70,8 +73,9 @@ var deleteGlobalProperty = exports.deleteGlobalProperty = function deleteGlobalP
|
|
|
70
73
|
* 安全地获取HunterInspectionKit对象
|
|
71
74
|
* @returns {Object|null} HunterInspectionKit对象,如果不存在则返回null
|
|
72
75
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
exports.deleteGlobalProperty = deleteGlobalProperty;
|
|
77
|
+
const getHunterInspectionKit = willInit => {
|
|
78
|
+
const kit = getGlobalProperty('HunterInspectionKit');
|
|
75
79
|
if (!kit) {
|
|
76
80
|
!willInit && console.warn('HunterInspectionKit未初始化,请先调用 initHunterInspectionKit() 函数');
|
|
77
81
|
return null;
|
|
@@ -85,26 +89,23 @@ var getHunterInspectionKit = exports.getHunterInspectionKit = function getHunter
|
|
|
85
89
|
* @param {...any} args 参数
|
|
86
90
|
* @returns {any|null} 方法返回值,如果调用失败则返回null
|
|
87
91
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
exports.getHunterInspectionKit = getHunterInspectionKit;
|
|
93
|
+
const callHunterInspectionKit = (methodName, ...args) => {
|
|
94
|
+
let kit = getHunterInspectionKit(true);
|
|
90
95
|
if (!kit) {
|
|
91
96
|
(0, _utils.initHunterInspectionKit)();
|
|
92
97
|
kit = getHunterInspectionKit(false);
|
|
93
98
|
}
|
|
94
99
|
if (!kit || typeof kit[methodName] !== 'function') {
|
|
95
|
-
console.error(
|
|
96
|
-
Sentry.captureException(
|
|
100
|
+
console.error(`HunterInspectionKit.${methodName}方法不存在或未初始化`);
|
|
101
|
+
Sentry.captureException(`HunterInspectionKit.${methodName}方法不存在或未初始化`);
|
|
97
102
|
return null;
|
|
98
103
|
}
|
|
99
104
|
try {
|
|
100
|
-
|
|
101
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
102
|
-
args[_key - 1] = arguments[_key];
|
|
103
|
-
}
|
|
104
|
-
return (_kit = kit)[methodName].apply(_kit, args);
|
|
105
|
+
return kit[methodName](...args);
|
|
105
106
|
} catch (error) {
|
|
106
|
-
console.error(
|
|
107
|
-
Sentry.captureException(
|
|
107
|
+
console.error(`调用HunterInspectionKit.${methodName}失败:`, error);
|
|
108
|
+
Sentry.captureException(`调用HunterInspectionKit.${methodName}失败:`, error);
|
|
108
109
|
return null;
|
|
109
110
|
}
|
|
110
111
|
};
|
|
@@ -114,15 +115,20 @@ var callHunterInspectionKit = exports.callHunterInspectionKit = function callHun
|
|
|
114
115
|
* @param {Object} data 参数
|
|
115
116
|
* @returns {Object} 报告结果
|
|
116
117
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
exports.callHunterInspectionKit = callHunterInspectionKit;
|
|
119
|
+
const getGeneralReportCallKit = data => {
|
|
120
|
+
const {
|
|
121
|
+
params,
|
|
122
|
+
biz
|
|
123
|
+
} = data;
|
|
124
|
+
const reportRes = callHunterInspectionKit('InspectionKit', biz, 'general_report', params);
|
|
121
125
|
if (reportRes) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
+
const reportResObj = JSON.parse(reportRes);
|
|
127
|
+
const {
|
|
128
|
+
Code,
|
|
129
|
+
Data,
|
|
130
|
+
Message
|
|
131
|
+
} = reportResObj;
|
|
126
132
|
if (Code == 0 && Data) {
|
|
127
133
|
return {
|
|
128
134
|
type: 'getGeneralReportSuccess',
|
|
@@ -157,13 +163,16 @@ var getGeneralReportCallKit = exports.getGeneralReportCallKit = function getGene
|
|
|
157
163
|
* @param {Object} params 参数
|
|
158
164
|
* @returns {Object} 报告结果
|
|
159
165
|
*/
|
|
160
|
-
|
|
161
|
-
|
|
166
|
+
exports.getGeneralReportCallKit = getGeneralReportCallKit;
|
|
167
|
+
const getSaaSReportCallKit = params => {
|
|
168
|
+
const reportRes = callHunterInspectionKit('InspectionKit', params, 'saas_report', params);
|
|
162
169
|
if (reportRes) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
170
|
+
const reportResObj = JSON.parse(reportRes);
|
|
171
|
+
const {
|
|
172
|
+
Code,
|
|
173
|
+
Data,
|
|
174
|
+
Message
|
|
175
|
+
} = reportResObj;
|
|
167
176
|
if (Code == 0 && Data) {
|
|
168
177
|
return {
|
|
169
178
|
type: 'getSaaSReportSuccess',
|
|
@@ -191,4 +200,119 @@ var getSaaSReportCallKit = exports.getSaaSReportCallKit = function getSaaSReport
|
|
|
191
200
|
message: '获取SaaS报告失败'
|
|
192
201
|
}
|
|
193
202
|
};
|
|
194
|
-
};
|
|
203
|
+
};
|
|
204
|
+
exports.getSaaSReportCallKit = getSaaSReportCallKit;
|
|
205
|
+
const eraseCallKit = paramStr => {
|
|
206
|
+
const res = callHunterInspectionKit('InspectionKit', paramStr, 'erase', paramStr);
|
|
207
|
+
if (res) {
|
|
208
|
+
const resObj = JSON.parse(res);
|
|
209
|
+
const {
|
|
210
|
+
Code,
|
|
211
|
+
Data,
|
|
212
|
+
Message
|
|
213
|
+
} = resObj;
|
|
214
|
+
if (Code == 0) {
|
|
215
|
+
return {
|
|
216
|
+
type: 'eraseSuccess',
|
|
217
|
+
data: {
|
|
218
|
+
code: 0,
|
|
219
|
+
data: Data,
|
|
220
|
+
message: '抹除设备成功'
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
type: 'eraseFail',
|
|
226
|
+
data: {
|
|
227
|
+
code: -1,
|
|
228
|
+
data: {},
|
|
229
|
+
message: Message || '抹除设备失败'
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
type: 'eraseFail',
|
|
235
|
+
data: {
|
|
236
|
+
code: -1,
|
|
237
|
+
data: {},
|
|
238
|
+
message: '抹除设备失败'
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
exports.eraseCallKit = eraseCallKit;
|
|
243
|
+
const activateCallKit = paramStr => {
|
|
244
|
+
const res = callHunterInspectionKit('InspectionKit', paramStr, 'activate', paramStr);
|
|
245
|
+
if (res) {
|
|
246
|
+
const resObj = JSON.parse(res);
|
|
247
|
+
const {
|
|
248
|
+
Code,
|
|
249
|
+
Data,
|
|
250
|
+
Message
|
|
251
|
+
} = resObj;
|
|
252
|
+
if (Code == 0) {
|
|
253
|
+
return {
|
|
254
|
+
type: 'activateSuccess',
|
|
255
|
+
data: {
|
|
256
|
+
code: 0,
|
|
257
|
+
data: Data,
|
|
258
|
+
message: '激活设备成功'
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
type: 'activateFail',
|
|
264
|
+
data: {
|
|
265
|
+
code: -1,
|
|
266
|
+
data: {},
|
|
267
|
+
message: Message || '激活设备失败'
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
type: 'activateFail',
|
|
273
|
+
data: {
|
|
274
|
+
code: -1,
|
|
275
|
+
data: {},
|
|
276
|
+
message: '激活设备失败'
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
exports.activateCallKit = activateCallKit;
|
|
281
|
+
const skipCallKit = paramStr => {
|
|
282
|
+
const res = callHunterInspectionKit('InspectionKit', paramStr, 'skip', paramStr);
|
|
283
|
+
if (res) {
|
|
284
|
+
const resObj = JSON.parse(res);
|
|
285
|
+
const {
|
|
286
|
+
Code,
|
|
287
|
+
Data,
|
|
288
|
+
Message
|
|
289
|
+
} = resObj;
|
|
290
|
+
if (Code == 0) {
|
|
291
|
+
return {
|
|
292
|
+
type: 'skipSuccess',
|
|
293
|
+
data: {
|
|
294
|
+
code: 0,
|
|
295
|
+
data: Data,
|
|
296
|
+
message: '跳过向导成功'
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
type: 'skipFail',
|
|
302
|
+
data: {
|
|
303
|
+
code: -1,
|
|
304
|
+
data: {},
|
|
305
|
+
message: Message || '跳过向导失败'
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
type: 'skipFail',
|
|
311
|
+
data: {
|
|
312
|
+
code: -1,
|
|
313
|
+
data: {},
|
|
314
|
+
message: '跳过向导失败'
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
exports.skipCallKit = skipCallKit;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -8,40 +7,43 @@ exports.initHunterInspectionKit = void 0;
|
|
|
8
7
|
var _koffi = _interopRequireDefault(require("koffi"));
|
|
9
8
|
var _path = _interopRequireDefault(require("path"));
|
|
10
9
|
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
-
var _utils = require("./utils");
|
|
10
|
+
var _utils = require("./utils.env");
|
|
12
11
|
var _utils2 = require("./utils.global");
|
|
12
|
+
var _utils3 = require("./utils.path");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
14
|
/**
|
|
14
15
|
* 声明dll函数
|
|
15
16
|
* @param {String} udid 设备id
|
|
16
17
|
* @returns
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
const initHunterInspectionKit = () => {
|
|
21
|
+
let dllPath;
|
|
21
22
|
|
|
22
23
|
// 读取本地sdk的version
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
const versionPath = _path.default.resolve(__dirname, '../resources/version.online');
|
|
25
|
+
const version = _fs.default.readFileSync(versionPath, 'utf-8');
|
|
25
26
|
if ((0, _utils.isMac)()) {
|
|
26
27
|
if ((0, _utils.isArm64)()) {
|
|
27
|
-
dllPath = _path.default.resolve(__dirname,
|
|
28
|
+
dllPath = _path.default.resolve(__dirname, `../resources/mac/libinspectionkit_arm64_${version}.dylib`);
|
|
28
29
|
}
|
|
29
30
|
if ((0, _utils.isAmd64)()) {
|
|
30
|
-
dllPath = _path.default.resolve(__dirname,
|
|
31
|
+
dllPath = _path.default.resolve(__dirname, `../resources/mac/libinspectionkit_amd64_${version}.dylib`);
|
|
31
32
|
}
|
|
32
33
|
} else {
|
|
33
|
-
dllPath = _path.default.resolve(__dirname,
|
|
34
|
+
dllPath = _path.default.resolve(__dirname, `../resources/dll/libinspectionkit_x64_${version}.dll`);
|
|
34
35
|
}
|
|
35
36
|
if (!(0, _utils.isDev)()) {
|
|
36
37
|
// 如果是生产模式 则替换app.asar 路径 为了在生产调用dll
|
|
37
|
-
dllPath =
|
|
38
|
+
dllPath = (0, _utils3.getCurrentEnvPath)(dllPath);
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
const dllLib = _koffi.default.load(dllPath);
|
|
41
|
+
const dllKit = {
|
|
41
42
|
InspectionKit: dllLib.func('InspectionKit', 'str', ['str', 'str', 'str']),
|
|
42
43
|
TheForceKit: dllLib.func('TheForceKit', 'str', ['str'])
|
|
43
44
|
};
|
|
44
45
|
|
|
45
46
|
// 挂载到全局对象,兼容主进程和渲染进程
|
|
46
47
|
(0, _utils2.setGlobalProperty)('HunterInspectionKit', dllKit);
|
|
47
|
-
};
|
|
48
|
+
};
|
|
49
|
+
exports.initHunterInspectionKit = initHunterInspectionKit;
|
package/lib/utils/utils.path.js
CHANGED
|
@@ -3,14 +3,32 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
exports.getCurrentEnvPath = getCurrentEnvPath;
|
|
7
|
+
exports.getCurrentProcess = getCurrentProcess;
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _process = _interopRequireDefault(require("process"));
|
|
10
|
+
var _utils = require("./utils.env");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
12
|
/**
|
|
10
13
|
* 当前环境地址转换
|
|
11
14
|
* @param {*} path
|
|
12
15
|
* @returns
|
|
13
16
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
function getCurrentEnvPath(dirPath, filePath = '') {
|
|
18
|
+
let fixPath = dirPath;
|
|
19
|
+
if (!(0, _utils.isDev)()) {
|
|
20
|
+
fixPath = fixPath.replace('/app.asar/', '/app.asar.unpacked/').replace(/\/app.asar\//, /\/app.asar.unpacked\//);
|
|
21
|
+
}
|
|
22
|
+
return _path.default.resolve(fixPath, filePath);
|
|
23
|
+
}
|
|
24
|
+
function getCurrentProcess() {
|
|
25
|
+
if (typeof _process.default === 'undefined' || _process.default.type === undefined) {
|
|
26
|
+
return '这是在浏览器环境中';
|
|
27
|
+
} else {
|
|
28
|
+
if (_process.default.type === 'browser') {
|
|
29
|
+
return '这是在 Node.js 环境中';
|
|
30
|
+
} else {
|
|
31
|
+
return '这是在 Electron 的渲染进程中';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getProccessType = getProccessType;
|
|
7
|
+
exports.isInMainProcess = isInMainProcess;
|
|
8
|
+
exports.isInRenderProcess = isInRenderProcess;
|
|
9
|
+
// 获取进程类型
|
|
10
|
+
function getProccessType() {
|
|
11
|
+
return process.type;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// 是否在主进程
|
|
15
|
+
function isInMainProcess() {
|
|
16
|
+
return getProccessType() === 'browser';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 是否在渲染进程
|
|
20
|
+
// eslint-disable-next-line no-unused-vars
|
|
21
|
+
function isInRenderProcess() {
|
|
22
|
+
return getProccessType() === 'renderer';
|
|
23
|
+
}
|
package/lib/utils/utils.sn.js
CHANGED
|
@@ -4,23 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.parseWmicOutput = parseWmicOutput;
|
|
7
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
8
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
10
7
|
/**
|
|
11
8
|
* 判断设备是否为手机设备
|
|
12
9
|
* @param {Object} device - 设备信息
|
|
13
10
|
* @returns {boolean} 是否为手机设备
|
|
14
11
|
*/
|
|
15
12
|
function isPhoneDevice(device) {
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const name = device.name.toLowerCase();
|
|
14
|
+
const pnpId = device.pnpDeviceId.toLowerCase();
|
|
18
15
|
|
|
19
16
|
// 只支持三星、荣耀、华为的手机设备关键词
|
|
20
|
-
|
|
17
|
+
const phoneKeywords = ['samsung', 'galaxy', 'huawei', 'honor', 'honor magic'];
|
|
21
18
|
|
|
22
19
|
// 只支持三星、荣耀、华为的手机厂商VID
|
|
23
|
-
|
|
20
|
+
const phoneVendors = ['VID_04E8',
|
|
24
21
|
// Samsung
|
|
25
22
|
'VID_12D1',
|
|
26
23
|
// Huawei
|
|
@@ -28,14 +25,10 @@ function isPhoneDevice(device) {
|
|
|
28
25
|
];
|
|
29
26
|
|
|
30
27
|
// 检查名称中是否包含手机关键词
|
|
31
|
-
|
|
32
|
-
return name.includes(keyword);
|
|
33
|
-
});
|
|
28
|
+
const isPhoneByName = phoneKeywords.some(keyword => name.includes(keyword));
|
|
34
29
|
|
|
35
30
|
// 检查PNPDeviceID中是否包含手机厂商VID
|
|
36
|
-
|
|
37
|
-
return pnpId.includes(vendor.toLowerCase());
|
|
38
|
-
});
|
|
31
|
+
const isPhoneByVendor = phoneVendors.some(vendor => pnpId.includes(vendor.toLowerCase()));
|
|
39
32
|
return isPhoneByName || isPhoneByVendor;
|
|
40
33
|
}
|
|
41
34
|
|
|
@@ -46,9 +39,9 @@ function isPhoneDevice(device) {
|
|
|
46
39
|
*/
|
|
47
40
|
function extractSerialNumber(pnpDeviceId) {
|
|
48
41
|
// USB设备ID格式通常为: USB\VID_v(4)&PID_d(4)\序列号
|
|
49
|
-
|
|
42
|
+
const parts = pnpDeviceId.split('\\');
|
|
50
43
|
if (parts.length >= 3) {
|
|
51
|
-
|
|
44
|
+
const serialPart = parts[parts.length - 1];
|
|
52
45
|
|
|
53
46
|
// 验证序列号格式(通常不包含&和#等特殊字符)
|
|
54
47
|
if (serialPart && !serialPart.includes('&') && !serialPart.includes('#')) {
|
|
@@ -65,43 +58,34 @@ function extractSerialNumber(pnpDeviceId) {
|
|
|
65
58
|
* @returns {Array} 手机设备信息数组
|
|
66
59
|
*/
|
|
67
60
|
function parseWmicOutput(output) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (isPhoneDevice(currentDevice)) {
|
|
82
|
-
// 提取序列号
|
|
83
|
-
currentDevice.serial = extractSerialNumber(currentDevice.pnpDeviceId);
|
|
84
|
-
devices.push(currentDevice);
|
|
85
|
-
}
|
|
61
|
+
const devices = [];
|
|
62
|
+
const lines = output.split('\r\n');
|
|
63
|
+
let currentDevice = {};
|
|
64
|
+
for (const line of lines) {
|
|
65
|
+
// 跳过空行
|
|
66
|
+
if (!line.trim()) {
|
|
67
|
+
// 如果当前设备有数据,则保存
|
|
68
|
+
if (currentDevice.name && currentDevice.pnpDeviceId) {
|
|
69
|
+
// 检查是否为手机设备
|
|
70
|
+
if (isPhoneDevice(currentDevice)) {
|
|
71
|
+
// 提取序列号
|
|
72
|
+
currentDevice.serial = extractSerialNumber(currentDevice.pnpDeviceId);
|
|
73
|
+
devices.push(currentDevice);
|
|
86
74
|
}
|
|
87
|
-
currentDevice = {};
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// 解析Name和PNPDeviceID
|
|
92
|
-
if (line.startsWith('Name=')) {
|
|
93
|
-
currentDevice.name = line.substring(5).trim();
|
|
94
|
-
} else if (line.startsWith('PNPDeviceID=')) {
|
|
95
|
-
currentDevice.pnpDeviceId = line.substring(12).trim();
|
|
96
75
|
}
|
|
76
|
+
currentDevice = {};
|
|
77
|
+
continue;
|
|
97
78
|
}
|
|
98
79
|
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
80
|
+
// 解析Name和PNPDeviceID
|
|
81
|
+
if (line.startsWith('Name=')) {
|
|
82
|
+
currentDevice.name = line.substring(5).trim();
|
|
83
|
+
} else if (line.startsWith('PNPDeviceID=')) {
|
|
84
|
+
currentDevice.pnpDeviceId = line.substring(12).trim();
|
|
85
|
+
}
|
|
104
86
|
}
|
|
87
|
+
|
|
88
|
+
// 处理最后一个设备
|
|
105
89
|
if (currentDevice.name && currentDevice.pnpDeviceId && isPhoneDevice(currentDevice)) {
|
|
106
90
|
currentDevice.serial = extractSerialNumber(currentDevice.pnpDeviceId);
|
|
107
91
|
devices.push(currentDevice);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hunter-open-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.11",
|
|
4
4
|
"description": "采货侠SaaS版本桌面端sdk",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "zz dev",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"fix": "zz lint --fix",
|
|
12
12
|
"staged": "zz lint --staged",
|
|
13
13
|
"staged-fix": "zz --staged --fix",
|
|
14
|
-
"pub": "
|
|
15
|
-
"pub-beta": "
|
|
14
|
+
"pub": "npm run build && npm publish",
|
|
15
|
+
"pub-beta": "npm run build && npm publish --tag beta",
|
|
16
16
|
"unpub": "zz pub --unpub",
|
|
17
17
|
"doc": "zz doc && zz doc --upload",
|
|
18
18
|
"dev-doc": "zz doc --dev",
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@sentry/browser": "^10.10.0",
|
|
30
30
|
"compressing": "2.0.0",
|
|
31
|
-
"core-js": "3.6.5",
|
|
32
31
|
"fs": "^0.0.1-security",
|
|
33
32
|
"fs-extra": "^11.3.0",
|
|
34
33
|
"koffi": "2.14.1",
|
|
@@ -36,10 +35,10 @@
|
|
|
36
35
|
"request": "^2.88.2",
|
|
37
36
|
"sudo-prompt": "^9.2.1",
|
|
38
37
|
"usb": "^2.15.0",
|
|
39
|
-
"usbmux": "^0.1.0"
|
|
38
|
+
"usbmux": "^0.1.0",
|
|
39
|
+
"web-worker": "1.5.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@babel/plugin-transform-runtime": "7.21.0",
|
|
43
42
|
"@commitlint/cli": "8.3.5",
|
|
44
43
|
"@commitlint/config-conventional": "8.3.4",
|
|
45
44
|
"@evilmartians/lefthook": "0.8.0",
|
|
@@ -53,6 +52,7 @@
|
|
|
53
52
|
"commitlint": "17.0.2",
|
|
54
53
|
"father": "4.6.7",
|
|
55
54
|
"lint-staged": "10.0.8",
|
|
55
|
+
"minimatch": "3.0.0",
|
|
56
56
|
"path-to-regexp": "2.4.0",
|
|
57
57
|
"typedoc": "0.23.9",
|
|
58
58
|
"typescript": "4.7.4"
|
|
@@ -63,8 +63,7 @@
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
"files": [
|
|
66
|
-
"lib"
|
|
67
|
-
"es"
|
|
66
|
+
"lib"
|
|
68
67
|
],
|
|
69
68
|
"engines": {
|
|
70
69
|
"node": ">=20.0.0"
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.GetGeneralReport = void 0;
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
var _utils = require("../utils/utils.global");
|
|
10
|
-
// 预定义worker
|
|
11
|
-
var worker = null;
|
|
12
|
-
|
|
13
|
-
// 获取进程类型
|
|
14
|
-
function getProccessType() {
|
|
15
|
-
// console.log('process.type', process.type)
|
|
16
|
-
return process.type;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// 是否在主进程
|
|
20
|
-
function isInMainProcess() {
|
|
21
|
-
return getProccessType() === 'browser';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// 是否在渲染进程
|
|
25
|
-
// eslint-disable-next-line no-unused-vars
|
|
26
|
-
function isInRenderProcess() {
|
|
27
|
-
return getProccessType() === 'renderer';
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 初始化worker
|
|
31
|
-
function initWorker() {
|
|
32
|
-
if (!worker) {
|
|
33
|
-
worker = new Worker('file://' + _path.default.resolve(__dirname, "./worker.js"));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 添加worker监听
|
|
38
|
-
function addWorkerListener(callBack) {
|
|
39
|
-
worker && (worker.onmessage = function (event) {
|
|
40
|
-
// console.log('main thread onmessage event.data', event.data)
|
|
41
|
-
|
|
42
|
-
var _event$data = event.data,
|
|
43
|
-
type = _event$data.type,
|
|
44
|
-
data = _event$data.data;
|
|
45
|
-
switch (type) {
|
|
46
|
-
case 'getGeneralReportSuccess':
|
|
47
|
-
callBack(data);
|
|
48
|
-
break;
|
|
49
|
-
case 'getGeneralReportFail':
|
|
50
|
-
callBack(data);
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// 发起获取报告消息
|
|
57
|
-
function getReport(params) {
|
|
58
|
-
worker && worker.postMessage({
|
|
59
|
-
type: 'getGeneralReport',
|
|
60
|
-
params: params
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 获取报告
|
|
65
|
-
var GetGeneralReport = exports.GetGeneralReport = function GetGeneralReport(params, callBack) {
|
|
66
|
-
// 如果是在主进程,则直接获取报告
|
|
67
|
-
if (isInMainProcess()) {
|
|
68
|
-
var reportRes = (0, _utils.getGeneralReportCallKit)(params);
|
|
69
|
-
return callBack(reportRes.data);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 如果是在渲染进程,则通过worker获取报告
|
|
73
|
-
initWorker();
|
|
74
|
-
addWorkerListener(callBack);
|
|
75
|
-
getReport(params);
|
|
76
|
-
};
|