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

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.
@@ -8,42 +8,42 @@ exports.UnregisterAndroidSn = exports.GetAndroidSn = 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
- var hadRegisterUsb = false; // 是否已经注册过usb事件
16
- var isPause = false; // 是否暂停获取sn
11
+ var _utils = require("../utils/utils.js");
12
+ var _utilsSn = require("../utils/utils.sn.js");
13
+ var _child_process = require("child_process");
14
+ // const childProcess = require('child_process')
15
+ // const exec = childProcess.exec
16
+ var attachHandler = null;
17
+ var customWebUSB = new _usb.WebUSB({
18
+ allowAllDevices: true
19
+ });
17
20
 
18
21
  // mac获取sn
19
22
  var getMacSn = /*#__PURE__*/function () {
20
23
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(device, callBack) {
21
24
  var _deviceInfo$productNa, _deviceInfo$manufactu;
22
- var attachDeviceId, customWebUSB, deviceList, currentDevice, deviceInfo, productName, manufacturerName, supportedBrands, isSupportedBrand;
25
+ var attachDeviceId, deviceList, currentDevice, deviceInfo, productName, manufacturerName, supportedBrands, isSupportedBrand;
23
26
  return _regenerator.default.wrap(function _callee$(_context) {
24
27
  while (1) switch (_context.prev = _context.next) {
25
28
  case 0:
26
29
  // 拿到当前连接的设备deviceAddress 作为标识去usb列表筛选
27
30
  attachDeviceId = device.deviceAddress;
28
- customWebUSB = new _usb.WebUSB({
29
- allowAllDevices: true
30
- });
31
- _context.next = 4;
31
+ _context.next = 3;
32
32
  return customWebUSB.getDevices();
33
- case 4:
33
+ case 3:
34
34
  deviceList = _context.sent;
35
35
  if (attachDeviceId) {
36
- _context.next = 7;
36
+ _context.next = 6;
37
37
  break;
38
38
  }
39
39
  return _context.abrupt("return");
40
- case 7:
40
+ case 6:
41
41
  // 删选出当前的设备信息 为获取到serialNumber
42
42
  currentDevice = deviceList.filter(function (item) {
43
43
  return item.device.deviceAddress == attachDeviceId;
44
44
  });
45
45
  if (currentDevice.length) {
46
- _context.next = 11;
46
+ _context.next = 10;
47
47
  break;
48
48
  }
49
49
  callBack({
@@ -52,7 +52,7 @@ var getMacSn = /*#__PURE__*/function () {
52
52
  message: '获取SN失败'
53
53
  });
54
54
  return _context.abrupt("return");
55
- case 11:
55
+ case 10:
56
56
  // 检查设备是否为支持的三星、华为、荣耀手机品牌
57
57
  deviceInfo = currentDevice[0];
58
58
  productName = ((_deviceInfo$productNa = deviceInfo.productName) === null || _deviceInfo$productNa === void 0 ? void 0 : _deviceInfo$productNa.toLowerCase()) || '';
@@ -62,7 +62,7 @@ var getMacSn = /*#__PURE__*/function () {
62
62
  return productName.includes(brand) || manufacturerName.includes(brand);
63
63
  });
64
64
  if (isSupportedBrand) {
65
- _context.next = 19;
65
+ _context.next = 18;
66
66
  break;
67
67
  }
68
68
  callBack({
@@ -71,7 +71,7 @@ var getMacSn = /*#__PURE__*/function () {
71
71
  message: '暂不支持该品牌手机查询SN'
72
72
  });
73
73
  return _context.abrupt("return");
74
- case 19:
74
+ case 18:
75
75
  callBack({
76
76
  code: 0,
77
77
  data: {
@@ -79,7 +79,7 @@ var getMacSn = /*#__PURE__*/function () {
79
79
  },
80
80
  message: '获取SN成功'
81
81
  });
82
- case 20:
82
+ case 19:
83
83
  case "end":
84
84
  return _context.stop();
85
85
  }
@@ -99,7 +99,7 @@ var getWinSn = /*#__PURE__*/function () {
99
99
  case 0:
100
100
  // windows 需要运行命令获取sn
101
101
  cmdStr = "wmic path Win32_PnPEntity where \"DeviceID like 'USB%'\" get Name, PNPDeviceID /value";
102
- exec(cmdStr, function (err, stdout, stderr) {
102
+ (0, _child_process.exec)(cmdStr, function (err, stdout, stderr) {
103
103
  if (err) {
104
104
  // 运行失败 则直接返回获取失败
105
105
  callBack({
@@ -120,7 +120,7 @@ var getWinSn = /*#__PURE__*/function () {
120
120
  }
121
121
 
122
122
  // 处理WMIC输出并提取手机序列号
123
- var phoneDevices = (0, _utils2.parseWmicOutput)(stdout);
123
+ var phoneDevices = (0, _utilsSn.parseWmicOutput)(stdout);
124
124
  if (phoneDevices.length === 0) {
125
125
  callBack({
126
126
  code: -1,
@@ -161,68 +161,47 @@ var getWinSn = /*#__PURE__*/function () {
161
161
  * @param {Object} params - 参数
162
162
  * @param {Function} callBack - 回调函数
163
163
  */
164
+
164
165
  var GetAndroidSn = exports.GetAndroidSn = function GetAndroidSn(params, callBack) {
165
- if (hadRegisterUsb) {
166
- isPause = false;
167
- return;
168
- }
169
- hadRegisterUsb = true;
170
- _usb.usb.on('attach', /*#__PURE__*/function () {
166
+ if (attachHandler) return;
167
+ // 定义处理函数并保存引用
168
+ attachHandler = /*#__PURE__*/function () {
171
169
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(device) {
172
- var idVendor;
173
170
  return _regenerator.default.wrap(function _callee3$(_context3) {
174
171
  while (1) switch (_context3.prev = _context3.next) {
175
172
  case 0:
176
- if (!isPause) {
177
- _context3.next = 2;
178
- break;
179
- }
180
- return _context3.abrupt("return");
181
- case 2:
182
- idVendor = device.deviceDescriptor.idVendor;
183
- if (!(idVendor == 1452)) {
184
- _context3.next = 5;
185
- break;
186
- }
187
- return _context3.abrupt("return");
188
- case 5:
189
- callBack({
190
- data: {
191
- eventName: 'type_usb_android_device_result',
192
- eventCode: 0
193
- }
194
- });
195
- if (!(0, _utils.isMac)()) {
196
- _context3.next = 9;
197
- break;
198
- }
199
- // mac获取sn
200
- getMacSn(device, callBack);
201
- return _context3.abrupt("return");
202
- case 9:
203
- if (!(0, _utils.isWin)()) {
204
- _context3.next = 12;
205
- break;
206
- }
207
- // win获取sn
208
- getWinSn(device, callBack);
209
- return _context3.abrupt("return");
210
- case 12:
173
+ console.log('device', device);
174
+ // const {idVendor} = device.deviceDescriptor;
175
+ // if(idVendor == 1452) return;
176
+
177
+ // callBack({
178
+ // data: {
179
+ // eventName: 'type_usb_android_device_result',
180
+ // eventCode: 0
181
+ // }
182
+ // });
183
+
184
+ // if (isMac()) {
185
+ // getMacSn(device, callBack);
186
+ // } else if (isWin()) {
187
+ // getWinSn(device, callBack);
188
+ // }
189
+ case 1:
211
190
  case "end":
212
191
  return _context3.stop();
213
192
  }
214
193
  }, _callee3);
215
194
  }));
216
- return function (_x5) {
195
+ return function attachHandler(_x5) {
217
196
  return _ref3.apply(this, arguments);
218
197
  };
219
- }());
220
- _usb.usb.on('detach', function () {
221
- if (isPause) {
222
- return;
223
- }
224
- });
198
+ }();
199
+ customWebUSB.addEventListener('connect', attachHandler);
225
200
  };
226
201
  var UnregisterAndroidSn = exports.UnregisterAndroidSn = function UnregisterAndroidSn() {
227
- isPause = true;
202
+ // 移除事件监听器
203
+ if (attachHandler) {
204
+ customWebUSB.removeEventListener('connect', attachHandler);
205
+ attachHandler = null;
206
+ }
228
207
  };
package/lib/test.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ var _require = require("./getAndroidSn/index.js"),
4
+ GetAndroidSn = _require.GetAndroidSn;
5
+ GetAndroidSn({}, function (res) {
6
+ console.log(res);
7
+ });
@@ -30,9 +30,10 @@ var isDev = exports.isDev = function isDev() {
30
30
  }
31
31
 
32
32
  // 检查是否在 Electron 主进程中,且没有打包
33
- if (process.type === 'browser' && !process.resourcesPath.includes('app.asar')) {
34
- return true;
35
- }
33
+ // if (process.type === 'browser' && !process.resourcesPath.includes('app.asar')) {
34
+ // return true
35
+ // }
36
+
36
37
  return false;
37
38
  };
38
39
  var isProd = exports.isProd = function isProd() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hunter-open-sdk",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0-beta.5",
4
4
  "description": "采货侠SaaS版本桌面端sdk",
5
5
  "scripts": {
6
6
  "start": "zz dev",