hunter-open-sdk 2.0.0-beta.3 → 2.0.0-beta.31

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.
Files changed (53) hide show
  1. package/lib/abilities/activate/index.js +51 -0
  2. package/lib/abilities/activate/worker.js +19 -0
  3. package/lib/abilities/erase/index.js +21 -0
  4. package/lib/abilities/erase/worker.js +19 -0
  5. package/lib/abilities/eventManager/index.js +347 -0
  6. package/lib/abilities/getAndroidReport/index.js +60 -0
  7. package/lib/abilities/getAndroidReport/worker.js +21 -0
  8. package/lib/abilities/getAndroidSn/index.js +187 -0
  9. package/lib/abilities/getGeneralReport/index.js +21 -0
  10. package/lib/abilities/getGeneralReport/worker.js +38 -0
  11. package/lib/abilities/getSaaSReport/index.js +51 -0
  12. package/lib/abilities/getSaaSReport/worker.js +21 -0
  13. package/lib/abilities/getUltimateReport/index.js +59 -0
  14. package/lib/abilities/getUltimateReport/worker.js +21 -0
  15. package/lib/abilities/installApp/index.js +51 -0
  16. package/lib/abilities/installApp/worker.js +19 -0
  17. package/lib/abilities/reboot/index.js +51 -0
  18. package/lib/abilities/reboot/worker.js +19 -0
  19. package/lib/abilities/shutdown/index.js +51 -0
  20. package/lib/abilities/shutdown/worker.js +19 -0
  21. package/lib/abilities/skip/index.js +21 -0
  22. package/lib/abilities/skip/worker.js +19 -0
  23. package/lib/constants/index.js +28 -0
  24. package/lib/events/driver/command.js +8 -9
  25. package/lib/events/driver/winDriver.js +123 -189
  26. package/lib/helper/deviceHelper.js +19 -37
  27. package/lib/index.d.ts +69 -0
  28. package/lib/index.js +115 -13
  29. package/lib/index.mjs +2 -0
  30. package/lib/resources/dll/{libinspectionkit_x64_0.1.0.dll → libinspectionkit_x64_0.6.1.dll} +0 -0
  31. package/lib/resources/{mac/libinspectionkit_arm64_0.1.0.dylib → dylib/libinspectionkit_amd64_0.6.1.dylib} +0 -0
  32. package/lib/resources/dylib/libinspectionkit_arm64_0.6.1.dylib +0 -0
  33. package/lib/resources/version.online +1 -1
  34. package/lib/utils/utils.ability.js +9 -0
  35. package/lib/utils/utils.command.js +8 -9
  36. package/lib/utils/utils.common.js +26 -0
  37. package/lib/utils/{utils.js → utils.env.js} +19 -18
  38. package/lib/utils/utils.global.js +70 -89
  39. package/lib/utils/utils.initDll.js +16 -14
  40. package/lib/utils/utils.path.js +56 -7
  41. package/lib/utils/utils.process.js +35 -0
  42. package/lib/utils/utils.sn.js +41 -56
  43. package/lib/utils/utils.worker.js +32 -0
  44. package/lib/utils/workerPool.js +100 -0
  45. package/package.json +15 -8
  46. package/lib/events/driver/service.js +0 -47
  47. package/lib/getAndroidSn/index.js +0 -228
  48. package/lib/getGeneralReport/index.js +0 -76
  49. package/lib/getGeneralReport/worker.js +0 -20
  50. package/lib/getSaaSReport/index.js +0 -76
  51. package/lib/getSaaSReport/worker.js +0 -20
  52. package/lib/registerEvent/index.js +0 -427
  53. package/lib/resources/mac/libinspectionkit_amd64_0.1.0.dylib +0 -0
@@ -0,0 +1,187 @@
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
+ var _constants = require("../../constants");
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ const exec = _child_process.default.exec;
14
+ let hadRegisterUsb = false; // 是否已经注册过usb事件
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
+ data: {
33
+ eventName: _constants.EVENT_TYPE.GET_ANDROID_SN_RESULT,
34
+ eventCode: -1,
35
+ message: '获取SN失败'
36
+ }
37
+ });
38
+ return '';
39
+ }
40
+
41
+ // 检查设备是否为支持的三星、华为、荣耀手机品牌
42
+ const deviceInfo = currentDevice[0];
43
+ const productName = deviceInfo.productName?.toLowerCase() || '';
44
+ const manufacturerName = deviceInfo.manufacturerName?.toLowerCase() || '';
45
+ const isSupportedBrand = _utils2.SUPPORT_PHONE_BRANDS.some(brand => productName.includes(brand) || manufacturerName.includes(brand));
46
+ if (!isSupportedBrand) {
47
+ callBack({
48
+ data: {
49
+ eventName: _constants.EVENT_TYPE.GET_ANDROID_SN_RESULT,
50
+ eventCode: -1,
51
+ message: '暂不支持该品牌手机查询SN'
52
+ }
53
+ });
54
+ return '';
55
+ }
56
+ const sn = currentDevice[0].serialNumber;
57
+ const brand = deviceInfo.manufacturerName?.replace(/\s*/g, '') || '';
58
+ callBack({
59
+ data: {
60
+ eventName: _constants.EVENT_TYPE.GET_ANDROID_SN_RESULT,
61
+ eventCode: 0,
62
+ eventContent: {
63
+ SN: sn,
64
+ brand
65
+ },
66
+ message: '获取SN成功'
67
+ }
68
+ });
69
+ return sn;
70
+ };
71
+
72
+ // win获取sn
73
+ const getWinSn = async (device, callBack) => {
74
+ // windows 需要运行命令获取sn
75
+ const cmdStr = `wmic path Win32_PnPEntity where "DeviceID like \'USB%\'" get Name, PNPDeviceID /value`;
76
+ exec(cmdStr, function (err, stdout, stderr) {
77
+ if (err) {
78
+ // 运行失败 则直接返回获取失败
79
+ callBack({
80
+ data: {
81
+ eventName: _constants.EVENT_TYPE.GET_ANDROID_SN_RESULT,
82
+ eventCode: -1,
83
+ message: `windows运行程序获取SN失败err: ${err}`
84
+ }
85
+ });
86
+ return '';
87
+ }
88
+ if (stderr) {
89
+ // 运行失败 则直接返回获取失败
90
+ callBack({
91
+ data: {
92
+ eventName: _constants.EVENT_TYPE.GET_ANDROID_SN_RESULT,
93
+ eventCode: -1,
94
+ message: `windows运行程序获取SN失败stderr: ${stderr}`
95
+ }
96
+ });
97
+ return '';
98
+ }
99
+
100
+ // 处理WMIC输出并提取手机序列号
101
+ const phoneDevices = (0, _utils2.parseWmicOutput)(stdout);
102
+ if (phoneDevices.length === 0) {
103
+ callBack({
104
+ data: {
105
+ eventName: _constants.EVENT_TYPE.GET_ANDROID_SN_RESULT,
106
+ eventCode: -1,
107
+ message: `暂不支持该品牌手机查询SN`
108
+ }
109
+ });
110
+ return '';
111
+ }
112
+ console.log('检测到的手机设备:');
113
+ const sn = phoneDevices[0].serial;
114
+ const brand = phoneDevices[0].name?.replace(/\s*/g, '') || '';
115
+ callBack({
116
+ data: {
117
+ eventName: _constants.EVENT_TYPE.GET_ANDROID_SN_RESULT,
118
+ eventCode: 0,
119
+ eventContent: {
120
+ SN: sn,
121
+ brand
122
+ },
123
+ message: `获取SN成功`
124
+ }
125
+ });
126
+ // phoneDevices.forEach(device => {
127
+ // console.log(`设备名称: ${device.name}`);
128
+ // console.log(`序列号: ${device.serial}`);
129
+ // console.log(`PNPDeviceID: ${device.pnpDeviceId}`);
130
+ // console.log('---');
131
+ // });
132
+
133
+ return sn;
134
+ });
135
+ };
136
+
137
+ /**
138
+ * 获取Android SN
139
+ * @param {Object} params - 参数
140
+ * @param {Function} callBack - 回调函数
141
+ */
142
+ const registerGetAndroidSn = (params, callBack) => {
143
+ if (hadRegisterUsb) {
144
+ return;
145
+ }
146
+ hadRegisterUsb = true;
147
+ _usb.usb.on('attach', async device => {
148
+ const {
149
+ idVendor
150
+ } = device.deviceDescriptor;
151
+ if (idVendor == 1452) {
152
+ // 表示该机器为苹果产品,则不进行获取sn
153
+ return;
154
+ }
155
+ callBack({
156
+ data: {
157
+ eventName: _constants.EVENT_TYPE.USB_ANDROID_DEVICE_RESULT,
158
+ eventCode: 0
159
+ }
160
+ });
161
+ if ((0, _utils.isMac)()) {
162
+ // mac获取sn
163
+ getMacSn(device, callBack);
164
+ return;
165
+ }
166
+ if ((0, _utils.isWin)()) {
167
+ // win获取sn
168
+ getWinSn(device, callBack);
169
+ return;
170
+ }
171
+ });
172
+ _usb.usb.on('detach', () => {
173
+ callBack({
174
+ data: {
175
+ eventName: _constants.EVENT_TYPE.USB_DISCONNECT,
176
+ eventCode: 0
177
+ }
178
+ });
179
+ });
180
+ };
181
+ exports.registerGetAndroidSn = registerGetAndroidSn;
182
+ const unregisterGetAndroidSn = () => {
183
+ hadRegisterUsb = false;
184
+ _usb.usb.removeAllListeners('attach');
185
+ _usb.usb.removeAllListeners('detach');
186
+ };
187
+ exports.unregisterGetAndroidSn = unregisterGetAndroidSn;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getGeneralReport = getGeneralReport;
7
+ var _utils = require("../../utils/utils.common");
8
+ var _utils2 = require("../../utils/utils.ability");
9
+ var _workerPool = require("../../utils/workerPool");
10
+ let pool = null;
11
+ function getGeneralReport(params, callback, options = {}) {
12
+ const cb = typeof callback === 'function' ? callback : _utils2.defaultCallback;
13
+ const payload = (0, _utils.parsePayload)(params);
14
+ const {
15
+ maxPoolSize = _workerPool.DEFAULT_MAX_POOL_SIZE
16
+ } = options;
17
+ if (!pool || pool.maxPoolSize !== maxPoolSize) {
18
+ pool = new _workerPool.WorkerPool(__dirname, './worker.js', maxPoolSize);
19
+ }
20
+ pool.exec(payload, cb);
21
+ }
@@ -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,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getUltimateReport = getUltimateReport;
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 GetUltimateReport {
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
+
46
+ /**
47
+ * 获取终极报告
48
+ * @param {Object} params - 请求参数
49
+ * @param {string} params.udid - 设备 UDID
50
+ * @param {string} [params.simpleReportId] - 普通报告 ID,传空串时服务端不进行删除操作
51
+ * @param {Function} callback - 回调函数,接收报告结果
52
+ */
53
+ function getUltimateReport(params, callback) {
54
+ if (!entity) {
55
+ entity = new GetUltimateReport();
56
+ }
57
+ const payload = (0, _utils.parsePayload)(params);
58
+ entity.exec(payload, callback);
59
+ }
@@ -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('ultimate_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,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.skip = skip;
7
+ var _utils = require("../../utils/utils.common");
8
+ var _utils2 = require("../../utils/utils.ability");
9
+ var _workerPool = require("../../utils/workerPool");
10
+ let pool = null;
11
+ function skip(params, callback, options = {}) {
12
+ const payload = (0, _utils.parsePayload)(params);
13
+ const cb = typeof callback === 'function' ? callback : _utils2.defaultCallback;
14
+ const {
15
+ maxPoolSize = _workerPool.DEFAULT_MAX_POOL_SIZE
16
+ } = options;
17
+ if (!pool || pool.maxPoolSize !== maxPoolSize) {
18
+ pool = new _workerPool.WorkerPool(__dirname, './worker.js', maxPoolSize);
19
+ }
20
+ pool.exec(payload, cb);
21
+ }
@@ -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);
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.EVENT_TYPE = void 0;
7
+ const EVENT_TYPE = exports.EVENT_TYPE = {
8
+ /** iOS 设备 USB 插拔结果:eventCode 0 已插入,-1 已拔出 */
9
+ USB_DEVICE_RESULT: 'type_usb_device_result',
10
+ /** iOS 设备信任配对结果:eventCode 0 已信任 */
11
+ TRUST_RESULT: 'type_trust_result',
12
+ /** 检测到 dll 热更新:eventCode 0 需要更新,-1 不需要更新 */
13
+ NEED_UPDATE: 'type_need_update',
14
+ /** dll 热更新下载并写入结果:eventCode 0 成功,-1 失败 */
15
+ UPDATE_RESULT: 'type_update_result',
16
+ /** 需要安装 USB 驱动(仅 Windows),eventContent.percent 为下载进度 */
17
+ NEED_INSTALL_DRIVER: 'type_need_install_driver',
18
+ /** USB 驱动安装结果(仅 Windows):eventCode 0 成功,-1 失败 */
19
+ INSTALL_DRIVER_RESULT: 'type_install_driver_result',
20
+ /** Android 设备 USB 插入结果:eventCode 0 已插入 */
21
+ USB_ANDROID_DEVICE_RESULT: 'type_usb_android_device_result',
22
+ /** 获取 Android SN 结果:eventCode 0 成功,-1 失败;成功时 eventContent: { SN, brand } */
23
+ GET_ANDROID_SN_RESULT: 'type_get_android_sn_result',
24
+ /** 设备 USB 断开(iOS / Android):eventCode 0 已拔出 */
25
+ USB_DISCONNECT: 'type_usb_disconnect',
26
+ /** USB 监听发生错误:eventCode -1,eventContent.message 为错误信息 */
27
+ USB_ERROR: 'type_usb_error'
28
+ };