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
|
@@ -0,0 +1,75 @@
|
|
|
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.convertPathWithCurrentEnv)(__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 = null;
|
|
57
|
+
function getGeneralReport(params, callback, options = {}) {
|
|
58
|
+
const cb = typeof callback === 'function' ? callback : _utils3.defaultCallback;
|
|
59
|
+
const payload = (0, _utils.parsePayload)(params);
|
|
60
|
+
const {
|
|
61
|
+
useMultiWorker = false,
|
|
62
|
+
poolSize = DEFAULT_POOL_SIZE
|
|
63
|
+
} = options;
|
|
64
|
+
if (!useMultiWorker) {
|
|
65
|
+
if (!pool || pool.poolSize !== 1) {
|
|
66
|
+
pool = new WorkerPool(1);
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
const targetSize = poolSize;
|
|
70
|
+
if (!pool || pool.poolSize !== targetSize) {
|
|
71
|
+
pool = new WorkerPool(targetSize);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
pool.exec(payload, cb);
|
|
75
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
const MAX_RETRY_COUNT = 3;
|
|
13
|
+
const RETRY_INTERVAL = 300;
|
|
14
|
+
|
|
15
|
+
// 处理主进程消息
|
|
16
|
+
function onMainMessage(event, retryCount = 0) {
|
|
17
|
+
const {
|
|
18
|
+
payload
|
|
19
|
+
} = event.data;
|
|
20
|
+
const reportRes = abilityCallKit('general_report', payload);
|
|
21
|
+
const {
|
|
22
|
+
payload: {
|
|
23
|
+
code
|
|
24
|
+
} = {}
|
|
25
|
+
} = reportRes;
|
|
26
|
+
|
|
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;
|
|
35
|
+
}
|
|
36
|
+
postMessage(reportRes);
|
|
37
|
+
}
|
|
38
|
+
addEventListener('message', onMainMessage);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSaaSReport = getSaaSReport;
|
|
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 GetSaaSReport {
|
|
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 getSaaSReport(params, callback) {
|
|
46
|
+
if (!entity) {
|
|
47
|
+
entity = new GetSaaSReport();
|
|
48
|
+
}
|
|
49
|
+
const payload = (0, _utils.parsePayload)(params);
|
|
50
|
+
entity.exec(payload, callback);
|
|
51
|
+
}
|
|
@@ -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('saas_report', payload);
|
|
19
|
+
postMessage(res);
|
|
20
|
+
}
|
|
21
|
+
addEventListener('message', onMainMessage);
|
|
@@ -0,0 +1,51 @@
|
|
|
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.convertPathWithCurrentEnv)(__dirname, './worker.js'));
|
|
38
|
+
this.worker = new _webWorker.default(workerPath, {
|
|
39
|
+
type: 'module'
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let entity = null;
|
|
45
|
+
function installApp(params, callback) {
|
|
46
|
+
if (!entity) {
|
|
47
|
+
entity = new InstallApp();
|
|
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('install_app', 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.reboot = reboot;
|
|
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 Reboot {
|
|
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 reboot(params, callback) {
|
|
46
|
+
if (!entity) {
|
|
47
|
+
entity = new Reboot();
|
|
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('reboot', 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.shutdown = shutdown;
|
|
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 Shutdown {
|
|
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 shutdown(params, callback) {
|
|
46
|
+
if (!entity) {
|
|
47
|
+
entity = new Shutdown();
|
|
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('shutdown', 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.skip = skip;
|
|
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 Skip {
|
|
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 skip(params, callback) {
|
|
46
|
+
if (!entity) {
|
|
47
|
+
entity = new Skip();
|
|
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('skip', payload);
|
|
17
|
+
postMessage(res);
|
|
18
|
+
}
|
|
19
|
+
addEventListener('message', onMainMessage);
|
|
@@ -4,29 +4,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.command = command;
|
|
7
|
-
|
|
8
|
-
function command(cmd) {
|
|
9
|
-
var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : './';
|
|
7
|
+
const exec = require('child_process').exec;
|
|
8
|
+
function command(cmd, path = './') {
|
|
10
9
|
// 任何你期望执行的cmd命令,ls都可以
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
let cmdStr1 = cmd;
|
|
11
|
+
let cmdPath = path;
|
|
13
12
|
// 子进程名称
|
|
14
|
-
|
|
13
|
+
let workerProcess;
|
|
15
14
|
runExec(cmdStr1);
|
|
16
15
|
function runExec(cmdStr) {
|
|
17
16
|
workerProcess = exec(cmdStr, {
|
|
18
17
|
cwd: cmdPath
|
|
19
18
|
});
|
|
20
19
|
// 打印正常的后台可执行程序输出
|
|
21
|
-
workerProcess.stdout.on('data',
|
|
20
|
+
workerProcess.stdout.on('data', data => {
|
|
22
21
|
console.log('stdout: ' + data);
|
|
23
22
|
});
|
|
24
23
|
// 打印错误的后台可执行程序输出
|
|
25
|
-
workerProcess.stderr.on('data',
|
|
24
|
+
workerProcess.stderr.on('data', data => {
|
|
26
25
|
console.log('stderr: ' + data);
|
|
27
26
|
});
|
|
28
27
|
// 退出之后的输出
|
|
29
|
-
workerProcess.on('close',
|
|
28
|
+
workerProcess.on('close', code => {
|
|
30
29
|
console.log('out code:' + code);
|
|
31
30
|
});
|
|
32
31
|
}
|