hunter-open-sdk 2.0.0-beta.2 → 2.0.0-beta.21
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/lib/abilities/activate/index.js +51 -0
- package/lib/abilities/activate/worker.js +19 -0
- package/lib/abilities/erase/index.js +51 -0
- package/lib/abilities/erase/worker.js +19 -0
- package/lib/abilities/eventManager/index.js +338 -0
- package/lib/abilities/getAndroidSn/index.js +165 -0
- package/lib/abilities/getGeneralReport/index.js +75 -0
- package/lib/abilities/getGeneralReport/worker.js +38 -0
- package/lib/abilities/getSaaSReport/index.js +51 -0
- package/lib/abilities/getSaaSReport/worker.js +21 -0
- package/lib/abilities/installApp/index.js +51 -0
- package/lib/abilities/installApp/worker.js +19 -0
- package/lib/abilities/reboot/index.js +51 -0
- package/lib/abilities/reboot/worker.js +19 -0
- package/lib/abilities/shutdown/index.js +51 -0
- package/lib/abilities/shutdown/worker.js +19 -0
- package/lib/abilities/skip/index.js +51 -0
- package/lib/abilities/skip/worker.js +19 -0
- package/lib/events/driver/command.js +8 -9
- package/lib/events/driver/winDriver.js +121 -188
- package/lib/helper/deviceHelper.js +19 -37
- package/lib/index.js +26 -13
- package/lib/resources/dll/{libinspectionkit_x64_0.1.0.dll → libinspectionkit_x64_0.4.1.dll} +0 -0
- package/lib/resources/mac/{libinspectionkit_arm64_0.1.0.dylib → libinspectionkit_amd64_0.4.1.dylib} +0 -0
- package/lib/resources/mac/libinspectionkit_arm64_0.4.1.dylib +0 -0
- package/lib/resources/version.online +1 -1
- package/lib/utils/utils.ability.js +9 -0
- package/lib/utils/utils.command.js +8 -9
- package/lib/utils/utils.common.js +26 -0
- package/lib/utils/{utils.js → utils.env.js} +19 -18
- package/lib/utils/utils.global.js +70 -89
- package/lib/utils/utils.initDll.js +16 -14
- package/lib/utils/utils.path.js +56 -7
- package/lib/utils/utils.process.js +35 -0
- package/lib/utils/utils.sn.js +31 -47
- package/lib/utils/utils.worker.js +32 -0
- package/package.json +7 -8
- package/lib/events/driver/service.js +0 -47
- package/lib/getAndroidSn/index.js +0 -228
- 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/registerEvent/index.js +0 -427
- package/lib/resources/mac/libinspectionkit_amd64_0.1.0.dylib +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hunter-open-sdk",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.21",
|
|
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,47 +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.default = void 0;
|
|
8
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
-
var _utils = require("../../utils/utils");
|
|
11
|
-
var _command = require("./command");
|
|
12
|
-
var _winDriver = require("./winDriver");
|
|
13
|
-
var path = require('path');
|
|
14
|
-
var Service = /*#__PURE__*/function () {
|
|
15
|
-
function Service() {
|
|
16
|
-
(0, _classCallCheck2.default)(this, Service);
|
|
17
|
-
}
|
|
18
|
-
(0, _createClass2.default)(Service, [{
|
|
19
|
-
key: "setup",
|
|
20
|
-
value:
|
|
21
|
-
// constructor () {}
|
|
22
|
-
function setup(mainWindow) {
|
|
23
|
-
console.log('Service setup');
|
|
24
|
-
if ((0, _utils.isMac)()) {
|
|
25
|
-
if ((0, _utils.isDev)()) {
|
|
26
|
-
(0, _command.command)(path.join(process.cwd(), './extraResources/ightools'));
|
|
27
|
-
}
|
|
28
|
-
if ((0, _utils.isProd)()) {
|
|
29
|
-
(0, _command.command)('nohup ' + path.join(process.resourcesPath, './extraResources/ightools') + ' > /dev/null 2>&1 & > ' + path.join(process.resourcesPath, './log/ightools.log'));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if ((0, _utils.isWin)()) {
|
|
33
|
-
(0, _winDriver.checkHasDriver)().then(function (res) {
|
|
34
|
-
console.log('------------checkHasDriver', res);
|
|
35
|
-
if (res) {
|
|
36
|
-
mainWindow.webContents.send("checkDriver", true);
|
|
37
|
-
} else {
|
|
38
|
-
mainWindow.webContents.send("checkDriver", false);
|
|
39
|
-
(0, _winDriver.downloadDriver)(mainWindow);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}]);
|
|
45
|
-
return Service;
|
|
46
|
-
}();
|
|
47
|
-
var _default = exports.default = Service;
|
|
@@ -1,228 +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.UnregisterAndroidSn = exports.GetAndroidSn = void 0;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
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
|
|
17
|
-
|
|
18
|
-
// mac获取sn
|
|
19
|
-
var getMacSn = /*#__PURE__*/function () {
|
|
20
|
-
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(device, callBack) {
|
|
21
|
-
var _deviceInfo$productNa, _deviceInfo$manufactu;
|
|
22
|
-
var attachDeviceId, customWebUSB, deviceList, currentDevice, deviceInfo, productName, manufacturerName, supportedBrands, isSupportedBrand;
|
|
23
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
24
|
-
while (1) switch (_context.prev = _context.next) {
|
|
25
|
-
case 0:
|
|
26
|
-
// 拿到当前连接的设备deviceAddress 作为标识去usb列表筛选
|
|
27
|
-
attachDeviceId = device.deviceAddress;
|
|
28
|
-
customWebUSB = new _usb.WebUSB({
|
|
29
|
-
allowAllDevices: true
|
|
30
|
-
});
|
|
31
|
-
_context.next = 4;
|
|
32
|
-
return customWebUSB.getDevices();
|
|
33
|
-
case 4:
|
|
34
|
-
deviceList = _context.sent;
|
|
35
|
-
if (attachDeviceId) {
|
|
36
|
-
_context.next = 7;
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
return _context.abrupt("return");
|
|
40
|
-
case 7:
|
|
41
|
-
// 删选出当前的设备信息 为获取到serialNumber
|
|
42
|
-
currentDevice = deviceList.filter(function (item) {
|
|
43
|
-
return item.device.deviceAddress == attachDeviceId;
|
|
44
|
-
});
|
|
45
|
-
if (currentDevice.length) {
|
|
46
|
-
_context.next = 11;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
callBack({
|
|
50
|
-
code: -1,
|
|
51
|
-
data: {},
|
|
52
|
-
message: '获取SN失败'
|
|
53
|
-
});
|
|
54
|
-
return _context.abrupt("return");
|
|
55
|
-
case 11:
|
|
56
|
-
// 检查设备是否为支持的三星、华为、荣耀手机品牌
|
|
57
|
-
deviceInfo = currentDevice[0];
|
|
58
|
-
productName = ((_deviceInfo$productNa = deviceInfo.productName) === null || _deviceInfo$productNa === void 0 ? void 0 : _deviceInfo$productNa.toLowerCase()) || '';
|
|
59
|
-
manufacturerName = ((_deviceInfo$manufactu = deviceInfo.manufacturerName) === null || _deviceInfo$manufactu === void 0 ? void 0 : _deviceInfo$manufactu.toLowerCase()) || ''; // 支持的三星、华为、荣耀品牌关键词
|
|
60
|
-
supportedBrands = ['samsung', 'galaxy', 'huawei', 'honor', 'honor magic'];
|
|
61
|
-
isSupportedBrand = supportedBrands.some(function (brand) {
|
|
62
|
-
return productName.includes(brand) || manufacturerName.includes(brand);
|
|
63
|
-
});
|
|
64
|
-
if (isSupportedBrand) {
|
|
65
|
-
_context.next = 19;
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
callBack({
|
|
69
|
-
code: -1,
|
|
70
|
-
data: {},
|
|
71
|
-
message: '暂不支持该品牌手机查询SN'
|
|
72
|
-
});
|
|
73
|
-
return _context.abrupt("return");
|
|
74
|
-
case 19:
|
|
75
|
-
callBack({
|
|
76
|
-
code: 0,
|
|
77
|
-
data: {
|
|
78
|
-
SN: currentDevice[0].serialNumber
|
|
79
|
-
},
|
|
80
|
-
message: '获取SN成功'
|
|
81
|
-
});
|
|
82
|
-
case 20:
|
|
83
|
-
case "end":
|
|
84
|
-
return _context.stop();
|
|
85
|
-
}
|
|
86
|
-
}, _callee);
|
|
87
|
-
}));
|
|
88
|
-
return function getMacSn(_x, _x2) {
|
|
89
|
-
return _ref.apply(this, arguments);
|
|
90
|
-
};
|
|
91
|
-
}();
|
|
92
|
-
|
|
93
|
-
// win获取sn
|
|
94
|
-
var getWinSn = /*#__PURE__*/function () {
|
|
95
|
-
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(device, callBack) {
|
|
96
|
-
var cmdStr;
|
|
97
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
98
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
99
|
-
case 0:
|
|
100
|
-
// windows 需要运行命令获取sn
|
|
101
|
-
cmdStr = "wmic path Win32_PnPEntity where \"DeviceID like 'USB%'\" get Name, PNPDeviceID /value";
|
|
102
|
-
exec(cmdStr, function (err, stdout, stderr) {
|
|
103
|
-
if (err) {
|
|
104
|
-
// 运行失败 则直接返回获取失败
|
|
105
|
-
callBack({
|
|
106
|
-
code: -1,
|
|
107
|
-
data: {},
|
|
108
|
-
message: "windows\u8FD0\u884C\u7A0B\u5E8F\u83B7\u53D6SN\u5931\u8D25err: ".concat(err)
|
|
109
|
-
});
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
if (stderr) {
|
|
113
|
-
// 运行失败 则直接返回获取失败
|
|
114
|
-
callBack({
|
|
115
|
-
code: -1,
|
|
116
|
-
data: {},
|
|
117
|
-
message: "windows\u8FD0\u884C\u7A0B\u5E8F\u83B7\u53D6SN\u5931\u8D25stderr: ".concat(stderr)
|
|
118
|
-
});
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// 处理WMIC输出并提取手机序列号
|
|
123
|
-
var phoneDevices = (0, _utils2.parseWmicOutput)(stdout);
|
|
124
|
-
if (phoneDevices.length === 0) {
|
|
125
|
-
callBack({
|
|
126
|
-
code: -1,
|
|
127
|
-
data: {},
|
|
128
|
-
message: "\u6682\u4E0D\u652F\u6301\u8BE5\u54C1\u724C\u624B\u673A\u67E5\u8BE2SN"
|
|
129
|
-
});
|
|
130
|
-
} else {
|
|
131
|
-
console.log('检测到的手机设备:');
|
|
132
|
-
var sn = phoneDevices[0].serial;
|
|
133
|
-
callBack({
|
|
134
|
-
code: 0,
|
|
135
|
-
data: {
|
|
136
|
-
SN: sn
|
|
137
|
-
},
|
|
138
|
-
message: "\u83B7\u53D6SN\u6210\u529F"
|
|
139
|
-
});
|
|
140
|
-
// phoneDevices.forEach(device => {
|
|
141
|
-
// console.log(`设备名称: ${device.name}`);
|
|
142
|
-
// console.log(`序列号: ${device.serial}`);
|
|
143
|
-
// console.log(`PNPDeviceID: ${device.pnpDeviceId}`);
|
|
144
|
-
// console.log('---');
|
|
145
|
-
// });
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
case 2:
|
|
149
|
-
case "end":
|
|
150
|
-
return _context2.stop();
|
|
151
|
-
}
|
|
152
|
-
}, _callee2);
|
|
153
|
-
}));
|
|
154
|
-
return function getWinSn(_x3, _x4) {
|
|
155
|
-
return _ref2.apply(this, arguments);
|
|
156
|
-
};
|
|
157
|
-
}();
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* 获取Android SN
|
|
161
|
-
* @param {Object} params - 参数
|
|
162
|
-
* @param {Function} callBack - 回调函数
|
|
163
|
-
*/
|
|
164
|
-
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 () {
|
|
171
|
-
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(device) {
|
|
172
|
-
var idVendor;
|
|
173
|
-
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
174
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
175
|
-
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:
|
|
211
|
-
case "end":
|
|
212
|
-
return _context3.stop();
|
|
213
|
-
}
|
|
214
|
-
}, _callee3);
|
|
215
|
-
}));
|
|
216
|
-
return function (_x5) {
|
|
217
|
-
return _ref3.apply(this, arguments);
|
|
218
|
-
};
|
|
219
|
-
}());
|
|
220
|
-
_usb.usb.on('detach', function () {
|
|
221
|
-
if (isPause) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
};
|
|
226
|
-
var UnregisterAndroidSn = exports.UnregisterAndroidSn = function UnregisterAndroidSn() {
|
|
227
|
-
isPause = true;
|
|
228
|
-
};
|
|
@@ -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;
|
|
@@ -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.GetSaaSReport = 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 'getSaaSReportSuccess':
|
|
47
|
-
callBack(data);
|
|
48
|
-
break;
|
|
49
|
-
case 'getSaaSReportFail':
|
|
50
|
-
callBack(data);
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// 发起获取报告消息
|
|
57
|
-
function getReport(params) {
|
|
58
|
-
worker && worker.postMessage({
|
|
59
|
-
type: 'getSaaSReport',
|
|
60
|
-
params: params
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 获取报告
|
|
65
|
-
var GetSaaSReport = exports.GetSaaSReport = function GetSaaSReport(params, callBack) {
|
|
66
|
-
// 如果是在主进程,则直接获取报告
|
|
67
|
-
if (isInMainProcess()) {
|
|
68
|
-
var reportRes = (0, _utils.getSaaSReportCallKit)(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 'getSaaSReport':
|
|
13
|
-
var reportRes = (0, _utils.getSaaSReportCallKit)(params);
|
|
14
|
-
self.postMessage(reportRes);
|
|
15
|
-
break;
|
|
16
|
-
default:
|
|
17
|
-
break;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
self.onmessage = onMainMessage;
|