hunter-open-sdk 2.0.0-beta.5 → 2.0.0-beta.7

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 (35) hide show
  1. package/lib/abilities/activate/index.js +52 -0
  2. package/lib/abilities/activate/worker.js +40 -0
  3. package/lib/abilities/erase/index.js +52 -0
  4. package/lib/abilities/erase/worker.js +40 -0
  5. package/lib/abilities/getGeneralReport/index.js +56 -0
  6. package/lib/abilities/getGeneralReport/worker.js +28 -0
  7. package/lib/abilities/getSaaSReport/index.js +56 -0
  8. package/lib/abilities/getSaaSReport/worker.js +20 -0
  9. package/lib/abilities/skip/index.js +52 -0
  10. package/lib/abilities/skip/worker.js +40 -0
  11. package/lib/events/driver/command.js +8 -9
  12. package/lib/events/driver/service.js +23 -34
  13. package/lib/events/driver/winDriver.js +119 -186
  14. package/lib/getAndroidSn/index.js +145 -188
  15. package/lib/helper/deviceHelper.js +19 -37
  16. package/lib/index.js +14 -6
  17. package/lib/registerEvent/index.js +143 -242
  18. package/lib/resources/dll/{libinspectionkit_x64_0.1.0.dll → libinspectionkit_x64_0.1.1.dll} +0 -0
  19. package/lib/resources/mac/{libinspectionkit_arm64_0.1.0.dylib → libinspectionkit_amd64_0.1.1.dylib} +0 -0
  20. package/lib/resources/mac/libinspectionkit_arm64_0.1.1.dylib +0 -0
  21. package/lib/resources/version.online +1 -1
  22. package/lib/utils/utils.command.js +8 -9
  23. package/lib/utils/utils.global.js +74 -40
  24. package/lib/utils/utils.initDll.js +11 -10
  25. package/lib/utils/utils.js +20 -12
  26. package/lib/utils/utils.path.js +4 -3
  27. package/lib/utils/utils.process.js +24 -0
  28. package/lib/utils/utils.sn.js +31 -47
  29. package/package.json +8 -6
  30. package/lib/getGeneralReport/index.js +0 -76
  31. package/lib/getGeneralReport/worker.js +0 -20
  32. package/lib/getSaaSReport/index.js +0 -76
  33. package/lib/getSaaSReport/worker.js +0 -20
  34. package/lib/resources/mac/libinspectionkit_amd64_0.1.0.dylib +0 -0
  35. package/lib/test.js +0 -7
@@ -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.setGlobalProperty = exports.hasGlobalProperty = exports.getUdidListCallKit = exports.getSaaSReportCallKit = exports.getHunterInspectionKit = exports.getGlobalProperty = exports.getGlobalObject = exports.getGeneralReportCallKit = exports.deleteGlobalProperty = exports.callHunterInspectionKit = 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,8 +73,9 @@ 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
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
- 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
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,29 @@ var getSaaSReportCallKit = exports.getSaaSReportCallKit = function getSaaSReport
191
200
  message: '获取SaaS报告失败'
192
201
  }
193
202
  };
194
- };
203
+ };
204
+ exports.getSaaSReportCallKit = getSaaSReportCallKit;
205
+ const getUdidListCallKit = () => {
206
+ const kitParamsObj = {
207
+ cmd: 'device_list'
208
+ };
209
+ const reportRes = callHunterInspectionKit('TheForceKit', JSON.stringify(kitParamsObj));
210
+ const {
211
+ Code,
212
+ Data,
213
+ Message
214
+ } = JSON.parse(reportRes || '{}');
215
+ if (Code !== 0) {
216
+ return {
217
+ code: -1,
218
+ data: [],
219
+ message: Message
220
+ };
221
+ }
222
+ return {
223
+ code: 0,
224
+ data: Data.map(item => item?.Properties?.SerialNumber || ''),
225
+ message: ''
226
+ };
227
+ };
228
+ exports.getUdidListCallKit = getUdidListCallKit;
@@ -16,32 +16,33 @@ var _utils2 = require("./utils.global");
16
16
  * @returns
17
17
  */
18
18
 
19
- var initHunterInspectionKit = exports.initHunterInspectionKit = function initHunterInspectionKit() {
20
- var dllPath;
19
+ const initHunterInspectionKit = () => {
20
+ let dllPath;
21
21
 
22
22
  // 读取本地sdk的version
23
- var versionPath = _path.default.resolve(__dirname, '../resources/version.online');
24
- var version = _fs.default.readFileSync(versionPath, 'utf-8');
23
+ const versionPath = _path.default.resolve(__dirname, '../resources/version.online');
24
+ const version = _fs.default.readFileSync(versionPath, 'utf-8');
25
25
  if ((0, _utils.isMac)()) {
26
26
  if ((0, _utils.isArm64)()) {
27
- dllPath = _path.default.resolve(__dirname, "../resources/mac/libinspectionkit_arm64_".concat(version, ".dylib"));
27
+ dllPath = _path.default.resolve(__dirname, `../resources/mac/libinspectionkit_arm64_${version}.dylib`);
28
28
  }
29
29
  if ((0, _utils.isAmd64)()) {
30
- dllPath = _path.default.resolve(__dirname, "../resources/mac/libinspectionkit_amd64_".concat(version, ".dylib"));
30
+ dllPath = _path.default.resolve(__dirname, `../resources/mac/libinspectionkit_amd64_${version}.dylib`);
31
31
  }
32
32
  } else {
33
- dllPath = _path.default.resolve(__dirname, "../resources/dll/libinspectionkit_x64_".concat(version, ".dll"));
33
+ dllPath = _path.default.resolve(__dirname, `../resources/dll/libinspectionkit_x64_${version}.dll`);
34
34
  }
35
35
  if (!(0, _utils.isDev)()) {
36
36
  // 如果是生产模式 则替换app.asar 路径 为了在生产调用dll
37
37
  dllPath = dllPath.replace('app.asar', 'app.asar.unpacked');
38
38
  }
39
- var dllLib = _koffi.default.load(dllPath);
40
- var dllKit = {
39
+ const dllLib = _koffi.default.load(dllPath);
40
+ const dllKit = {
41
41
  InspectionKit: dllLib.func('InspectionKit', 'str', ['str', 'str', 'str']),
42
42
  TheForceKit: dllLib.func('TheForceKit', 'str', ['str'])
43
43
  };
44
44
 
45
45
  // 挂载到全局对象,兼容主进程和渲染进程
46
46
  (0, _utils2.setGlobalProperty)('HunterInspectionKit', dllKit);
47
- };
47
+ };
48
+ exports.initHunterInspectionKit = initHunterInspectionKit;
@@ -4,16 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.sleep = exports.isWin = exports.isProd = exports.isMac = exports.isLinux = exports.isDev = exports.isArm64 = exports.isAmd64 = void 0;
7
- var isMac = exports.isMac = function isMac() {
7
+ const isMac = () => {
8
8
  return process.platform === 'darwin';
9
9
  };
10
- var isWin = exports.isWin = function isWin() {
10
+ exports.isMac = isMac;
11
+ const isWin = () => {
11
12
  return process.platform === 'win32';
12
13
  };
13
- var isLinux = exports.isLinux = function isLinux() {
14
+ exports.isWin = isWin;
15
+ const isLinux = () => {
14
16
  return process.platform === 'linux';
15
17
  };
16
- var isDev = exports.isDev = function isDev() {
18
+ exports.isLinux = isLinux;
19
+ const isDev = () => {
17
20
  // 检查 NODE_ENV 是否为 development
18
21
  if (process.env.NODE_ENV === 'development') {
19
22
  return true;
@@ -36,19 +39,24 @@ var isDev = exports.isDev = function isDev() {
36
39
 
37
40
  return false;
38
41
  };
39
- var isProd = exports.isProd = function isProd() {
42
+ exports.isDev = isDev;
43
+ const isProd = () => {
40
44
  return process.env.NODE_ENV === 'production';
41
45
  };
42
- var isArm64 = exports.isArm64 = function isArm64() {
46
+ exports.isProd = isProd;
47
+ const isArm64 = () => {
43
48
  return process.arch === 'arm64';
44
49
  };
45
- var isAmd64 = exports.isAmd64 = function isAmd64() {
50
+ exports.isArm64 = isArm64;
51
+ const isAmd64 = () => {
46
52
  return process.arch === 'x64';
47
53
  };
48
- var sleep = exports.sleep = function sleep() {
49
- return new Promise(function (resolve) {
50
- setTimeout(function () {
54
+ exports.isAmd64 = isAmd64;
55
+ const sleep = () => {
56
+ return new Promise(resolve => {
57
+ setTimeout(() => {
51
58
  resolve();
52
- }, 2000);
59
+ }, 1000);
53
60
  });
54
- };
61
+ };
62
+ exports.sleep = sleep;
@@ -4,13 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.currentEnvPath = void 0;
7
- var path = require('path');
7
+ const path = require('path');
8
8
 
9
9
  /**
10
10
  * 当前环境地址转换
11
11
  * @param {*} path
12
12
  * @returns
13
13
  */
14
- var currentEnvPath = exports.currentEnvPath = function currentEnvPath(filePath) {
14
+ const currentEnvPath = filePath => {
15
15
  return path.resolve(__dirname, filePath);
16
- };
16
+ };
17
+ exports.currentEnvPath = currentEnvPath;
@@ -0,0 +1,24 @@
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
+ // console.log('process.type', process.type)
12
+ return process.type;
13
+ }
14
+
15
+ // 是否在主进程
16
+ function isInMainProcess() {
17
+ return getProccessType() === 'browser';
18
+ }
19
+
20
+ // 是否在渲染进程
21
+ // eslint-disable-next-line no-unused-vars
22
+ function isInRenderProcess() {
23
+ return getProccessType() === 'renderer';
24
+ }
@@ -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": "2.0.0-beta.5",
3
+ "version": "2.0.0-beta.7",
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,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,7 +35,8 @@
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
42
  "@babel/plugin-transform-runtime": "7.21.0",
@@ -55,7 +55,9 @@
55
55
  "lint-staged": "10.0.8",
56
56
  "path-to-regexp": "2.4.0",
57
57
  "typedoc": "0.23.9",
58
- "typescript": "4.7.4"
58
+ "typescript": "4.7.4",
59
+ "minimatch": "3.0.0",
60
+ "core-js": "3.6.5"
59
61
  },
60
62
  "config": {
61
63
  "commitizen": {
@@ -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
- };
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- var _utils = require("../utils/utils.global");
4
- // 处理主进程消息
5
- function onMainMessage(event) {
6
- // console.log('worker thread worker onmessage event.data', event.data)
7
-
8
- var _event$data = event.data,
9
- type = _event$data.type,
10
- params = _event$data.params;
11
- switch (type) {
12
- case 'getGeneralReport':
13
- var reportRes = (0, _utils.getGeneralReportCallKit)(params);
14
- self.postMessage(reportRes);
15
- break;
16
- default:
17
- break;
18
- }
19
- }
20
- self.onmessage = onMainMessage;