hunter-open-sdk 2.0.0-beta.3 → 2.0.0-beta.30
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 +347 -0
- package/lib/abilities/getAndroidReport/index.js +60 -0
- package/lib/abilities/getAndroidReport/worker.js +21 -0
- package/lib/abilities/getAndroidSn/index.js +187 -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/getUltimateReport/index.js +59 -0
- package/lib/abilities/getUltimateReport/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/constants/index.js +28 -0
- package/lib/events/driver/command.js +8 -9
- package/lib/events/driver/winDriver.js +123 -189
- package/lib/helper/deviceHelper.js +19 -37
- package/lib/index.d.ts +70 -0
- package/lib/index.js +115 -13
- package/lib/index.mjs +2 -0
- package/lib/resources/dll/{libinspectionkit_x64_0.1.0.dll → libinspectionkit_x64_0.6.1.dll} +0 -0
- package/lib/resources/{mac/libinspectionkit_arm64_0.1.0.dylib → dylib/libinspectionkit_amd64_0.6.1.dylib} +0 -0
- package/lib/resources/dylib/libinspectionkit_arm64_0.6.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 +41 -56
- package/lib/utils/utils.worker.js +32 -0
- package/package.json +15 -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
|
@@ -0,0 +1,51 @@
|
|
|
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.convertPathWithCurrentEnv)(__dirname, './worker.js'));
|
|
38
|
+
this.worker = new _webWorker.default(workerPath, {
|
|
39
|
+
type: 'module'
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let entity = null;
|
|
45
|
+
function activate(params, callback) {
|
|
46
|
+
if (!entity) {
|
|
47
|
+
entity = new Activate();
|
|
48
|
+
}
|
|
49
|
+
const payload = (0, _utils.parsePayload)(params);
|
|
50
|
+
entity.exec(payload, callback);
|
|
51
|
+
}
|
|
@@ -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,51 @@
|
|
|
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.convertPathWithCurrentEnv)(__dirname, './worker.js'));
|
|
38
|
+
this.worker = new _webWorker.default(workerPath, {
|
|
39
|
+
type: 'module'
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let entity = null;
|
|
45
|
+
function erase(params, callback) {
|
|
46
|
+
if (!entity) {
|
|
47
|
+
entity = new Erase();
|
|
48
|
+
}
|
|
49
|
+
const payload = (0, _utils.parsePayload)(params);
|
|
50
|
+
entity.exec(payload, callback);
|
|
51
|
+
}
|
|
@@ -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,347 @@
|
|
|
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 _constants = require("../../constants");
|
|
14
|
+
var _utils2 = require("../../utils/utils.common");
|
|
15
|
+
var _winDriver = require("../../events/driver/winDriver");
|
|
16
|
+
var _utils3 = require("../../utils/utils.global");
|
|
17
|
+
var _deviceHelper = require("../../helper/deviceHelper");
|
|
18
|
+
var _utils4 = require("../../utils/utils.initDll");
|
|
19
|
+
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); }
|
|
20
|
+
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; }
|
|
21
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
+
// saas回调
|
|
23
|
+
let saasCallBack;
|
|
24
|
+
|
|
25
|
+
// usb监听
|
|
26
|
+
let usbListener = null;
|
|
27
|
+
/**
|
|
28
|
+
* 获取资源文件的基础路径
|
|
29
|
+
*/
|
|
30
|
+
const getResourcePath = () => {
|
|
31
|
+
if ((0, _utils.isDev)()) {
|
|
32
|
+
// 开发环境:使用源码目录
|
|
33
|
+
return _path.default.resolve(__dirname, '../resources');
|
|
34
|
+
} else {
|
|
35
|
+
// 生产环境:使用 Electron 的资源路径
|
|
36
|
+
return _path.default.resolve(process.resourcesPath, 'resources');
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 发布配对
|
|
42
|
+
* @param {String} udid 设备id
|
|
43
|
+
* @param {String} params 参数
|
|
44
|
+
* @returns {String} 发布配对结果
|
|
45
|
+
*/
|
|
46
|
+
const publishPair = (udid = '', params) => {
|
|
47
|
+
// 通过调用 trust_status 来判断信任状态
|
|
48
|
+
const kitParamsObj = JSON.parse(params);
|
|
49
|
+
|
|
50
|
+
// 合并参数
|
|
51
|
+
Object.assign(kitParamsObj, {
|
|
52
|
+
cmd: 'publish_pair',
|
|
53
|
+
udid
|
|
54
|
+
});
|
|
55
|
+
return (0, _utils3.callHunterInspectionKit)('TheForceKit', JSON.stringify(kitParamsObj));
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 获取信任状态
|
|
60
|
+
* @param {String} udid 设备id
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
const getTrustStatus = async (udid = '', params, once = false) => {
|
|
64
|
+
if (!_deviceHelper.deviceHelper.hasUdid(udid)) {
|
|
65
|
+
// 防止一直循环占用cpu资源
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 合并参数
|
|
70
|
+
const paramsObj = Object.assign(JSON.parse(params), {
|
|
71
|
+
udid
|
|
72
|
+
});
|
|
73
|
+
let label = 'Windows';
|
|
74
|
+
if ((0, _utils.isMac)()) {
|
|
75
|
+
label = 'Mac';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 通过调用 trust_status 来判断信任状态
|
|
79
|
+
const kitParamsObj = {
|
|
80
|
+
cmd: 'trust_status',
|
|
81
|
+
label,
|
|
82
|
+
params: JSON.stringify(paramsObj)
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// 获取信任状态
|
|
86
|
+
const trustStatusRes = (0, _utils3.callHunterInspectionKit)('TheForceKit', JSON.stringify(kitParamsObj));
|
|
87
|
+
if (trustStatusRes) {
|
|
88
|
+
const trustStatusResObj = JSON.parse(trustStatusRes);
|
|
89
|
+
const {
|
|
90
|
+
Code,
|
|
91
|
+
Data
|
|
92
|
+
} = trustStatusResObj;
|
|
93
|
+
if (Code == 0 && (Data.imei || Data.serialNumber)) {
|
|
94
|
+
return Data;
|
|
95
|
+
} else if (!once) {
|
|
96
|
+
await (0, _utils2.sleep)();
|
|
97
|
+
return await getTrustStatus(udid, params);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
};
|
|
102
|
+
const getTrustStatusOnce = async (udid, params) => {
|
|
103
|
+
return await getTrustStatus(udid, params, true);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 配对并获取信任状态
|
|
108
|
+
* @param {String} udid 设备id
|
|
109
|
+
* @returns
|
|
110
|
+
*/
|
|
111
|
+
const DevicePair = async (udid = '', params) => {
|
|
112
|
+
const callBack = () => {
|
|
113
|
+
saasCallBack({
|
|
114
|
+
data: {
|
|
115
|
+
eventName: _constants.EVENT_TYPE.TRUST_RESULT,
|
|
116
|
+
udid,
|
|
117
|
+
eventCode: 0
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// 单次获取信任状态
|
|
123
|
+
const trustStatusOnceRes = await getTrustStatusOnce(udid, params);
|
|
124
|
+
|
|
125
|
+
// 未信任弹起信任窗口
|
|
126
|
+
if (!trustStatusOnceRes) {
|
|
127
|
+
// 发布配对
|
|
128
|
+
publishPair(udid, params);
|
|
129
|
+
|
|
130
|
+
// 通过 trust_status 来判断信任状态
|
|
131
|
+
const trustStatusRes = await getTrustStatus(udid, params);
|
|
132
|
+
if (trustStatusRes) {
|
|
133
|
+
callBack();
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 已信任 直接返回
|
|
139
|
+
callBack();
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// 写入dll文件version
|
|
143
|
+
const writeDllVersion = version => {
|
|
144
|
+
const resourcePath = getResourcePath();
|
|
145
|
+
const versionPath = _path.default.resolve(resourcePath, 'version.online');
|
|
146
|
+
_fs.default.writeFile(versionPath, version, err => {
|
|
147
|
+
if (err) {
|
|
148
|
+
saasCallBack({
|
|
149
|
+
data: {
|
|
150
|
+
eventName: _constants.EVENT_TYPE.UPDATE_RESULT,
|
|
151
|
+
eventCode: -1 // eventCode 0 更新成功 -1 更新失败
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
console.log('========写入version成功');
|
|
157
|
+
// 写入成功后 重新初始化dll
|
|
158
|
+
(0, _utils4.initHunterInspectionKit)();
|
|
159
|
+
saasCallBack({
|
|
160
|
+
data: {
|
|
161
|
+
eventName: _constants.EVENT_TYPE.UPDATE_RESULT,
|
|
162
|
+
eventCode: 0 // eventCode 0 更新成功 -1 更新失败
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// 下载更新dll
|
|
169
|
+
const updateDll = (packageUrl, targetVersion) => {
|
|
170
|
+
// 若需要更新 则下载完成后 覆盖本地dll文件
|
|
171
|
+
let dllOutPath;
|
|
172
|
+
const resourcePath = getResourcePath();
|
|
173
|
+
if ((0, _utils.isMac)()) {
|
|
174
|
+
if ((0, _utils.isArm64)()) {
|
|
175
|
+
dllOutPath = _path.default.resolve(resourcePath, `mac/libinspectionkit_arm64_${targetVersion}.dylib`);
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
dllOutPath = _path.default.resolve(resourcePath, `dll/libinspectionkit_x64_${targetVersion}.dll`);
|
|
179
|
+
}
|
|
180
|
+
const dllStream = _fs.default.createWriteStream(dllOutPath);
|
|
181
|
+
(0, _request.default)(packageUrl).pipe(dllStream).on('close', function (err) {
|
|
182
|
+
if (err) {
|
|
183
|
+
saasCallBack({
|
|
184
|
+
data: {
|
|
185
|
+
eventName: _constants.EVENT_TYPE.UPDATE_RESULT,
|
|
186
|
+
eventCode: -1 // eventCode 0 更新成功 -1 更新失败
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
} else {
|
|
190
|
+
// 写version文件内容
|
|
191
|
+
writeDllVersion(targetVersion);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 更新下载dll文件 并重写本地版本号
|
|
198
|
+
* @param {String} udid 设备id
|
|
199
|
+
* @returns
|
|
200
|
+
*/
|
|
201
|
+
const updateDllFileCheck = () => {
|
|
202
|
+
// mac的amd不支持更新
|
|
203
|
+
if ((0, _utils.isMac)() && (0, _utils.isAmd64)()) return;
|
|
204
|
+
const updateParams = {
|
|
205
|
+
cmd: 'hot_update',
|
|
206
|
+
label: (0, _utils.isWin)() ? 'Windows' : 'Mac',
|
|
207
|
+
params: {}
|
|
208
|
+
};
|
|
209
|
+
const updateRes = (0, _utils3.callHunterInspectionKit)('TheForceKit', JSON.stringify(updateParams));
|
|
210
|
+
if (updateRes) {
|
|
211
|
+
const updateResObj = JSON.parse(updateRes);
|
|
212
|
+
const {
|
|
213
|
+
Code,
|
|
214
|
+
Data
|
|
215
|
+
} = updateResObj;
|
|
216
|
+
if (Code == 0) {
|
|
217
|
+
const {
|
|
218
|
+
isHot,
|
|
219
|
+
url,
|
|
220
|
+
targetVersion
|
|
221
|
+
} = Data;
|
|
222
|
+
|
|
223
|
+
// 需要更新 则直接下载
|
|
224
|
+
isHot == 1 && updateDll(url, targetVersion);
|
|
225
|
+
saasCallBack({
|
|
226
|
+
data: {
|
|
227
|
+
eventName: _constants.EVENT_TYPE.NEED_UPDATE,
|
|
228
|
+
eventCode: isHot == 1 ? 0 : -1 // eventCode 0 需要更新 -1 不需要更新
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
} else {
|
|
232
|
+
// 错误的时候不需要更新
|
|
233
|
+
saasCallBack({
|
|
234
|
+
data: {
|
|
235
|
+
eventName: _constants.EVENT_TYPE.NEED_UPDATE,
|
|
236
|
+
eventCode: -1 // eventCode 0 需要更新 -1 不需要更新
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* 检查并安装驱动
|
|
245
|
+
*/
|
|
246
|
+
const checkAndInstallDriver = () => {
|
|
247
|
+
return new Promise((resolve, reject) => {
|
|
248
|
+
if (!(0, _utils.isWin)()) {
|
|
249
|
+
resolve();
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
(0, _winDriver.checkHasDriver)().then(res => {
|
|
253
|
+
if (res) {
|
|
254
|
+
resolve();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
(0, _winDriver.downloadDriver)(percent => {
|
|
258
|
+
saasCallBack({
|
|
259
|
+
data: {
|
|
260
|
+
eventName: _constants.EVENT_TYPE.NEED_INSTALL_DRIVER,
|
|
261
|
+
eventCode: 0,
|
|
262
|
+
eventContent: JSON.stringify({
|
|
263
|
+
percent // 下载进度
|
|
264
|
+
})
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}).then(() => {
|
|
268
|
+
// 成功
|
|
269
|
+
console.log('驱动下载并安装成功');
|
|
270
|
+
saasCallBack({
|
|
271
|
+
data: {
|
|
272
|
+
eventName: _constants.EVENT_TYPE.INSTALL_DRIVER_RESULT,
|
|
273
|
+
eventCode: 0 // 0 成功 -1 失败
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
resolve();
|
|
277
|
+
}).catch(err => {
|
|
278
|
+
// 失败
|
|
279
|
+
console.error('驱动下载或安装失败', err);
|
|
280
|
+
Sentry.captureException('驱动下载或安装失败:' + JSON.stringify(err));
|
|
281
|
+
saasCallBack({
|
|
282
|
+
data: {
|
|
283
|
+
eventName: _constants.EVENT_TYPE.INSTALL_DRIVER_RESULT,
|
|
284
|
+
eventCode: -1 // 0 成功 -1 失败
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
reject();
|
|
288
|
+
});
|
|
289
|
+
}).catch(err => {
|
|
290
|
+
console.error('驱动检测失败', err);
|
|
291
|
+
Sentry.captureException('驱动检测失败:' + JSON.stringify(err));
|
|
292
|
+
reject();
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
const registerEvent = async (params, callBack) => {
|
|
297
|
+
saasCallBack = callBack;
|
|
298
|
+
|
|
299
|
+
// 检查是否需要更新dll
|
|
300
|
+
updateDllFileCheck();
|
|
301
|
+
|
|
302
|
+
// 在插线之前就检测驱动状态
|
|
303
|
+
await checkAndInstallDriver();
|
|
304
|
+
usbListener = new _usbmux.default.createListener().on('attached', async udid => {
|
|
305
|
+
if (!udid) return;
|
|
306
|
+
// 插入设备通知
|
|
307
|
+
saasCallBack({
|
|
308
|
+
data: {
|
|
309
|
+
eventName: _constants.EVENT_TYPE.USB_DEVICE_RESULT,
|
|
310
|
+
udid,
|
|
311
|
+
eventCode: 0
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
_deviceHelper.deviceHelper.addUdid(udid);
|
|
315
|
+
// 有驱动,直接运行脚本
|
|
316
|
+
DevicePair(udid, params);
|
|
317
|
+
}).on('detached', function (udid) {
|
|
318
|
+
// 拔出设备
|
|
319
|
+
saasCallBack({
|
|
320
|
+
data: {
|
|
321
|
+
eventName: _constants.EVENT_TYPE.USB_DISCONNECT,
|
|
322
|
+
udid,
|
|
323
|
+
eventCode: 0
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
_deviceHelper.deviceHelper.removeUdid(udid);
|
|
327
|
+
}).on('error', function (err) {
|
|
328
|
+
const errStr = 'usb连接错误:' + JSON.stringify(err);
|
|
329
|
+
console.log(errStr);
|
|
330
|
+
Sentry.captureException(errStr);
|
|
331
|
+
saasCallBack({
|
|
332
|
+
data: {
|
|
333
|
+
eventName: _constants.EVENT_TYPE.USB_ERROR,
|
|
334
|
+
eventCode: -1,
|
|
335
|
+
eventContent: JSON.stringify({
|
|
336
|
+
message: errStr
|
|
337
|
+
})
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
exports.registerEvent = registerEvent;
|
|
343
|
+
const unregisterEvent = () => {
|
|
344
|
+
usbListener && usbListener.destroy();
|
|
345
|
+
_deviceHelper.deviceHelper.clearUdidList();
|
|
346
|
+
};
|
|
347
|
+
exports.unregisterEvent = unregisterEvent;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getAndroidReport = getAndroidReport;
|
|
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 GetAndroidReport {
|
|
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
|
+
console.log('GetAndroidReport', event);
|
|
29
|
+
const {
|
|
30
|
+
payload
|
|
31
|
+
} = event.data;
|
|
32
|
+
this.callback(payload);
|
|
33
|
+
this.callback = null;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
initWorker() {
|
|
37
|
+
if (!this.worker) {
|
|
38
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
|
|
39
|
+
this.worker = new _webWorker.default(workerPath, {
|
|
40
|
+
type: 'module'
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
let entity = null;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 获取Android设备报告
|
|
49
|
+
* @param {Object} params - 请求参数
|
|
50
|
+
* @param {string} params.imei - 设备IMEI
|
|
51
|
+
* @param {string} params.brandCode - 品牌编码
|
|
52
|
+
* @param {Function} callback - 回调函数,接收报告结果
|
|
53
|
+
*/
|
|
54
|
+
function getAndroidReport(params, callback) {
|
|
55
|
+
if (!entity) {
|
|
56
|
+
entity = new GetAndroidReport();
|
|
57
|
+
}
|
|
58
|
+
const payload = (0, _utils.parsePayload)(params);
|
|
59
|
+
entity.exec(payload, callback);
|
|
60
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
|
|
13
|
+
// 处理主进程消息
|
|
14
|
+
function onMainMessage(event) {
|
|
15
|
+
const {
|
|
16
|
+
payload
|
|
17
|
+
} = event.data;
|
|
18
|
+
const res = abilityCallKit('android_report', payload);
|
|
19
|
+
postMessage(res);
|
|
20
|
+
}
|
|
21
|
+
addEventListener('message', onMainMessage);
|