hunter-open-sdk 2.0.0-beta.17 → 2.0.0-beta.19
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 +12 -18
- package/lib/abilities/activate/worker.js +6 -17
- package/lib/abilities/erase/index.js +12 -18
- package/lib/abilities/erase/worker.js +6 -17
- package/lib/{registerEvent → abilities/eventManager}/index.js +28 -26
- package/lib/{getAndroidSn → abilities/getAndroidSn}/index.js +10 -9
- package/lib/abilities/getGeneralReport/index.js +11 -17
- package/lib/abilities/getGeneralReport/worker.js +19 -32
- package/lib/abilities/getSaaSReport/index.js +11 -17
- package/lib/abilities/getSaaSReport/worker.js +6 -11
- package/lib/abilities/installApp/index.js +48 -0
- package/lib/abilities/installApp/worker.js +19 -0
- package/lib/abilities/reboot/index.js +12 -18
- package/lib/abilities/reboot/worker.js +6 -17
- package/lib/abilities/shutdown/index.js +12 -18
- package/lib/abilities/shutdown/worker.js +6 -17
- package/lib/abilities/skip/index.js +12 -18
- package/lib/abilities/skip/worker.js +6 -17
- package/lib/index.js +9 -7
- package/lib/resources/dll/{libinspectionkit_x64_0.3.1.dll → libinspectionkit_x64_0.4.0.dll} +0 -0
- package/lib/resources/mac/{libinspectionkit_amd64_0.3.1.dylib → libinspectionkit_amd64_0.4.0.dylib} +0 -0
- package/lib/resources/mac/{libinspectionkit_arm64_0.3.1.dylib → libinspectionkit_arm64_0.4.0.dylib} +0 -0
- package/lib/resources/version.online +1 -1
- package/lib/utils/utils.ability.js +9 -0
- package/lib/utils/utils.common.js +13 -1
- package/lib/utils/utils.global.js +36 -258
- package/package.json +1 -1
|
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.activate = activate;
|
|
7
7
|
var _webWorker = _interopRequireDefault(require("web-worker"));
|
|
8
8
|
var _url = _interopRequireDefault(require("url"));
|
|
9
|
-
var _utils = require("../../utils/utils.
|
|
9
|
+
var _utils = require("../../utils/utils.common");
|
|
10
|
+
var _utils2 = require("../../utils/utils.path");
|
|
11
|
+
var _utils3 = require("../../utils/utils.ability");
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
13
|
class Activate {
|
|
12
14
|
constructor() {
|
|
@@ -15,33 +17,24 @@ class Activate {
|
|
|
15
17
|
}
|
|
16
18
|
worker = null;
|
|
17
19
|
callback = null;
|
|
18
|
-
exec(
|
|
19
|
-
this.callback = callback;
|
|
20
|
+
exec(payload, callback) {
|
|
21
|
+
this.callback = typeof callback === 'function' ? callback : _utils3.defaultCallback;
|
|
20
22
|
this.worker && this.worker.postMessage({
|
|
21
|
-
|
|
22
|
-
params
|
|
23
|
+
payload
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
initWorkerListener() {
|
|
26
27
|
this.worker && this.worker.addEventListener('message', event => {
|
|
27
28
|
const {
|
|
28
|
-
|
|
29
|
-
data
|
|
29
|
+
payload
|
|
30
30
|
} = event.data;
|
|
31
|
-
|
|
32
|
-
case 'activateSuccess':
|
|
33
|
-
this.callback(data);
|
|
34
|
-
break;
|
|
35
|
-
case 'activateFail':
|
|
36
|
-
this.callback(data);
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
31
|
+
this.callback(payload);
|
|
39
32
|
this.callback = null;
|
|
40
33
|
});
|
|
41
34
|
}
|
|
42
35
|
initWorker() {
|
|
43
36
|
if (!this.worker) {
|
|
44
|
-
const workerPath = new _url.default.URL('file://' + (0,
|
|
37
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.getCurrentEnvPath)(__dirname, './worker.js'));
|
|
45
38
|
this.worker = new _webWorker.default(workerPath, {
|
|
46
39
|
type: 'module'
|
|
47
40
|
});
|
|
@@ -49,6 +42,7 @@ class Activate {
|
|
|
49
42
|
}
|
|
50
43
|
}
|
|
51
44
|
const entity = new Activate();
|
|
52
|
-
function activate(
|
|
53
|
-
|
|
45
|
+
function activate(params, callback) {
|
|
46
|
+
const payload = (0, _utils.parsePayload)(params);
|
|
47
|
+
entity.exec(payload, callback);
|
|
54
48
|
}
|
|
@@ -3,28 +3,17 @@
|
|
|
3
3
|
const {
|
|
4
4
|
initWorkerNodePath
|
|
5
5
|
} = require("../../utils/utils.worker");
|
|
6
|
+
|
|
7
|
+
// 先注册NodePath后才能正常使用node包,请勿挪动位置
|
|
6
8
|
initWorkerNodePath();
|
|
7
9
|
const {
|
|
8
|
-
|
|
10
|
+
abilityCallKit
|
|
9
11
|
} = require("../../utils/utils.global");
|
|
10
12
|
function onMainMessage(event) {
|
|
11
13
|
const {
|
|
12
|
-
|
|
13
|
-
params
|
|
14
|
+
payload
|
|
14
15
|
} = event.data;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
{
|
|
18
|
-
if (!params) {
|
|
19
|
-
return {
|
|
20
|
-
code: -1,
|
|
21
|
-
message: '【activate】方法缺少必要参数'
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
const res = activateCallKit(params);
|
|
25
|
-
postMessage(res);
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
16
|
+
const res = abilityCallKit('activate', payload);
|
|
17
|
+
postMessage(res);
|
|
29
18
|
}
|
|
30
19
|
addEventListener('message', onMainMessage);
|
|
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.erase = erase;
|
|
7
7
|
var _webWorker = _interopRequireDefault(require("web-worker"));
|
|
8
8
|
var _url = _interopRequireDefault(require("url"));
|
|
9
|
-
var _utils = require("../../utils/utils.
|
|
9
|
+
var _utils = require("../../utils/utils.common");
|
|
10
|
+
var _utils2 = require("../../utils/utils.path");
|
|
11
|
+
var _utils3 = require("../../utils/utils.ability");
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
13
|
class Erase {
|
|
12
14
|
constructor() {
|
|
@@ -15,33 +17,24 @@ class Erase {
|
|
|
15
17
|
}
|
|
16
18
|
worker = null;
|
|
17
19
|
callback = null;
|
|
18
|
-
exec(
|
|
19
|
-
this.callback = callback;
|
|
20
|
+
exec(payload, callback) {
|
|
21
|
+
this.callback = typeof callback === 'function' ? callback : _utils3.defaultCallback;
|
|
20
22
|
this.worker && this.worker.postMessage({
|
|
21
|
-
|
|
22
|
-
params
|
|
23
|
+
payload
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
initWorkerListener() {
|
|
26
27
|
this.worker && this.worker.addEventListener('message', event => {
|
|
27
28
|
const {
|
|
28
|
-
|
|
29
|
-
data
|
|
29
|
+
payload
|
|
30
30
|
} = event.data;
|
|
31
|
-
|
|
32
|
-
case 'eraseSuccess':
|
|
33
|
-
this.callback(data);
|
|
34
|
-
break;
|
|
35
|
-
case 'eraseFail':
|
|
36
|
-
this.callback(data);
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
31
|
+
this.callback(payload);
|
|
39
32
|
this.callback = null;
|
|
40
33
|
});
|
|
41
34
|
}
|
|
42
35
|
initWorker() {
|
|
43
36
|
if (!this.worker) {
|
|
44
|
-
const workerPath = new _url.default.URL('file://' + (0,
|
|
37
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.getCurrentEnvPath)(__dirname, './worker.js'));
|
|
45
38
|
this.worker = new _webWorker.default(workerPath, {
|
|
46
39
|
type: 'module'
|
|
47
40
|
});
|
|
@@ -49,6 +42,7 @@ class Erase {
|
|
|
49
42
|
}
|
|
50
43
|
}
|
|
51
44
|
const entity = new Erase();
|
|
52
|
-
function erase(
|
|
53
|
-
|
|
45
|
+
function erase(params, callback) {
|
|
46
|
+
const payload = (0, _utils.parsePayload)(params);
|
|
47
|
+
entity.exec(payload, callback);
|
|
54
48
|
}
|
|
@@ -3,28 +3,17 @@
|
|
|
3
3
|
const {
|
|
4
4
|
initWorkerNodePath
|
|
5
5
|
} = require("../../utils/utils.worker");
|
|
6
|
+
|
|
7
|
+
// 先注册NodePath后才能正常使用node包,请勿挪动位置
|
|
6
8
|
initWorkerNodePath();
|
|
7
9
|
const {
|
|
8
|
-
|
|
10
|
+
abilityCallKit
|
|
9
11
|
} = require("../../utils/utils.global");
|
|
10
12
|
function onMainMessage(event) {
|
|
11
13
|
const {
|
|
12
|
-
|
|
13
|
-
params
|
|
14
|
+
payload
|
|
14
15
|
} = event.data;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
{
|
|
18
|
-
if (!params) {
|
|
19
|
-
return {
|
|
20
|
-
code: -1,
|
|
21
|
-
message: '【erase】方法缺少必要参数'
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
const res = eraseCallKit(params);
|
|
25
|
-
postMessage(res);
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
16
|
+
const res = abilityCallKit('erase', payload);
|
|
17
|
+
postMessage(res);
|
|
29
18
|
}
|
|
30
19
|
addEventListener('message', onMainMessage);
|
|
@@ -3,19 +3,21 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 }; }
|
|
19
21
|
// saas回调
|
|
20
22
|
let saasCallBack;
|
|
21
23
|
|
|
@@ -27,10 +29,10 @@ let usbListener = null;
|
|
|
27
29
|
const getResourcePath = () => {
|
|
28
30
|
if ((0, _utils.isDev)()) {
|
|
29
31
|
// 开发环境:使用源码目录
|
|
30
|
-
return
|
|
32
|
+
return _path.default.resolve(__dirname, '../resources');
|
|
31
33
|
} else {
|
|
32
34
|
// 生产环境:使用 Electron 的资源路径
|
|
33
|
-
return
|
|
35
|
+
return _path.default.resolve(process.resourcesPath, 'resources');
|
|
34
36
|
}
|
|
35
37
|
};
|
|
36
38
|
|
|
@@ -139,8 +141,8 @@ const DevicePair = async (udid = '', params) => {
|
|
|
139
141
|
// 写入dll文件version
|
|
140
142
|
const writeDllVersion = version => {
|
|
141
143
|
const resourcePath = getResourcePath();
|
|
142
|
-
const versionPath =
|
|
143
|
-
|
|
144
|
+
const versionPath = _path.default.resolve(resourcePath, 'version.online');
|
|
145
|
+
_fs.default.writeFile(versionPath, version, err => {
|
|
144
146
|
if (err) {
|
|
145
147
|
saasCallBack({
|
|
146
148
|
data: {
|
|
@@ -169,13 +171,13 @@ const updateDll = (packageUrl, targetVersion) => {
|
|
|
169
171
|
const resourcePath = getResourcePath();
|
|
170
172
|
if ((0, _utils.isMac)()) {
|
|
171
173
|
if ((0, _utils.isArm64)()) {
|
|
172
|
-
dllOutPath =
|
|
174
|
+
dllOutPath = _path.default.resolve(resourcePath, `mac/libinspectionkit_arm64_${targetVersion}.dylib`);
|
|
173
175
|
}
|
|
174
176
|
} else {
|
|
175
|
-
dllOutPath =
|
|
177
|
+
dllOutPath = _path.default.resolve(resourcePath, `dll/libinspectionkit_x64_${targetVersion}.dll`);
|
|
176
178
|
}
|
|
177
|
-
const dllStream =
|
|
178
|
-
|
|
179
|
+
const dllStream = _fs.default.createWriteStream(dllOutPath);
|
|
180
|
+
(0, _request.default)(packageUrl).pipe(dllStream).on('close', function (err) {
|
|
179
181
|
if (err) {
|
|
180
182
|
saasCallBack({
|
|
181
183
|
data: {
|
|
@@ -290,7 +292,7 @@ const checkAndInstallDriver = () => {
|
|
|
290
292
|
});
|
|
291
293
|
});
|
|
292
294
|
};
|
|
293
|
-
const
|
|
295
|
+
const registerEvent = async (params, callBack) => {
|
|
294
296
|
saasCallBack = callBack;
|
|
295
297
|
|
|
296
298
|
// 检查是否需要更新dll
|
|
@@ -298,7 +300,7 @@ const RegisterEvent = async (params, callBack) => {
|
|
|
298
300
|
|
|
299
301
|
// 在插线之前就检测驱动状态
|
|
300
302
|
await checkAndInstallDriver();
|
|
301
|
-
usbListener = new
|
|
303
|
+
usbListener = new _usbmux.default.createListener().on('attached', async udid => {
|
|
302
304
|
if (!udid) return;
|
|
303
305
|
// 插入设备通知
|
|
304
306
|
saasCallBack({
|
|
@@ -328,9 +330,9 @@ const RegisterEvent = async (params, callBack) => {
|
|
|
328
330
|
throw new Error(errMsg);
|
|
329
331
|
});
|
|
330
332
|
};
|
|
331
|
-
exports.
|
|
332
|
-
const
|
|
333
|
+
exports.registerEvent = registerEvent;
|
|
334
|
+
const unregisterEvent = () => {
|
|
333
335
|
usbListener && usbListener.destroy();
|
|
334
336
|
_deviceHelper.deviceHelper.clearUdidList();
|
|
335
337
|
};
|
|
336
|
-
exports.
|
|
338
|
+
exports.unregisterEvent = unregisterEvent;
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.unregisterGetAndroidSn = exports.registerGetAndroidSn = void 0;
|
|
7
7
|
var _usb = require("usb");
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
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;
|
|
12
13
|
let hadRegisterUsb = false; // 是否已经注册过usb事件
|
|
13
14
|
let isPause = false; // 是否暂停获取sn
|
|
14
15
|
|
|
@@ -117,7 +118,7 @@ const getWinSn = async (device, callBack) => {
|
|
|
117
118
|
* @param {Object} params - 参数
|
|
118
119
|
* @param {Function} callBack - 回调函数
|
|
119
120
|
*/
|
|
120
|
-
const
|
|
121
|
+
const registerGetAndroidSn = (params, callBack) => {
|
|
121
122
|
if (hadRegisterUsb) {
|
|
122
123
|
isPause = false;
|
|
123
124
|
return;
|
|
@@ -157,8 +158,8 @@ const GetAndroidSn = (params, callBack) => {
|
|
|
157
158
|
}
|
|
158
159
|
});
|
|
159
160
|
};
|
|
160
|
-
exports.
|
|
161
|
-
const
|
|
161
|
+
exports.registerGetAndroidSn = registerGetAndroidSn;
|
|
162
|
+
const unregisterGetAndroidSn = () => {
|
|
162
163
|
isPause = true;
|
|
163
164
|
};
|
|
164
|
-
exports.
|
|
165
|
+
exports.unregisterGetAndroidSn = unregisterGetAndroidSn;
|
|
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getGeneralReport = getGeneralReport;
|
|
7
7
|
var _webWorker = _interopRequireDefault(require("web-worker"));
|
|
8
8
|
var _url = _interopRequireDefault(require("url"));
|
|
9
|
-
var _utils = require("../../utils/utils.
|
|
9
|
+
var _utils = require("../../utils/utils.common");
|
|
10
|
+
var _utils2 = require("../../utils/utils.path");
|
|
11
|
+
var _utils3 = require("../../utils/utils.ability");
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
13
|
class GetGeneralReport {
|
|
12
14
|
constructor() {
|
|
@@ -15,33 +17,24 @@ class GetGeneralReport {
|
|
|
15
17
|
}
|
|
16
18
|
worker = null;
|
|
17
19
|
callback = null;
|
|
18
|
-
exec(
|
|
19
|
-
this.callback = callback;
|
|
20
|
+
exec(payload, callback) {
|
|
21
|
+
this.callback = typeof callback === 'function' ? callback : _utils3.defaultCallback;
|
|
20
22
|
this.worker && this.worker.postMessage({
|
|
21
|
-
|
|
22
|
-
params
|
|
23
|
+
payload
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
initWorkerListener() {
|
|
26
27
|
this.worker && this.worker.addEventListener('message', event => {
|
|
27
28
|
const {
|
|
28
|
-
|
|
29
|
-
data
|
|
29
|
+
payload
|
|
30
30
|
} = event.data;
|
|
31
|
-
|
|
32
|
-
case 'getGeneralReportSuccess':
|
|
33
|
-
this.callback(data);
|
|
34
|
-
break;
|
|
35
|
-
case 'getGeneralReportFail':
|
|
36
|
-
this.callback(data);
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
31
|
+
this.callback(payload);
|
|
39
32
|
this.callback = null;
|
|
40
33
|
});
|
|
41
34
|
}
|
|
42
35
|
initWorker() {
|
|
43
36
|
if (!this.worker) {
|
|
44
|
-
const workerPath = new _url.default.URL('file://' + (0,
|
|
37
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.getCurrentEnvPath)(__dirname, './worker.js'));
|
|
45
38
|
this.worker = new _webWorker.default(workerPath, {
|
|
46
39
|
type: 'module'
|
|
47
40
|
});
|
|
@@ -50,5 +43,6 @@ class GetGeneralReport {
|
|
|
50
43
|
}
|
|
51
44
|
const entity = new GetGeneralReport();
|
|
52
45
|
function getGeneralReport(params, callback) {
|
|
53
|
-
|
|
46
|
+
const payload = (0, _utils.parsePayload)(params);
|
|
47
|
+
entity.exec(payload, callback);
|
|
54
48
|
}
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
const {
|
|
4
4
|
initWorkerNodePath
|
|
5
5
|
} = require("../../utils/utils.worker");
|
|
6
|
+
|
|
7
|
+
// 先注册NodePath后才能正常使用node包,请勿挪动位置
|
|
6
8
|
initWorkerNodePath();
|
|
7
9
|
const {
|
|
8
|
-
|
|
10
|
+
abilityCallKit
|
|
9
11
|
} = require("../../utils/utils.global");
|
|
10
12
|
const MAX_RETRY_COUNT = 3;
|
|
11
13
|
const RETRY_INTERVAL = 300;
|
|
@@ -13,39 +15,24 @@ const RETRY_INTERVAL = 300;
|
|
|
13
15
|
// 处理主进程消息
|
|
14
16
|
function onMainMessage(event, retryCount = 0) {
|
|
15
17
|
const {
|
|
16
|
-
|
|
17
|
-
params
|
|
18
|
+
payload
|
|
18
19
|
} = event.data;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
message: '【getGeneralReport】方法缺少必要参数'
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
const reportRes = getGeneralReportCallKit(params);
|
|
29
|
-
console.log(`第${retryCount + 1}次获取报告:`, reportRes);
|
|
30
|
-
const {
|
|
31
|
-
data: {
|
|
32
|
-
code
|
|
33
|
-
} = {}
|
|
34
|
-
} = reportRes;
|
|
20
|
+
const reportRes = abilityCallKit('general_report', payload);
|
|
21
|
+
const {
|
|
22
|
+
payload: {
|
|
23
|
+
code
|
|
24
|
+
} = {}
|
|
25
|
+
} = reportRes;
|
|
35
26
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
postMessage(reportRes);
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
default:
|
|
48
|
-
break;
|
|
27
|
+
// 如果获取报告失败,则重试一次
|
|
28
|
+
if (code !== 0 && retryCount < MAX_RETRY_COUNT) {
|
|
29
|
+
retryCount++;
|
|
30
|
+
console.log(`获取报告失败,重试次数:${retryCount}/${MAX_RETRY_COUNT}`);
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
onMainMessage(event, retryCount);
|
|
33
|
+
}, retryCount * RETRY_INTERVAL);
|
|
34
|
+
return;
|
|
49
35
|
}
|
|
36
|
+
postMessage(reportRes);
|
|
50
37
|
}
|
|
51
38
|
addEventListener('message', onMainMessage);
|
|
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getSaaSReport = getSaaSReport;
|
|
7
7
|
var _webWorker = _interopRequireDefault(require("web-worker"));
|
|
8
8
|
var _url = _interopRequireDefault(require("url"));
|
|
9
|
-
var _utils = require("../../utils/utils.
|
|
9
|
+
var _utils = require("../../utils/utils.common");
|
|
10
|
+
var _utils2 = require("../../utils/utils.path");
|
|
11
|
+
var _utils3 = require("../../utils/utils.ability");
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
13
|
class GetSaaSReport {
|
|
12
14
|
constructor() {
|
|
@@ -15,33 +17,24 @@ class GetSaaSReport {
|
|
|
15
17
|
}
|
|
16
18
|
worker = null;
|
|
17
19
|
callback = null;
|
|
18
|
-
exec(
|
|
19
|
-
this.callback = callback;
|
|
20
|
+
exec(payload, callback) {
|
|
21
|
+
this.callback = typeof callback === 'function' ? callback : _utils3.defaultCallback;
|
|
20
22
|
this.worker && this.worker.postMessage({
|
|
21
|
-
|
|
22
|
-
params
|
|
23
|
+
payload
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
initWorkerListener() {
|
|
26
27
|
this.worker && this.worker.addEventListener('message', event => {
|
|
27
28
|
const {
|
|
28
|
-
|
|
29
|
-
data
|
|
29
|
+
payload
|
|
30
30
|
} = event.data;
|
|
31
|
-
|
|
32
|
-
case 'getSaaSReportSuccess':
|
|
33
|
-
this.callback(data);
|
|
34
|
-
break;
|
|
35
|
-
case 'getSaaSReportFail':
|
|
36
|
-
this.callback(data);
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
31
|
+
this.callback(payload);
|
|
39
32
|
this.callback = null;
|
|
40
33
|
});
|
|
41
34
|
}
|
|
42
35
|
initWorker() {
|
|
43
36
|
if (!this.worker) {
|
|
44
|
-
const workerPath = new _url.default.URL('file://' + (0,
|
|
37
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils2.getCurrentEnvPath)(__dirname, './worker.js'));
|
|
45
38
|
this.worker = new _webWorker.default(workerPath, {
|
|
46
39
|
type: 'module'
|
|
47
40
|
});
|
|
@@ -50,5 +43,6 @@ class GetSaaSReport {
|
|
|
50
43
|
}
|
|
51
44
|
const entity = new GetSaaSReport();
|
|
52
45
|
function getSaaSReport(params, callback) {
|
|
53
|
-
|
|
46
|
+
const payload = (0, _utils.parsePayload)(params);
|
|
47
|
+
entity.exec(payload, callback);
|
|
54
48
|
}
|
|
@@ -3,24 +3,19 @@
|
|
|
3
3
|
const {
|
|
4
4
|
initWorkerNodePath
|
|
5
5
|
} = require("../../utils/utils.worker");
|
|
6
|
+
|
|
7
|
+
// 先注册NodePath后才能正常使用node包,请勿挪动位置
|
|
6
8
|
initWorkerNodePath();
|
|
7
9
|
const {
|
|
8
|
-
|
|
10
|
+
abilityCallKit
|
|
9
11
|
} = require("../../utils/utils.global");
|
|
10
12
|
|
|
11
13
|
// 处理主进程消息
|
|
12
14
|
function onMainMessage(event) {
|
|
13
15
|
const {
|
|
14
|
-
|
|
15
|
-
params
|
|
16
|
+
payload
|
|
16
17
|
} = event.data;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const reportRes = getSaaSReportCallKit(params);
|
|
20
|
-
postMessage(reportRes);
|
|
21
|
-
break;
|
|
22
|
-
default:
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
18
|
+
const res = abilityCallKit('saas_report', payload);
|
|
19
|
+
postMessage(res);
|
|
25
20
|
}
|
|
26
21
|
addEventListener('message', onMainMessage);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.installApp = installApp;
|
|
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 InstallApp {
|
|
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 InstallApp();
|
|
45
|
+
function installApp(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('install_app', payload);
|
|
17
|
+
postMessage(res);
|
|
18
|
+
}
|
|
19
|
+
addEventListener('message', onMainMessage);
|