hunter-open-sdk 1.1.2 → 2.0.0-beta.12

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.
Files changed (36) hide show
  1. package/README.md +5 -0
  2. package/lib/abilities/activate/index.js +54 -0
  3. package/lib/abilities/activate/worker.js +24 -0
  4. package/lib/abilities/erase/index.js +54 -0
  5. package/lib/abilities/erase/worker.js +24 -0
  6. package/lib/abilities/getGeneralReport/index.js +54 -0
  7. package/lib/abilities/getGeneralReport/worker.js +27 -0
  8. package/lib/abilities/getSaaSReport/index.js +54 -0
  9. package/lib/abilities/getSaaSReport/worker.js +19 -0
  10. package/lib/abilities/skip/index.js +54 -0
  11. package/lib/abilities/skip/worker.js +24 -0
  12. package/lib/events/driver/command.js +8 -9
  13. package/lib/events/driver/service.js +24 -35
  14. package/lib/events/driver/winDriver.js +121 -188
  15. package/lib/getAndroidSn/index.js +134 -198
  16. package/lib/helper/deviceHelper.js +19 -37
  17. package/lib/index.js +12 -6
  18. package/lib/registerEvent/index.js +149 -247
  19. package/lib/resources/dll/{libinspectionkit_x64_0.0.7.dll → libinspectionkit_x64_0.2.0.dll} +0 -0
  20. package/lib/resources/mac/{libinspectionkit_arm64_0.0.7.dylib → libinspectionkit_amd64_0.2.0.dylib} +0 -0
  21. package/lib/resources/mac/libinspectionkit_arm64_0.2.0.dylib +0 -0
  22. package/lib/resources/version.online +1 -1
  23. package/lib/utils/utils.command.js +8 -9
  24. package/lib/utils/utils.common.js +14 -0
  25. package/lib/utils/{utils.js → utils.env.js} +19 -18
  26. package/lib/utils/utils.global.js +166 -42
  27. package/lib/utils/utils.initDll.js +24 -20
  28. package/lib/utils/utils.path.js +24 -6
  29. package/lib/utils/utils.process.js +23 -0
  30. package/lib/utils/utils.sn.js +31 -47
  31. package/package.json +16 -14
  32. package/lib/getGeneralReport/index.js +0 -76
  33. package/lib/getGeneralReport/worker.js +0 -20
  34. package/lib/getSaaSReport/index.js +0 -76
  35. package/lib/getSaaSReport/worker.js +0 -20
  36. 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
- var Sentry = require("@sentry/browser");
12
+ const Sentry = require("@sentry/browser");
13
13
  /**
14
14
  * 获取全局对象
15
15
  * @returns {Object} 全局对象
16
16
  */
17
- var getGlobalObject = exports.getGlobalObject = function getGlobalObject() {
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
- var setGlobalProperty = exports.setGlobalProperty = function setGlobalProperty(key, value) {
34
- var globalObj = getGlobalObject();
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
- var getGlobalProperty = exports.getGlobalProperty = function getGlobalProperty(key) {
45
- var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
46
- var globalObj = getGlobalObject();
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
- var hasGlobalProperty = exports.hasGlobalProperty = function hasGlobalProperty(key) {
56
- var globalObj = getGlobalObject();
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
- var deleteGlobalProperty = exports.deleteGlobalProperty = function deleteGlobalProperty(key) {
65
- var globalObj = getGlobalObject();
66
+ exports.hasGlobalProperty = hasGlobalProperty;
67
+ const deleteGlobalProperty = key => {
68
+ const globalObj = getGlobalObject();
66
69
  delete globalObj[key];
67
70
  };
68
71
 
@@ -70,10 +73,11 @@ var deleteGlobalProperty = exports.deleteGlobalProperty = function deleteGlobalP
70
73
  * 安全地获取HunterInspectionKit对象
71
74
  * @returns {Object|null} HunterInspectionKit对象,如果不存在则返回null
72
75
  */
73
- var getHunterInspectionKit = exports.getHunterInspectionKit = function getHunterInspectionKit(willInit) {
74
- var kit = getGlobalProperty('HunterInspectionKit');
76
+ exports.deleteGlobalProperty = deleteGlobalProperty;
77
+ const getHunterInspectionKit = willInit => {
78
+ const kit = getGlobalProperty('HunterInspectionKit');
75
79
  if (!kit) {
76
- !willInit && console.warn('HunterInspectionKit未初始化,请先调用HunterInspectionKit()函数');
80
+ !willInit && console.warn('HunterInspectionKit未初始化,请先调用 initHunterInspectionKit() 函数');
77
81
  return null;
78
82
  }
79
83
  return kit;
@@ -85,26 +89,23 @@ var getHunterInspectionKit = exports.getHunterInspectionKit = function getHunter
85
89
  * @param {...any} args 参数
86
90
  * @returns {any|null} 方法返回值,如果调用失败则返回null
87
91
  */
88
- var callHunterInspectionKit = exports.callHunterInspectionKit = function callHunterInspectionKit(methodName) {
89
- var kit = getHunterInspectionKit(true);
92
+ exports.getHunterInspectionKit = getHunterInspectionKit;
93
+ const callHunterInspectionKit = (methodName, ...args) => {
94
+ let kit = getHunterInspectionKit(true);
90
95
  if (!kit) {
91
- (0, _utils.HunterInspectionKit)();
96
+ (0, _utils.initHunterInspectionKit)();
92
97
  kit = getHunterInspectionKit(false);
93
98
  }
94
99
  if (!kit || typeof kit[methodName] !== 'function') {
95
- console.error("HunterInspectionKit.".concat(methodName, "\u65B9\u6CD5\u4E0D\u5B58\u5728\u6216\u672A\u521D\u59CB\u5316"));
96
- Sentry.captureException("HunterInspectionKit.".concat(methodName, "\u65B9\u6CD5\u4E0D\u5B58\u5728\u6216\u672A\u521D\u59CB\u5316"));
100
+ console.error(`HunterInspectionKit.${methodName}方法不存在或未初始化`);
101
+ Sentry.captureException(`HunterInspectionKit.${methodName}方法不存在或未初始化`);
97
102
  return null;
98
103
  }
99
104
  try {
100
- var _kit;
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("\u8C03\u7528HunterInspectionKit.".concat(methodName, "\u5931\u8D25:"), error);
107
- Sentry.captureException("\u8C03\u7528HunterInspectionKit.".concat(methodName, "\u5931\u8D25:"), error);
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
- var getGeneralReportCallKit = exports.getGeneralReportCallKit = function getGeneralReportCallKit(data) {
118
- var params = data.params,
119
- biz = data.biz;
120
- var reportRes = callHunterInspectionKit('InspectionKit', biz, 'general_report', params);
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
- var reportResObj = JSON.parse(reportRes);
123
- var Code = reportResObj.Code,
124
- Data = reportResObj.Data,
125
- Message = reportResObj.Message;
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
- var getSaaSReportCallKit = exports.getSaaSReportCallKit = function getSaaSReportCallKit(params) {
161
- var reportRes = callHunterInspectionKit('InspectionKit', params, 'saas_report', params);
166
+ exports.getGeneralReportCallKit = getGeneralReportCallKit;
167
+ const getSaaSReportCallKit = params => {
168
+ const reportRes = callHunterInspectionKit('InspectionKit', params, 'saas_report', params);
162
169
  if (reportRes) {
163
- var reportResObj = JSON.parse(reportRes);
164
- var Code = reportResObj.Code,
165
- Data = reportResObj.Data,
166
- Message = reportResObj.Message;
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;
@@ -3,43 +3,47 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.HunterInspectionKit = void 0;
7
- var _utils = require("./utils");
6
+ exports.initHunterInspectionKit = void 0;
7
+ var _koffi = _interopRequireDefault(require("koffi"));
8
+ var _path = _interopRequireDefault(require("path"));
9
+ var _fs = _interopRequireDefault(require("fs"));
10
+ var _utils = require("./utils.env");
8
11
  var _utils2 = require("./utils.global");
9
- var ffi = require('ffi-napi');
10
- var path = require('path');
11
- var fs = require('fs');
12
-
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
- var HunterInspectionKit = exports.HunterInspectionKit = function HunterInspectionKit() {
20
- var dllPath;
20
+ const initHunterInspectionKit = () => {
21
+ let dllPath;
21
22
 
22
23
  // 读取本地sdk的version
23
- var versionPath = path.resolve(__dirname, '../resources/version.online');
24
- var version = fs.readFileSync(versionPath, 'utf-8');
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.resolve(__dirname, "../resources/mac/libinspectionkit_arm64_".concat(version, ".dylib"));
28
+ dllPath = _path.default.resolve(__dirname, `../resources/mac/libinspectionkit_arm64_${version}.dylib`);
28
29
  }
29
30
  if ((0, _utils.isAmd64)()) {
30
- dllPath = path.resolve(__dirname, "../resources/mac/libinspectionkit_amd64_".concat(version, ".dylib"));
31
+ dllPath = _path.default.resolve(__dirname, `../resources/mac/libinspectionkit_amd64_${version}.dylib`);
31
32
  }
32
33
  } else {
33
- dllPath = path.resolve(__dirname, "../resources/dll/libinspectionkit_x64_".concat(version, ".dll"));
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 = dllPath.replace('app.asar', 'app.asar.unpacked');
38
+ dllPath = (0, _utils3.getCurrentEnvPath)(dllPath);
38
39
  }
39
- var kitFn = new ffi.Library(dllPath, {
40
- 'InspectionKit': ['string', ['string', 'string', 'string']],
41
- 'TheForceKit': ['string', ['string']]
42
- });
40
+ const dllLib = _koffi.default.load(dllPath);
41
+ const dllKit = {
42
+ InspectionKit: dllLib.func('InspectionKit', 'str', ['str', 'str', 'str']),
43
+ TheForceKit: dllLib.func('TheForceKit', 'str', ['str'])
44
+ };
45
+
43
46
  // 挂载到全局对象,兼容主进程和渲染进程
44
- (0, _utils2.setGlobalProperty)('HunterInspectionKit', kitFn);
45
- };
47
+ (0, _utils2.setGlobalProperty)('HunterInspectionKit', dllKit);
48
+ };
49
+ exports.initHunterInspectionKit = initHunterInspectionKit;
@@ -3,14 +3,32 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.currentEnvPath = void 0;
7
- var path = require('path');
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
- var currentEnvPath = exports.currentEnvPath = function currentEnvPath(filePath) {
15
- return path.resolve(__dirname, filePath);
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
+ }
@@ -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
- var name = device.name.toLowerCase();
17
- var pnpId = device.pnpDeviceId.toLowerCase();
13
+ const name = device.name.toLowerCase();
14
+ const pnpId = device.pnpDeviceId.toLowerCase();
18
15
 
19
16
  // 只支持三星、荣耀、华为的手机设备关键词
20
- var phoneKeywords = ['samsung', 'galaxy', 'huawei', 'honor', 'honor magic'];
17
+ const phoneKeywords = ['samsung', 'galaxy', 'huawei', 'honor', 'honor magic'];
21
18
 
22
19
  // 只支持三星、荣耀、华为的手机厂商VID
23
- var phoneVendors = ['VID_04E8',
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
- var isPhoneByName = phoneKeywords.some(function (keyword) {
32
- return name.includes(keyword);
33
- });
28
+ const isPhoneByName = phoneKeywords.some(keyword => name.includes(keyword));
34
29
 
35
30
  // 检查PNPDeviceID中是否包含手机厂商VID
36
- var isPhoneByVendor = phoneVendors.some(function (vendor) {
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
- var parts = pnpDeviceId.split('\\');
42
+ const parts = pnpDeviceId.split('\\');
50
43
  if (parts.length >= 3) {
51
- var serialPart = parts[parts.length - 1];
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
- var devices = [];
69
- var lines = output.split('\r\n');
70
- var currentDevice = {};
71
- var _iterator = _createForOfIteratorHelper(lines),
72
- _step;
73
- try {
74
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
75
- var line = _step.value;
76
- // 跳过空行
77
- if (!line.trim()) {
78
- // 如果当前设备有数据,则保存
79
- if (currentDevice.name && currentDevice.pnpDeviceId) {
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
- } catch (err) {
101
- _iterator.e(err);
102
- } finally {
103
- _iterator.f();
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": "1.1.2",
3
+ "version": "2.0.0-beta.12",
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": "zz pub",
15
- "pub-beta": "zz 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,31 +28,31 @@
28
28
  "dependencies": {
29
29
  "@sentry/browser": "^10.10.0",
30
30
  "compressing": "2.0.0",
31
- "core-js": "3.6.5",
32
- "ffi-napi": "^4.0.3",
33
31
  "fs": "^0.0.1-security",
34
32
  "fs-extra": "^11.3.0",
33
+ "koffi": "2.14.1",
35
34
  "lodash": "4.17.21",
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",
46
45
  "@types/lodash": "4.14.182",
47
46
  "@umijs/fabric": "2.12.2",
48
- "@zz-common/bunlder-module-father": "^0.0.10",
47
+ "@zz-common/bunlder-module-father": "0.0.11",
49
48
  "@zz-common/dev-standard": "^2.0.8",
50
- "@zz-common/zz-cli": "^5.0.3",
51
- "@zz-common/zz-cli-types": "^0.0.9",
49
+ "@zz-common/zz-cli": "5.0.6",
50
+ "@zz-common/zz-cli-types": "0.0.15",
52
51
  "commitizen": "4.2.5",
53
52
  "commitlint": "17.0.2",
54
- "father": "4.1.6",
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,7 +63,9 @@
63
63
  }
64
64
  },
65
65
  "files": [
66
- "lib",
67
- "es"
68
- ]
66
+ "lib"
67
+ ],
68
+ "engines": {
69
+ "node": ">=20.0.0"
70
+ }
69
71
  }