hunter-open-sdk 2.0.0-beta.2 → 2.0.0-beta.20
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 +48 -0
- package/lib/abilities/activate/worker.js +19 -0
- package/lib/abilities/erase/index.js +48 -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 +64 -0
- package/lib/abilities/getGeneralReport/worker.js +38 -0
- package/lib/abilities/getSaaSReport/index.js +48 -0
- package/lib/abilities/getSaaSReport/worker.js +21 -0
- package/lib/abilities/installApp/index.js +48 -0
- package/lib/abilities/installApp/worker.js +19 -0
- package/lib/abilities/reboot/index.js +48 -0
- package/lib/abilities/reboot/worker.js +19 -0
- package/lib/abilities/shutdown/index.js +48 -0
- package/lib/abilities/shutdown/worker.js +19 -0
- package/lib/abilities/skip/index.js +48 -0
- package/lib/abilities/skip/worker.js +19 -0
- package/lib/events/driver/command.js +8 -9
- package/lib/events/driver/service.js +24 -35
- package/lib/events/driver/winDriver.js +121 -188
- package/lib/helper/deviceHelper.js +19 -37
- package/lib/index.js +24 -12
- 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 +21 -6
- 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/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
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.activate = activate;
|
|
7
|
+
var _webWorker = _interopRequireDefault(require("web-worker"));
|
|
8
|
+
var _url = _interopRequireDefault(require("url"));
|
|
9
|
+
var _utils = require("../../utils/utils.common");
|
|
10
|
+
var _utils2 = require("../../utils/utils.path");
|
|
11
|
+
var _utils3 = require("../../utils/utils.ability");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
class Activate {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.initWorker();
|
|
16
|
+
this.initWorkerListener();
|
|
17
|
+
}
|
|
18
|
+
worker = null;
|
|
19
|
+
callback = null;
|
|
20
|
+
exec(payload, callback) {
|
|
21
|
+
this.callback = typeof callback === 'function' ? callback : _utils3.defaultCallback;
|
|
22
|
+
this.worker && this.worker.postMessage({
|
|
23
|
+
payload
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
initWorkerListener() {
|
|
27
|
+
this.worker && this.worker.addEventListener('message', event => {
|
|
28
|
+
const {
|
|
29
|
+
payload
|
|
30
|
+
} = event.data;
|
|
31
|
+
this.callback(payload);
|
|
32
|
+
this.callback = null;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
initWorker() {
|
|
36
|
+
if (!this.worker) {
|
|
37
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.getCurrentEnvPath)(__dirname, './worker.js'));
|
|
38
|
+
this.worker = new _webWorker.default(workerPath, {
|
|
39
|
+
type: 'module'
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const entity = new Activate();
|
|
45
|
+
function activate(params, callback) {
|
|
46
|
+
const payload = (0, _utils.parsePayload)(params);
|
|
47
|
+
entity.exec(payload, callback);
|
|
48
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
initWorkerNodePath
|
|
5
|
+
} = require("../../utils/utils.worker");
|
|
6
|
+
|
|
7
|
+
// 先注册NodePath后才能正常使用node包,请勿挪动位置
|
|
8
|
+
initWorkerNodePath();
|
|
9
|
+
const {
|
|
10
|
+
abilityCallKit
|
|
11
|
+
} = require("../../utils/utils.global");
|
|
12
|
+
function onMainMessage(event) {
|
|
13
|
+
const {
|
|
14
|
+
payload
|
|
15
|
+
} = event.data;
|
|
16
|
+
const res = abilityCallKit('activate', payload);
|
|
17
|
+
postMessage(res);
|
|
18
|
+
}
|
|
19
|
+
addEventListener('message', onMainMessage);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.erase = erase;
|
|
7
|
+
var _webWorker = _interopRequireDefault(require("web-worker"));
|
|
8
|
+
var _url = _interopRequireDefault(require("url"));
|
|
9
|
+
var _utils = require("../../utils/utils.common");
|
|
10
|
+
var _utils2 = require("../../utils/utils.path");
|
|
11
|
+
var _utils3 = require("../../utils/utils.ability");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
class Erase {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.initWorker();
|
|
16
|
+
this.initWorkerListener();
|
|
17
|
+
}
|
|
18
|
+
worker = null;
|
|
19
|
+
callback = null;
|
|
20
|
+
exec(payload, callback) {
|
|
21
|
+
this.callback = typeof callback === 'function' ? callback : _utils3.defaultCallback;
|
|
22
|
+
this.worker && this.worker.postMessage({
|
|
23
|
+
payload
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
initWorkerListener() {
|
|
27
|
+
this.worker && this.worker.addEventListener('message', event => {
|
|
28
|
+
const {
|
|
29
|
+
payload
|
|
30
|
+
} = event.data;
|
|
31
|
+
this.callback(payload);
|
|
32
|
+
this.callback = null;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
initWorker() {
|
|
36
|
+
if (!this.worker) {
|
|
37
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.getCurrentEnvPath)(__dirname, './worker.js'));
|
|
38
|
+
this.worker = new _webWorker.default(workerPath, {
|
|
39
|
+
type: 'module'
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const entity = new Erase();
|
|
45
|
+
function erase(params, callback) {
|
|
46
|
+
const payload = (0, _utils.parsePayload)(params);
|
|
47
|
+
entity.exec(payload, callback);
|
|
48
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
initWorkerNodePath
|
|
5
|
+
} = require("../../utils/utils.worker");
|
|
6
|
+
|
|
7
|
+
// 先注册NodePath后才能正常使用node包,请勿挪动位置
|
|
8
|
+
initWorkerNodePath();
|
|
9
|
+
const {
|
|
10
|
+
abilityCallKit
|
|
11
|
+
} = require("../../utils/utils.global");
|
|
12
|
+
function onMainMessage(event) {
|
|
13
|
+
const {
|
|
14
|
+
payload
|
|
15
|
+
} = event.data;
|
|
16
|
+
const res = abilityCallKit('erase', payload);
|
|
17
|
+
postMessage(res);
|
|
18
|
+
}
|
|
19
|
+
addEventListener('message', onMainMessage);
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.unregisterEvent = exports.registerEvent = void 0;
|
|
7
|
+
var _usbmux = _interopRequireDefault(require("usbmux"));
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _request = _interopRequireDefault(require("request"));
|
|
10
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
+
var Sentry = _interopRequireWildcard(require("@sentry/browser"));
|
|
12
|
+
var _utils = require("../../utils/utils.env");
|
|
13
|
+
var _utils2 = require("../../utils/utils.common");
|
|
14
|
+
var _winDriver = require("../../events/driver/winDriver");
|
|
15
|
+
var _utils3 = require("../../utils/utils.global");
|
|
16
|
+
var _deviceHelper = require("../../helper/deviceHelper");
|
|
17
|
+
var _utils4 = require("../../utils/utils.initDll");
|
|
18
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
19
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
// saas回调
|
|
22
|
+
let saasCallBack;
|
|
23
|
+
|
|
24
|
+
// usb监听
|
|
25
|
+
let usbListener = null;
|
|
26
|
+
/**
|
|
27
|
+
* 获取资源文件的基础路径
|
|
28
|
+
*/
|
|
29
|
+
const getResourcePath = () => {
|
|
30
|
+
if ((0, _utils.isDev)()) {
|
|
31
|
+
// 开发环境:使用源码目录
|
|
32
|
+
return _path.default.resolve(__dirname, '../resources');
|
|
33
|
+
} else {
|
|
34
|
+
// 生产环境:使用 Electron 的资源路径
|
|
35
|
+
return _path.default.resolve(process.resourcesPath, 'resources');
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 发布配对
|
|
41
|
+
* @param {String} udid 设备id
|
|
42
|
+
* @param {String} params 参数
|
|
43
|
+
* @returns {String} 发布配对结果
|
|
44
|
+
*/
|
|
45
|
+
const publishPair = (udid = '', params) => {
|
|
46
|
+
// 通过调用 trust_status 来判断信任状态
|
|
47
|
+
const kitParamsObj = JSON.parse(params);
|
|
48
|
+
|
|
49
|
+
// 合并参数
|
|
50
|
+
Object.assign(kitParamsObj, {
|
|
51
|
+
cmd: 'publish_pair',
|
|
52
|
+
udid
|
|
53
|
+
});
|
|
54
|
+
return (0, _utils3.callHunterInspectionKit)('TheForceKit', JSON.stringify(kitParamsObj));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 获取信任状态
|
|
59
|
+
* @param {String} udid 设备id
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
const getTrustStatus = async (udid = '', params, once = false) => {
|
|
63
|
+
if (!_deviceHelper.deviceHelper.hasUdid(udid)) {
|
|
64
|
+
// 防止一直循环占用cpu资源
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 合并参数
|
|
69
|
+
const paramsObj = Object.assign(JSON.parse(params), {
|
|
70
|
+
udid
|
|
71
|
+
});
|
|
72
|
+
let label = 'Windows';
|
|
73
|
+
if ((0, _utils.isMac)()) {
|
|
74
|
+
label = 'Mac';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 通过调用 trust_status 来判断信任状态
|
|
78
|
+
const kitParamsObj = {
|
|
79
|
+
cmd: 'trust_status',
|
|
80
|
+
label,
|
|
81
|
+
params: JSON.stringify(paramsObj)
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// 获取信任状态
|
|
85
|
+
const trustStatusRes = (0, _utils3.callHunterInspectionKit)('TheForceKit', JSON.stringify(kitParamsObj));
|
|
86
|
+
if (trustStatusRes) {
|
|
87
|
+
const trustStatusResObj = JSON.parse(trustStatusRes);
|
|
88
|
+
const {
|
|
89
|
+
Code,
|
|
90
|
+
Data
|
|
91
|
+
} = trustStatusResObj;
|
|
92
|
+
if (Code == 0 && (Data.imei || Data.serialNumber)) {
|
|
93
|
+
return Data;
|
|
94
|
+
} else if (!once) {
|
|
95
|
+
await (0, _utils2.sleep)();
|
|
96
|
+
return await getTrustStatus(udid, params);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
};
|
|
101
|
+
const getTrustStatusOnce = async (udid, params) => {
|
|
102
|
+
return await getTrustStatus(udid, params, true);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 配对并获取信任状态
|
|
107
|
+
* @param {String} udid 设备id
|
|
108
|
+
* @returns
|
|
109
|
+
*/
|
|
110
|
+
const DevicePair = async (udid = '', params) => {
|
|
111
|
+
const callBack = () => {
|
|
112
|
+
saasCallBack({
|
|
113
|
+
data: {
|
|
114
|
+
eventName: 'type_trust_result',
|
|
115
|
+
udid,
|
|
116
|
+
eventCode: 0
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// 单次获取信任状态
|
|
122
|
+
const trustStatusOnceRes = await getTrustStatusOnce(udid, params);
|
|
123
|
+
|
|
124
|
+
// 未信任弹起信任窗口
|
|
125
|
+
if (!trustStatusOnceRes) {
|
|
126
|
+
// 发布配对
|
|
127
|
+
publishPair(udid, params);
|
|
128
|
+
|
|
129
|
+
// 通过 trust_status 来判断信任状态
|
|
130
|
+
const trustStatusRes = await getTrustStatus(udid, params);
|
|
131
|
+
if (trustStatusRes) {
|
|
132
|
+
callBack();
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 已信任 直接返回
|
|
138
|
+
callBack();
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// 写入dll文件version
|
|
142
|
+
const writeDllVersion = version => {
|
|
143
|
+
const resourcePath = getResourcePath();
|
|
144
|
+
const versionPath = _path.default.resolve(resourcePath, 'version.online');
|
|
145
|
+
_fs.default.writeFile(versionPath, version, err => {
|
|
146
|
+
if (err) {
|
|
147
|
+
saasCallBack({
|
|
148
|
+
data: {
|
|
149
|
+
eventName: 'type_update_result',
|
|
150
|
+
eventCode: -1 // eventCode 0 更新成功 -1 更新失败
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
console.log('========写入version成功');
|
|
156
|
+
// 写入成功后 重新初始化dll
|
|
157
|
+
(0, _utils4.initHunterInspectionKit)();
|
|
158
|
+
saasCallBack({
|
|
159
|
+
data: {
|
|
160
|
+
eventName: 'type_update_result',
|
|
161
|
+
eventCode: 0 // eventCode 0 更新成功 -1 更新失败
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// 下载更新dll
|
|
168
|
+
const updateDll = (packageUrl, targetVersion) => {
|
|
169
|
+
// 若需要更新 则下载完成后 覆盖本地dll文件
|
|
170
|
+
let dllOutPath;
|
|
171
|
+
const resourcePath = getResourcePath();
|
|
172
|
+
if ((0, _utils.isMac)()) {
|
|
173
|
+
if ((0, _utils.isArm64)()) {
|
|
174
|
+
dllOutPath = _path.default.resolve(resourcePath, `mac/libinspectionkit_arm64_${targetVersion}.dylib`);
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
dllOutPath = _path.default.resolve(resourcePath, `dll/libinspectionkit_x64_${targetVersion}.dll`);
|
|
178
|
+
}
|
|
179
|
+
const dllStream = _fs.default.createWriteStream(dllOutPath);
|
|
180
|
+
(0, _request.default)(packageUrl).pipe(dllStream).on('close', function (err) {
|
|
181
|
+
if (err) {
|
|
182
|
+
saasCallBack({
|
|
183
|
+
data: {
|
|
184
|
+
eventName: 'type_update_result',
|
|
185
|
+
eventCode: -1 // eventCode 0 更新成功 -1 更新失败
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
} else {
|
|
189
|
+
// 写version文件内容
|
|
190
|
+
writeDllVersion(targetVersion);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 更新下载dll文件 并重写本地版本号
|
|
197
|
+
* @param {String} udid 设备id
|
|
198
|
+
* @returns
|
|
199
|
+
*/
|
|
200
|
+
const updateDllFileCheck = () => {
|
|
201
|
+
// mac的amd不支持更新
|
|
202
|
+
if ((0, _utils.isMac)() && (0, _utils.isAmd64)()) return;
|
|
203
|
+
const updateParams = {
|
|
204
|
+
cmd: 'hot_update',
|
|
205
|
+
label: (0, _utils.isWin)() ? 'Windows' : 'Mac',
|
|
206
|
+
params: {}
|
|
207
|
+
};
|
|
208
|
+
const updateRes = (0, _utils3.callHunterInspectionKit)('TheForceKit', JSON.stringify(updateParams));
|
|
209
|
+
if (updateRes) {
|
|
210
|
+
const updateResObj = JSON.parse(updateRes);
|
|
211
|
+
const {
|
|
212
|
+
Code,
|
|
213
|
+
Data
|
|
214
|
+
} = updateResObj;
|
|
215
|
+
if (Code == 0) {
|
|
216
|
+
const {
|
|
217
|
+
isHot,
|
|
218
|
+
url,
|
|
219
|
+
targetVersion
|
|
220
|
+
} = Data;
|
|
221
|
+
|
|
222
|
+
// 需要更新 则直接下载
|
|
223
|
+
isHot == 1 && updateDll(url, targetVersion);
|
|
224
|
+
saasCallBack({
|
|
225
|
+
data: {
|
|
226
|
+
eventName: 'type_need_update',
|
|
227
|
+
eventCode: isHot == 1 ? 0 : -1 // eventCode 0 需要更新 -1 不需要更新
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
} else {
|
|
231
|
+
// 错误的时候不需要更新
|
|
232
|
+
saasCallBack({
|
|
233
|
+
data: {
|
|
234
|
+
eventName: 'type_need_update',
|
|
235
|
+
eventCode: -1 // eventCode 0 需要更新 -1 不需要更新
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* 检查并安装驱动
|
|
244
|
+
*/
|
|
245
|
+
const checkAndInstallDriver = () => {
|
|
246
|
+
return new Promise((resolve, reject) => {
|
|
247
|
+
if (!(0, _utils.isWin)()) {
|
|
248
|
+
resolve();
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
(0, _winDriver.checkHasDriver)().then(res => {
|
|
252
|
+
if (res) {
|
|
253
|
+
resolve();
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
(0, _winDriver.downloadDriver)(percent => {
|
|
257
|
+
saasCallBack({
|
|
258
|
+
data: {
|
|
259
|
+
eventName: 'type_need_install_driver',
|
|
260
|
+
eventCode: 0,
|
|
261
|
+
eventContent: JSON.stringify({
|
|
262
|
+
percent // 下载进度
|
|
263
|
+
})
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}).then(() => {
|
|
267
|
+
// 成功
|
|
268
|
+
console.log('驱动下载并安装成功');
|
|
269
|
+
saasCallBack({
|
|
270
|
+
data: {
|
|
271
|
+
eventName: 'type_install_driver_result',
|
|
272
|
+
eventCode: 0 // 0 成功 -1 失败
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
resolve();
|
|
276
|
+
}).catch(err => {
|
|
277
|
+
// 失败
|
|
278
|
+
console.error('驱动下载或安装失败', err);
|
|
279
|
+
Sentry.captureException('驱动下载或安装失败:' + JSON.stringify(err));
|
|
280
|
+
saasCallBack({
|
|
281
|
+
data: {
|
|
282
|
+
eventName: 'type_install_driver_result',
|
|
283
|
+
eventCode: -1 // 0 成功 -1 失败
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
reject();
|
|
287
|
+
});
|
|
288
|
+
}).catch(err => {
|
|
289
|
+
console.error('驱动检测失败', err);
|
|
290
|
+
Sentry.captureException('驱动检测失败:' + JSON.stringify(err));
|
|
291
|
+
reject();
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
const registerEvent = async (params, callBack) => {
|
|
296
|
+
saasCallBack = callBack;
|
|
297
|
+
|
|
298
|
+
// 检查是否需要更新dll
|
|
299
|
+
updateDllFileCheck();
|
|
300
|
+
|
|
301
|
+
// 在插线之前就检测驱动状态
|
|
302
|
+
await checkAndInstallDriver();
|
|
303
|
+
usbListener = new _usbmux.default.createListener().on('attached', async udid => {
|
|
304
|
+
if (!udid) return;
|
|
305
|
+
// 插入设备通知
|
|
306
|
+
saasCallBack({
|
|
307
|
+
data: {
|
|
308
|
+
eventName: 'type_usb_device_result',
|
|
309
|
+
udid,
|
|
310
|
+
eventCode: 0
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
_deviceHelper.deviceHelper.addUdid(udid);
|
|
314
|
+
// 有驱动,直接运行脚本
|
|
315
|
+
DevicePair(udid, params);
|
|
316
|
+
}).on('detached', function (udid) {
|
|
317
|
+
// 拔出设备
|
|
318
|
+
saasCallBack({
|
|
319
|
+
data: {
|
|
320
|
+
eventName: 'type_usb_device_result',
|
|
321
|
+
udid,
|
|
322
|
+
eventCode: -1
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
_deviceHelper.deviceHelper.removeUdid(udid);
|
|
326
|
+
}).on('error', function (err) {
|
|
327
|
+
console.log('usb连接错误:', err);
|
|
328
|
+
Sentry.captureException('usb连接错误:' + JSON.stringify(err));
|
|
329
|
+
const errMsg = `usb连接错误:${err}`;
|
|
330
|
+
throw new Error(errMsg);
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
exports.registerEvent = registerEvent;
|
|
334
|
+
const unregisterEvent = () => {
|
|
335
|
+
usbListener && usbListener.destroy();
|
|
336
|
+
_deviceHelper.deviceHelper.clearUdidList();
|
|
337
|
+
};
|
|
338
|
+
exports.unregisterEvent = unregisterEvent;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.unregisterGetAndroidSn = exports.registerGetAndroidSn = void 0;
|
|
7
|
+
var _usb = require("usb");
|
|
8
|
+
var _child_process = _interopRequireDefault(require("child_process"));
|
|
9
|
+
var _utils = require("../../utils/utils.env");
|
|
10
|
+
var _utils2 = require("../../utils/utils.sn");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
const exec = _child_process.default.exec;
|
|
13
|
+
let hadRegisterUsb = false; // 是否已经注册过usb事件
|
|
14
|
+
let isPause = false; // 是否暂停获取sn
|
|
15
|
+
|
|
16
|
+
// mac获取sn
|
|
17
|
+
const getMacSn = async (device, callBack) => {
|
|
18
|
+
// 拿到当前连接的设备deviceAddress 作为标识去usb列表筛选
|
|
19
|
+
const attachDeviceId = device.deviceAddress;
|
|
20
|
+
const customWebUSB = new _usb.WebUSB({
|
|
21
|
+
allowAllDevices: true
|
|
22
|
+
});
|
|
23
|
+
const deviceList = await customWebUSB.getDevices();
|
|
24
|
+
|
|
25
|
+
// 如果设备没有attachDeviceId 则直接返回
|
|
26
|
+
if (!attachDeviceId) return;
|
|
27
|
+
|
|
28
|
+
// 删选出当前的设备信息 为获取到serialNumber
|
|
29
|
+
const currentDevice = deviceList.filter(item => item.device.deviceAddress == attachDeviceId);
|
|
30
|
+
if (!currentDevice.length) {
|
|
31
|
+
callBack({
|
|
32
|
+
code: -1,
|
|
33
|
+
data: {},
|
|
34
|
+
message: '获取SN失败'
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 检查设备是否为支持的三星、华为、荣耀手机品牌
|
|
40
|
+
const deviceInfo = currentDevice[0];
|
|
41
|
+
const productName = deviceInfo.productName?.toLowerCase() || '';
|
|
42
|
+
const manufacturerName = deviceInfo.manufacturerName?.toLowerCase() || '';
|
|
43
|
+
|
|
44
|
+
// 支持的三星、华为、荣耀品牌关键词
|
|
45
|
+
const supportedBrands = ['samsung', 'galaxy', 'huawei', 'honor', 'honor magic'];
|
|
46
|
+
const isSupportedBrand = supportedBrands.some(brand => productName.includes(brand) || manufacturerName.includes(brand));
|
|
47
|
+
if (!isSupportedBrand) {
|
|
48
|
+
callBack({
|
|
49
|
+
code: -1,
|
|
50
|
+
data: {},
|
|
51
|
+
message: '暂不支持该品牌手机查询SN'
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
callBack({
|
|
56
|
+
code: 0,
|
|
57
|
+
data: {
|
|
58
|
+
SN: currentDevice[0].serialNumber
|
|
59
|
+
},
|
|
60
|
+
message: '获取SN成功'
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// win获取sn
|
|
65
|
+
const getWinSn = async (device, callBack) => {
|
|
66
|
+
// windows 需要运行命令获取sn
|
|
67
|
+
const cmdStr = `wmic path Win32_PnPEntity where "DeviceID like \'USB%\'" get Name, PNPDeviceID /value`;
|
|
68
|
+
exec(cmdStr, function (err, stdout, stderr) {
|
|
69
|
+
if (err) {
|
|
70
|
+
// 运行失败 则直接返回获取失败
|
|
71
|
+
callBack({
|
|
72
|
+
code: -1,
|
|
73
|
+
data: {},
|
|
74
|
+
message: `windows运行程序获取SN失败err: ${err}`
|
|
75
|
+
});
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (stderr) {
|
|
79
|
+
// 运行失败 则直接返回获取失败
|
|
80
|
+
callBack({
|
|
81
|
+
code: -1,
|
|
82
|
+
data: {},
|
|
83
|
+
message: `windows运行程序获取SN失败stderr: ${stderr}`
|
|
84
|
+
});
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 处理WMIC输出并提取手机序列号
|
|
89
|
+
const phoneDevices = (0, _utils2.parseWmicOutput)(stdout);
|
|
90
|
+
if (phoneDevices.length === 0) {
|
|
91
|
+
callBack({
|
|
92
|
+
code: -1,
|
|
93
|
+
data: {},
|
|
94
|
+
message: `暂不支持该品牌手机查询SN`
|
|
95
|
+
});
|
|
96
|
+
} else {
|
|
97
|
+
console.log('检测到的手机设备:');
|
|
98
|
+
const sn = phoneDevices[0].serial;
|
|
99
|
+
callBack({
|
|
100
|
+
code: 0,
|
|
101
|
+
data: {
|
|
102
|
+
SN: sn
|
|
103
|
+
},
|
|
104
|
+
message: `获取SN成功`
|
|
105
|
+
});
|
|
106
|
+
// phoneDevices.forEach(device => {
|
|
107
|
+
// console.log(`设备名称: ${device.name}`);
|
|
108
|
+
// console.log(`序列号: ${device.serial}`);
|
|
109
|
+
// console.log(`PNPDeviceID: ${device.pnpDeviceId}`);
|
|
110
|
+
// console.log('---');
|
|
111
|
+
// });
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 获取Android SN
|
|
118
|
+
* @param {Object} params - 参数
|
|
119
|
+
* @param {Function} callBack - 回调函数
|
|
120
|
+
*/
|
|
121
|
+
const registerGetAndroidSn = (params, callBack) => {
|
|
122
|
+
if (hadRegisterUsb) {
|
|
123
|
+
isPause = false;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
hadRegisterUsb = true;
|
|
127
|
+
_usb.usb.on('attach', async device => {
|
|
128
|
+
if (isPause) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const {
|
|
132
|
+
idVendor
|
|
133
|
+
} = device.deviceDescriptor;
|
|
134
|
+
if (idVendor == 1452) {
|
|
135
|
+
// 表示该机器为苹果产品,则不进行获取sn
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
callBack({
|
|
139
|
+
data: {
|
|
140
|
+
eventName: 'type_usb_android_device_result',
|
|
141
|
+
eventCode: 0
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
if ((0, _utils.isMac)()) {
|
|
145
|
+
// mac获取sn
|
|
146
|
+
getMacSn(device, callBack);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if ((0, _utils.isWin)()) {
|
|
150
|
+
// win获取sn
|
|
151
|
+
getWinSn(device, callBack);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
_usb.usb.on('detach', () => {
|
|
156
|
+
if (isPause) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
exports.registerGetAndroidSn = registerGetAndroidSn;
|
|
162
|
+
const unregisterGetAndroidSn = () => {
|
|
163
|
+
isPause = true;
|
|
164
|
+
};
|
|
165
|
+
exports.unregisterGetAndroidSn = unregisterGetAndroidSn;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getGeneralReport = getGeneralReport;
|
|
7
|
+
var _webWorker = _interopRequireDefault(require("web-worker"));
|
|
8
|
+
var _url = _interopRequireDefault(require("url"));
|
|
9
|
+
var _utils = require("../../utils/utils.common");
|
|
10
|
+
var _utils2 = require("../../utils/utils.path");
|
|
11
|
+
var _utils3 = require("../../utils/utils.ability");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
const DEFAULT_POOL_SIZE = 8;
|
|
14
|
+
class WorkerPool {
|
|
15
|
+
constructor(size) {
|
|
16
|
+
this.poolSize = size;
|
|
17
|
+
this.idleWorkers = [];
|
|
18
|
+
this.taskQueue = [];
|
|
19
|
+
for (let i = 0; i < this.poolSize; i++) {
|
|
20
|
+
this.idleWorkers.push(this._createWorker());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
_createWorker() {
|
|
24
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.getCurrentEnvPath)(__dirname, './worker.js'));
|
|
25
|
+
return new _webWorker.default(workerPath, {
|
|
26
|
+
type: 'module'
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exec(payload, callback) {
|
|
30
|
+
if (this.idleWorkers.length > 0) {
|
|
31
|
+
this._run(this.idleWorkers.pop(), payload, callback);
|
|
32
|
+
} else {
|
|
33
|
+
this.taskQueue.push({
|
|
34
|
+
payload,
|
|
35
|
+
callback
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
_run(worker, payload, callback) {
|
|
40
|
+
const onMessage = event => {
|
|
41
|
+
worker.removeEventListener('message', onMessage);
|
|
42
|
+
callback(event.data.payload);
|
|
43
|
+
if (this.taskQueue.length > 0) {
|
|
44
|
+
const next = this.taskQueue.shift();
|
|
45
|
+
this._run(worker, next.payload, next.callback);
|
|
46
|
+
} else {
|
|
47
|
+
this.idleWorkers.push(worker);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
worker.addEventListener('message', onMessage);
|
|
51
|
+
worker.postMessage({
|
|
52
|
+
payload
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
let pool = new WorkerPool(DEFAULT_POOL_SIZE);
|
|
57
|
+
function getGeneralReport(params, callback, options = {}) {
|
|
58
|
+
const cb = typeof callback === 'function' ? callback : _utils3.defaultCallback;
|
|
59
|
+
const payload = (0, _utils.parsePayload)(params);
|
|
60
|
+
if (options?.poolSize != null && options.poolSize !== pool.poolSize) {
|
|
61
|
+
pool = new WorkerPool(options.poolSize);
|
|
62
|
+
}
|
|
63
|
+
pool.exec(payload, cb);
|
|
64
|
+
}
|