hunter-open-sdk 0.0.20 → 0.0.22

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.
@@ -15,6 +15,7 @@ var _fsExtra = _interopRequireDefault(require("fs-extra"));
15
15
  // import { app } from 'electron'
16
16
  // import { command } from '../../utils/utils.command'
17
17
 
18
+ var Sentry = require("@sentry/browser");
18
19
  var sudo = require('sudo-prompt');
19
20
  var path = require('path');
20
21
  var fs = require('fs');
@@ -35,6 +36,7 @@ try {
35
36
  _fsExtra.default.ensureDirSync(CACHE_PATH);
36
37
  } catch (e) {
37
38
  console.error('创建缓存目录失败:', e);
39
+ Sentry.captureException('创建缓存目录失败:' + JSON.stringify(e));
38
40
  }
39
41
  var checkProcess = function checkProcess() {
40
42
  return new Promise(function (resolve, reject) {
@@ -131,6 +133,7 @@ var installDriver = function installDriver() {
131
133
  checkProcessTimer();
132
134
  if (error) {
133
135
  console.error('驱动安装失败:', error);
136
+ Sentry.captureException('驱动安装失败:' + JSON.stringify(error));
134
137
  reject(error); // 安装失败
135
138
  } else {
136
139
  console.log('驱动安装成功');
@@ -148,6 +151,7 @@ var uncopressingFile = function uncopressingFile(filePath) {
148
151
  resolve(true);
149
152
  }).catch(function (err) {
150
153
  console.error('文件解压失败:', err);
154
+ Sentry.captureException('文件解压失败:' + JSON.stringify(err));
151
155
  resolve(false);
152
156
  });
153
157
  });
@@ -201,6 +205,7 @@ function downloadDriver(onProgress) {
201
205
  }
202
206
  }).on('error', function (err) {
203
207
  console.error('驱动下载失败', err);
208
+ Sentry.captureException('驱动下载失败:' + JSON.stringify(err));
204
209
  fileStream.end(); // 确保关闭文件流
205
210
  reject(err);
206
211
  }).pipe(fileStream).once('close', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
@@ -229,26 +234,30 @@ function downloadDriver(onProgress) {
229
234
  resolve();
230
235
  }).catch(function (err) {
231
236
  console.error('驱动安装失败:', err);
237
+ Sentry.captureException('驱动安装失败:' + JSON.stringify(err));
232
238
  reject(err);
233
239
  });
234
240
  } else {
235
241
  console.error('解压失败');
242
+ Sentry.captureException('解压失败');
236
243
  reject(new Error('解压失败'));
237
244
  }
238
- _context2.next = 15;
245
+ _context2.next = 16;
239
246
  break;
240
247
  case 11:
241
248
  _context2.prev = 11;
242
249
  _context2.t0 = _context2["catch"](3);
243
250
  console.error('解压或安装过程中出错:', _context2.t0);
251
+ Sentry.captureException('解压或安装过程中出错:' + JSON.stringify(_context2.t0));
244
252
  reject(_context2.t0);
245
- case 15:
253
+ case 16:
246
254
  case "end":
247
255
  return _context2.stop();
248
256
  }
249
257
  }, _callee2, null, [[3, 11]]);
250
258
  }))).once('error', function (err) {
251
259
  console.error('文件流写入错误:', err);
260
+ Sentry.captureException('文件流写入错误:' + JSON.stringify(err));
252
261
  reject(err);
253
262
  });
254
263
  });
@@ -8,58 +8,167 @@ exports.default = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
10
  var _usb = require("usb");
11
+ var _utils = require("../utils/utils");
12
+ var _utils2 = require("../utils/utils.sn");
13
+ var childProcess = require('child_process');
14
+ var exec = childProcess.exec;
15
+
16
+ // mac获取sn
17
+ var getMacSn = /*#__PURE__*/function () {
18
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(device, callBack) {
19
+ var attachDeviceId, customWebUSB, deviceList, currentDevice;
20
+ return _regenerator.default.wrap(function _callee$(_context) {
21
+ while (1) switch (_context.prev = _context.next) {
22
+ case 0:
23
+ // 拿到当前连接的设备deviceAddress 作为标识去usb列表筛选
24
+ attachDeviceId = device.deviceAddress;
25
+ customWebUSB = new _usb.WebUSB({
26
+ allowAllDevices: true
27
+ });
28
+ _context.next = 4;
29
+ return customWebUSB.getDevices();
30
+ case 4:
31
+ deviceList = _context.sent;
32
+ if (attachDeviceId) {
33
+ _context.next = 7;
34
+ break;
35
+ }
36
+ return _context.abrupt("return");
37
+ case 7:
38
+ // 删选出当前的设备信息 为获取到serialNumber
39
+ currentDevice = deviceList.filter(function (item) {
40
+ return item.device.deviceAddress == attachDeviceId;
41
+ });
42
+ if (currentDevice.length) {
43
+ _context.next = 11;
44
+ break;
45
+ }
46
+ callBack({
47
+ code: -1,
48
+ data: {},
49
+ message: '获取SN失败'
50
+ });
51
+ return _context.abrupt("return");
52
+ case 11:
53
+ callBack({
54
+ code: 0,
55
+ data: {
56
+ SN: currentDevice[0].serialNumber
57
+ },
58
+ message: '获取SN成功'
59
+ });
60
+ case 12:
61
+ case "end":
62
+ return _context.stop();
63
+ }
64
+ }, _callee);
65
+ }));
66
+ return function getMacSn(_x, _x2) {
67
+ return _ref.apply(this, arguments);
68
+ };
69
+ }();
70
+
71
+ // win获取sn
72
+ var getWinSn = /*#__PURE__*/function () {
73
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(device, callBack) {
74
+ var cmdStr;
75
+ return _regenerator.default.wrap(function _callee2$(_context2) {
76
+ while (1) switch (_context2.prev = _context2.next) {
77
+ case 0:
78
+ // windows 需要运行命令获取sn
79
+ cmdStr = "wmic path Win32_PnPEntity where \"DeviceID like 'USB%'\" get Name, PNPDeviceID /value";
80
+ exec(cmdStr, function (err, stdout, stderr) {
81
+ if (err) {
82
+ // 运行失败 则直接返回获取失败
83
+ callBack({
84
+ code: -1,
85
+ data: {},
86
+ message: "windows\u8FD0\u884C\u7A0B\u5E8F\u83B7\u53D6SN\u5931\u8D25err: ".concat(err)
87
+ });
88
+ return;
89
+ }
90
+ if (stderr) {
91
+ // 运行失败 则直接返回获取失败
92
+ callBack({
93
+ code: -1,
94
+ data: {},
95
+ message: "windows\u8FD0\u884C\u7A0B\u5E8F\u83B7\u53D6SN\u5931\u8D25stderr: ".concat(stderr)
96
+ });
97
+ return;
98
+ }
99
+
100
+ // 处理WMIC输出并提取手机序列号
101
+ var phoneDevices = (0, _utils2.parseWmicOutput)(stdout);
102
+ if (phoneDevices.length === 0) {
103
+ callBack({
104
+ code: -1,
105
+ data: {},
106
+ message: "\u672A\u68C0\u6D4B\u5230\u624B\u673AUSB\u8BBE\u5907"
107
+ });
108
+ } else {
109
+ console.log('检测到的手机设备:');
110
+ var sn = phoneDevices[0].serial;
111
+ callBack({
112
+ code: 0,
113
+ data: {
114
+ SN: sn
115
+ },
116
+ message: "\u83B7\u53D6SN\u6210\u529F"
117
+ });
118
+ // phoneDevices.forEach(device => {
119
+ // console.log(`设备名称: ${device.name}`);
120
+ // console.log(`序列号: ${device.serial}`);
121
+ // console.log(`PNPDeviceID: ${device.pnpDeviceId}`);
122
+ // console.log('---');
123
+ // });
124
+ }
125
+ });
126
+ case 2:
127
+ case "end":
128
+ return _context2.stop();
129
+ }
130
+ }, _callee2);
131
+ }));
132
+ return function getWinSn(_x3, _x4) {
133
+ return _ref2.apply(this, arguments);
134
+ };
135
+ }();
136
+
137
+ /**
138
+ * 获取Android SN
139
+ * @param {Object} params - 参数
140
+ * @param {Function} callBack - 回调函数
141
+ */
11
142
  var GetAndroidSn = function GetAndroidSn(params, callBack) {
143
+ console.log('GetAndroidSn params', params);
12
144
  _usb.usb.on('attach', /*#__PURE__*/function () {
13
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(device) {
14
- var attachDeviceId, customWebUSB, deviceList, currentDevice;
15
- return _regenerator.default.wrap(function _callee$(_context) {
16
- while (1) switch (_context.prev = _context.next) {
145
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(device) {
146
+ return _regenerator.default.wrap(function _callee3$(_context3) {
147
+ while (1) switch (_context3.prev = _context3.next) {
17
148
  case 0:
18
- // 拿到当前连接的设备deviceAddress 作为标识去usb列表筛选
19
- attachDeviceId = device.deviceAddress;
20
- customWebUSB = new _usb.WebUSB({
21
- allowAllDevices: true
22
- });
23
- _context.next = 4;
24
- return customWebUSB.getDevices();
25
- case 4:
26
- deviceList = _context.sent;
27
- if (attachDeviceId) {
28
- _context.next = 7;
149
+ if (!(0, _utils.isMac)()) {
150
+ _context3.next = 3;
29
151
  break;
30
152
  }
31
- return _context.abrupt("return");
32
- case 7:
33
- // 删选出当前的设备信息 为获取到serialNumber
34
- currentDevice = deviceList.filter(function (item) {
35
- return item.device.deviceAddress == attachDeviceId;
36
- });
37
- if (currentDevice.length) {
38
- _context.next = 11;
153
+ // mac获取sn
154
+ getMacSn(device, callBack);
155
+ return _context3.abrupt("return");
156
+ case 3:
157
+ if (!(0, _utils.isWin)()) {
158
+ _context3.next = 6;
39
159
  break;
40
160
  }
41
- callBack({
42
- code: -1,
43
- data: {},
44
- message: '获取SN失败'
45
- });
46
- return _context.abrupt("return");
47
- case 11:
48
- callBack({
49
- code: 0,
50
- data: {
51
- SN: currentDevice[0].serialNumber
52
- },
53
- message: '获取SN成功'
54
- });
55
- case 12:
161
+ // win获取sn
162
+ getWinSn(device, callBack);
163
+ return _context3.abrupt("return");
164
+ case 6:
56
165
  case "end":
57
- return _context.stop();
166
+ return _context3.stop();
58
167
  }
59
- }, _callee);
168
+ }, _callee3);
60
169
  }));
61
- return function (_x) {
62
- return _ref.apply(this, arguments);
170
+ return function (_x5) {
171
+ return _ref3.apply(this, arguments);
63
172
  };
64
173
  }());
65
174
  _usb.usb.on('detach', function () {});
@@ -1,35 +1,77 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.default = void 0;
8
+ var _path = _interopRequireDefault(require("path"));
7
9
  var _utils = require("../utils/utils.global");
8
- var GetGeneralReport = function GetGeneralReport(params, callBack) {
9
- var reportRes = (0, _utils.callHunterInspectionKit)('InspectionKit', params, 'saas_report', params);
10
- if (reportRes) {
11
- var reportResObj = JSON.parse(reportRes);
12
- var Code = reportResObj.Code,
13
- Data = reportResObj.Data;
14
- if (Code == 0 && Data) {
15
- callBack({
16
- code: 0,
17
- data: Data,
18
- message: '获取报告成功'
19
- });
20
- } else {
21
- callBack({
22
- code: -1,
23
- data: {},
24
- message: '获取报告结果为空'
25
- });
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;
26
52
  }
27
- } else {
28
- callBack({
29
- code: -1,
30
- data: {},
31
- message: '获取报告失败'
32
- });
53
+ });
54
+ }
55
+
56
+ // 发起获取报告消息
57
+ function getReport(params) {
58
+ worker && worker.postMessage({
59
+ type: 'getGeneralReport',
60
+ params: params
61
+ });
62
+ }
63
+
64
+ // 获取报告
65
+ function GetGeneralReport(params, callBack) {
66
+ // 如果是在主进程,则直接获取报告
67
+ if (isInMainProcess()) {
68
+ var reportRes = (0, _utils.getGeneralReportCallKit)(params);
69
+ return callBack(reportRes.data);
33
70
  }
34
- };
71
+
72
+ // 如果是在渲染进程,则通过worker获取报告
73
+ initWorker();
74
+ addWorkerListener(callBack);
75
+ getReport(params);
76
+ }
35
77
  var _default = exports.default = GetGeneralReport;
@@ -0,0 +1,20 @@
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;
package/lib/index.js CHANGED
@@ -8,6 +8,12 @@ exports.default = void 0;
8
8
  var _registerEvent = _interopRequireDefault(require("./registerEvent"));
9
9
  var _getGeneralReport = _interopRequireDefault(require("./getGeneralReport"));
10
10
  var _getAndroidSn = _interopRequireDefault(require("./getAndroidSn"));
11
+ var Sentry = require("@sentry/browser");
12
+ Sentry.init({
13
+ dsn: "https://8a5296c59083430fbac0756f56ddbf5d@sentry.zhuanzhuan.com/2300",
14
+ tracesSampleRate: 1.0
15
+ });
16
+ console.log('Sentry initialized');
11
17
  // 初始化
12
18
  var _default = exports.default = {
13
19
  registerEvent: _registerEvent.default,
@@ -8,13 +8,13 @@ exports.default = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
10
  var _utils = require("../utils/utils");
11
- var _utils2 = require("../utils/utils.initDll");
12
11
  var _winDriver = require("../events/driver/winDriver");
13
- var _utils3 = require("../utils/utils.global");
12
+ var _utils2 = require("../utils/utils.global");
14
13
  var usbmux = require('usbmux');
15
14
  var path = require('path');
16
15
  var request = require("request");
17
16
  var fs = require('fs');
17
+ var Sentry = require("@sentry/browser");
18
18
 
19
19
  // saas回调
20
20
  var saasCallBack;
@@ -23,9 +23,6 @@ var saasCallBack;
23
23
  var isDriverInstalling = false;
24
24
  var isDriverReady = false;
25
25
 
26
- // 初始化dll
27
- (0, _utils2.HunterInspectionKit)();
28
-
29
26
  /**
30
27
  * 获取资源文件的基础路径
31
28
  */
@@ -65,7 +62,7 @@ var DevicePair = /*#__PURE__*/function () {
65
62
  cmd: 'trust_status',
66
63
  udid: udid
67
64
  });
68
- devicePair = (0, _utils3.callHunterInspectionKit)('TheForceKit', JSON.stringify(paramsObj));
65
+ devicePair = (0, _utils2.callHunterInspectionKit)('TheForceKit', JSON.stringify(paramsObj));
69
66
  if (!devicePair) {
70
67
  _context.next = 15;
71
68
  break;
@@ -117,7 +114,7 @@ var writeDllVersion = function writeDllVersion(version) {
117
114
  }
118
115
  console.log('========写入version成功');
119
116
  // 写入成功后 重新初始化dll
120
- (0, _utils2.HunterInspectionKit)();
117
+ HunterInspectionKit();
121
118
  saasCallBack({
122
119
  data: {
123
120
  eventName: 'type_update_result',
@@ -168,7 +165,7 @@ var updateDllFileCheck = function updateDllFileCheck() {
168
165
  label: (0, _utils.isWin)() ? 'Windows' : 'Mac',
169
166
  params: {}
170
167
  };
171
- var updateRes = (0, _utils3.callHunterInspectionKit)('TheForceKit', JSON.stringify(updateParams));
168
+ var updateRes = (0, _utils2.callHunterInspectionKit)('TheForceKit', JSON.stringify(updateParams));
172
169
  if (updateRes) {
173
170
  var updateResObj = JSON.parse(updateRes);
174
171
  var Code = updateResObj.Code,
@@ -238,6 +235,7 @@ var checkAndInstallDriver = function checkAndInstallDriver() {
238
235
  }).catch(function (err) {
239
236
  // 失败
240
237
  console.error('驱动下载或安装失败', err);
238
+ Sentry.captureException('驱动下载或安装失败:' + JSON.stringify(err));
241
239
  isDriverInstalling = false;
242
240
  saasCallBack({
243
241
  data: {
@@ -248,6 +246,7 @@ var checkAndInstallDriver = function checkAndInstallDriver() {
248
246
  });
249
247
  }).catch(function (err) {
250
248
  console.error('驱动检测失败', err);
249
+ Sentry.captureException('驱动检测失败:' + JSON.stringify(err));
251
250
  });
252
251
  };
253
252
  var RegisterEvent = function RegisterEvent(params, callBack) {
@@ -269,6 +268,7 @@ var RegisterEvent = function RegisterEvent(params, callBack) {
269
268
  }
270
269
  return _context2.abrupt("return");
271
270
  case 2:
271
+ Sentry.captureException("\u51FA\u9519\u5566\u6D4B\u8BD5");
272
272
  // 插入设备通知
273
273
  saasCallBack({
274
274
  data: {
@@ -315,7 +315,7 @@ var RegisterEvent = function RegisterEvent(params, callBack) {
315
315
  // 有驱动,直接运行脚本
316
316
  DevicePair(udid, params);
317
317
  }
318
- case 4:
318
+ case 5:
319
319
  case "end":
320
320
  return _context2.stop();
321
321
  }
@@ -335,6 +335,7 @@ var RegisterEvent = function RegisterEvent(params, callBack) {
335
335
  });
336
336
  }).on('error', function (err) {
337
337
  console.log('usb连接错误:', err);
338
+ Sentry.captureException('usb连接错误:' + JSON.stringify(err));
338
339
  var errMsg = "usb\u8FDE\u63A5\u9519\u8BEF\uFF1A".concat(err);
339
340
  throw new Error(errMsg);
340
341
  });
@@ -3,12 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setGlobalProperty = exports.hasGlobalProperty = exports.getHunterInspectionKit = exports.getGlobalProperty = exports.getGlobalObject = exports.deleteGlobalProperty = exports.callHunterInspectionKit = void 0;
6
+ exports.setGlobalProperty = exports.hasGlobalProperty = exports.getHunterInspectionKit = exports.getGlobalProperty = exports.getGlobalObject = exports.getGeneralReportCallKit = exports.deleteGlobalProperty = exports.callHunterInspectionKit = void 0;
7
+ var _utils = require("../utils/utils.initDll");
7
8
  /**
8
9
  * 全局对象兼容性处理工具
9
10
  * 兼容Electron主进程(global)和渲染进程(window)环境
10
11
  */
11
-
12
+ var Sentry = require("@sentry/browser");
12
13
  /**
13
14
  * 获取全局对象
14
15
  * @returns {Object} 全局对象
@@ -86,17 +87,64 @@ var getHunterInspectionKit = exports.getHunterInspectionKit = function getHunter
86
87
  */
87
88
  var callHunterInspectionKit = exports.callHunterInspectionKit = function callHunterInspectionKit(methodName) {
88
89
  var kit = getHunterInspectionKit();
90
+ if (!kit) {
91
+ (0, _utils.HunterInspectionKit)();
92
+ kit = getHunterInspectionKit();
93
+ }
89
94
  if (!kit || typeof kit[methodName] !== 'function') {
90
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"));
91
97
  return null;
92
98
  }
93
99
  try {
100
+ var _kit;
94
101
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
95
102
  args[_key - 1] = arguments[_key];
96
103
  }
97
- return kit[methodName].apply(kit, args);
104
+ return (_kit = kit)[methodName].apply(_kit, args);
98
105
  } catch (error) {
99
106
  console.error("\u8C03\u7528HunterInspectionKit.".concat(methodName, "\u5931\u8D25:"), error);
107
+ Sentry.captureException("\u8C03\u7528HunterInspectionKit.".concat(methodName, "\u5931\u8D25:"), error);
100
108
  return null;
101
109
  }
110
+ };
111
+
112
+ /**
113
+ * 获取报告
114
+ * @param {Object} params 参数
115
+ * @returns {Object} 报告结果
116
+ */
117
+ var getGeneralReportCallKit = exports.getGeneralReportCallKit = function getGeneralReportCallKit(params) {
118
+ var reportRes = callHunterInspectionKit('InspectionKit', params, 'saas_report', params);
119
+ if (reportRes) {
120
+ var reportResObj = JSON.parse(reportRes);
121
+ var Code = reportResObj.Code,
122
+ Data = reportResObj.Data;
123
+ if (Code == 0 && Data) {
124
+ return {
125
+ type: 'getGeneralReportSuccess',
126
+ data: {
127
+ code: 0,
128
+ data: Data,
129
+ message: '获取报告成功'
130
+ }
131
+ };
132
+ }
133
+ return {
134
+ type: 'getGeneralReportFail',
135
+ data: {
136
+ code: -1,
137
+ data: {},
138
+ message: '获取报告结果为空'
139
+ }
140
+ };
141
+ }
142
+ return {
143
+ type: 'getGeneralReportFail',
144
+ data: {
145
+ code: -1,
146
+ data: {},
147
+ message: '获取报告失败'
148
+ }
149
+ };
102
150
  };
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
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
+ /**
11
+ * 判断设备是否为手机设备
12
+ * @param {Object} device - 设备信息
13
+ * @returns {boolean} 是否为手机设备
14
+ */
15
+ function isPhoneDevice(device) {
16
+ var name = device.name.toLowerCase();
17
+ var pnpId = device.pnpDeviceId.toLowerCase();
18
+
19
+ // 常见手机设备关键词
20
+ var phoneKeywords = ['android', 'phone', 'mobile', 'iphone', 'samsung', 'huawei', 'xiaomi', 'oppo', 'vivo', 'meizu', 'google', 'pixel', 'oneplus', 'nokia', 'sony'];
21
+
22
+ // 常见手机厂商VID
23
+ var phoneVendors = ['VID_18D1',
24
+ // Google
25
+ 'VID_22B8',
26
+ // Motorola
27
+ 'VID_04E8',
28
+ // Samsung
29
+ 'VID_0FCE',
30
+ // Sony Ericsson
31
+ 'VID_1004',
32
+ // LG
33
+ 'VID_12D1',
34
+ // Huawei
35
+ 'VID_2717',
36
+ // Xiaomi
37
+ 'VID_2A45',
38
+ // OnePlus
39
+ 'VID_05C6',
40
+ // Qualcomm
41
+ 'VID_0BB4' // HTC
42
+ ];
43
+
44
+ // 检查名称中是否包含手机关键词
45
+ var isPhoneByName = phoneKeywords.some(function (keyword) {
46
+ return name.includes(keyword);
47
+ });
48
+
49
+ // 检查PNPDeviceID中是否包含手机厂商VID
50
+ var isPhoneByVendor = phoneVendors.some(function (vendor) {
51
+ return pnpId.includes(vendor.toLowerCase());
52
+ });
53
+ return isPhoneByName || isPhoneByVendor;
54
+ }
55
+
56
+ /**
57
+ * 从PNPDeviceID中提取序列号
58
+ * @param {string} pnpDeviceId - PNPDeviceID
59
+ * @returns {string} 序列号
60
+ */
61
+ function extractSerialNumber(pnpDeviceId) {
62
+ // USB设备ID格式通常为: USB\VID_v(4)&PID_d(4)\序列号
63
+ var parts = pnpDeviceId.split('\\');
64
+ if (parts.length >= 3) {
65
+ var serialPart = parts[parts.length - 1];
66
+
67
+ // 验证序列号格式(通常不包含&和#等特殊字符)
68
+ if (serialPart && !serialPart.includes('&') && !serialPart.includes('#')) {
69
+ return serialPart;
70
+ }
71
+ }
72
+
73
+ // 如果无法提取序列号,返回空字符串
74
+ return '';
75
+ }
76
+ /**
77
+ * 解析WMIC输出并提取手机设备信息
78
+ * @param {string} output - WMIC命令输出
79
+ * @returns {Array} 手机设备信息数组
80
+ */
81
+ function parseWmicOutput(output) {
82
+ var devices = [];
83
+ var lines = output.split('\r\n');
84
+ var currentDevice = {};
85
+ var _iterator = _createForOfIteratorHelper(lines),
86
+ _step;
87
+ try {
88
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
89
+ var line = _step.value;
90
+ // 跳过空行
91
+ if (!line.trim()) {
92
+ // 如果当前设备有数据,则保存
93
+ if (currentDevice.name && currentDevice.pnpDeviceId) {
94
+ // 检查是否为手机设备
95
+ if (isPhoneDevice(currentDevice)) {
96
+ // 提取序列号
97
+ currentDevice.serial = extractSerialNumber(currentDevice.pnpDeviceId);
98
+ devices.push(currentDevice);
99
+ }
100
+ }
101
+ currentDevice = {};
102
+ continue;
103
+ }
104
+
105
+ // 解析Name和PNPDeviceID
106
+ if (line.startsWith('Name=')) {
107
+ currentDevice.name = line.substring(5).trim();
108
+ } else if (line.startsWith('PNPDeviceID=')) {
109
+ currentDevice.pnpDeviceId = line.substring(12).trim();
110
+ }
111
+ }
112
+
113
+ // 处理最后一个设备
114
+ } catch (err) {
115
+ _iterator.e(err);
116
+ } finally {
117
+ _iterator.f();
118
+ }
119
+ if (currentDevice.name && currentDevice.pnpDeviceId && isPhoneDevice(currentDevice)) {
120
+ currentDevice.serial = extractSerialNumber(currentDevice.pnpDeviceId);
121
+ devices.push(currentDevice);
122
+ }
123
+ return devices;
124
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hunter-open-sdk",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "采货侠SaaS版本桌面端sdk",
5
5
  "scripts": {
6
6
  "start": "zz dev",
@@ -26,6 +26,7 @@
26
26
  "author": "xiexing <xiexing@zhuanzhuan.com>",
27
27
  "license": "ISC",
28
28
  "dependencies": {
29
+ "@sentry/browser": "^10.10.0",
29
30
  "compressing": "2.0.0",
30
31
  "core-js": "3.6.5",
31
32
  "ffi-napi": "^4.0.3",