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.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);
|
|
@@ -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
|
+
};
|
|
@@ -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
|
}
|
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.checkHasDriver = checkHasDriver;
|
|
8
7
|
exports.downloadDriver = downloadDriver;
|
|
9
|
-
var
|
|
10
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
|
-
var _utils = require("../../utils/utils");
|
|
8
|
+
var _utils = require("../../utils/utils.env");
|
|
13
9
|
var _request = _interopRequireDefault(require("request"));
|
|
14
10
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
12
|
// import { app } from 'electron'
|
|
16
13
|
// import { command } from '../../utils/utils.command'
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
const Sentry = require('@sentry/browser');
|
|
16
|
+
const sudo = require('sudo-prompt');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const fs = require('fs');
|
|
19
|
+
const childProcess = require('child_process');
|
|
20
|
+
const compressing = require('compressing');
|
|
21
|
+
const exec = childProcess.exec;
|
|
22
|
+
const options = {
|
|
26
23
|
name: 'Electron'
|
|
27
24
|
};
|
|
28
|
-
|
|
25
|
+
const AppleMobileDeviceService = 'AppleMobileDeviceService';
|
|
26
|
+
const AppleMobileDeviceProcess = 'AppleMobileDeviceProcess';
|
|
29
27
|
// const reddirPath = 'C:/Program Files (x86)/Common Files/Apple/Apple Application Support'
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
const cmdStr = process.platform === 'win32' ? 'tasklist' : 'ps aux';
|
|
29
|
+
const CACHE_PATH = (0, _utils.isDev)() ? path.join(process.cwd(), './cache') : path.join(process.resourcesPath, './cache');
|
|
30
|
+
const filePath = path.join(CACHE_PATH, './iTunesOL_Lite_64_12.10.0.7.zip');
|
|
33
31
|
|
|
34
32
|
// 确保缓存目录存在,避免后续写入流抛出 ENOENT
|
|
35
33
|
try {
|
|
@@ -38,8 +36,8 @@ try {
|
|
|
38
36
|
console.error('创建缓存目录失败:', e);
|
|
39
37
|
Sentry.captureException('创建缓存目录失败:' + JSON.stringify(e));
|
|
40
38
|
}
|
|
41
|
-
|
|
42
|
-
return new Promise(
|
|
39
|
+
const checkProcess = () => {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
43
41
|
exec(cmdStr, function (err, stdout, stderr) {
|
|
44
42
|
// console.log('stdout>>>', stdout)
|
|
45
43
|
console.log('stderr>>>', stderr);
|
|
@@ -47,12 +45,12 @@ var checkProcess = function checkProcess() {
|
|
|
47
45
|
return reject(err);
|
|
48
46
|
}
|
|
49
47
|
if (stdout) {
|
|
50
|
-
|
|
51
|
-
stdout.split('\n').filter(
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
let hasRroess = false;
|
|
49
|
+
stdout.split('\n').filter(line => {
|
|
50
|
+
let processMessage = line.trim().split(/\s+/);
|
|
51
|
+
let processName = processMessage[0];
|
|
54
52
|
// console.log('names.....', processName)
|
|
55
|
-
if (processName.indexOf(
|
|
53
|
+
if (processName.indexOf(AppleMobileDeviceService) > -1 || processName.indexOf(AppleMobileDeviceProcess) > -1) {
|
|
56
54
|
hasRroess = true;
|
|
57
55
|
}
|
|
58
56
|
});
|
|
@@ -69,8 +67,8 @@ var checkProcess = function checkProcess() {
|
|
|
69
67
|
// })
|
|
70
68
|
// }
|
|
71
69
|
|
|
72
|
-
|
|
73
|
-
return new Promise(
|
|
70
|
+
const checkCache = () => {
|
|
71
|
+
return new Promise(resolve => {
|
|
74
72
|
fs.readFile(filePath, function (err) {
|
|
75
73
|
resolve(err ? false : true);
|
|
76
74
|
});
|
|
@@ -78,54 +76,39 @@ var checkCache = function checkCache() {
|
|
|
78
76
|
};
|
|
79
77
|
|
|
80
78
|
// 轮询检测是否存在进程
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
let processCheckTimer = null;
|
|
80
|
+
const checkProcessTimer = () => {
|
|
83
81
|
// 清除之前的定时器
|
|
84
82
|
if (processCheckTimer) {
|
|
85
83
|
clearTimeout(processCheckTimer);
|
|
86
84
|
}
|
|
87
|
-
processCheckTimer = setTimeout(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
case 2:
|
|
95
|
-
hasDriver = _context.sent;
|
|
96
|
-
if (!hasDriver) {
|
|
97
|
-
_context.next = 6;
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
// 检测到驱动,清除定时器并返回
|
|
101
|
-
if (processCheckTimer) {
|
|
102
|
-
clearTimeout(processCheckTimer);
|
|
103
|
-
processCheckTimer = null;
|
|
104
|
-
}
|
|
105
|
-
return _context.abrupt("return");
|
|
106
|
-
case 6:
|
|
107
|
-
// 继续轮询检测
|
|
108
|
-
checkProcessTimer();
|
|
109
|
-
case 7:
|
|
110
|
-
case "end":
|
|
111
|
-
return _context.stop();
|
|
85
|
+
processCheckTimer = setTimeout(async () => {
|
|
86
|
+
let hasDriver = await checkProcess();
|
|
87
|
+
if (hasDriver) {
|
|
88
|
+
// 检测到驱动,清除定时器并返回
|
|
89
|
+
if (processCheckTimer) {
|
|
90
|
+
clearTimeout(processCheckTimer);
|
|
91
|
+
processCheckTimer = null;
|
|
112
92
|
}
|
|
113
|
-
|
|
114
|
-
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
// 继续轮询检测
|
|
96
|
+
checkProcessTimer();
|
|
97
|
+
}, 1000);
|
|
115
98
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
99
|
+
const installDriver = () => {
|
|
100
|
+
const AppleApplicationSupport = path.join(CACHE_PATH, './AppleApplicationSupport.msi');
|
|
101
|
+
const AppleApplicationSupport64 = path.join(CACHE_PATH, './AppleApplicationSupport64.msi');
|
|
102
|
+
const AppleMobileDeviceSupport64 = path.join(CACHE_PATH, './AppleMobileDeviceSupport64.msi');
|
|
103
|
+
const Bonjour64 = path.join(CACHE_PATH, './Bonjour64.msi');
|
|
104
|
+
const cmdStr = `start /i /wait ${AppleApplicationSupport} /qn && start /i /wait ${AppleApplicationSupport64} /qn && start /i /wait ${AppleMobileDeviceSupport64} /qn && start /i /wait ${Bonjour64} /qn`;
|
|
122
105
|
console.log('开始安装驱动,命令:', cmdStr);
|
|
123
106
|
console.log('检查安装文件是否存在:');
|
|
124
107
|
console.log('AppleApplicationSupport:', fs.existsSync(AppleApplicationSupport));
|
|
125
108
|
console.log('AppleApplicationSupport64:', fs.existsSync(AppleApplicationSupport64));
|
|
126
109
|
console.log('AppleMobileDeviceSupport64:', fs.existsSync(AppleMobileDeviceSupport64));
|
|
127
110
|
console.log('Bonjour64:', fs.existsSync(Bonjour64));
|
|
128
|
-
return new Promise(
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
129
112
|
sudo.exec(cmdStr, options, function (error, stdout, stderr) {
|
|
130
113
|
console.log('安装 error>>', error);
|
|
131
114
|
console.log('安装 stdout>>>', stdout);
|
|
@@ -143,13 +126,13 @@ var installDriver = function installDriver() {
|
|
|
143
126
|
});
|
|
144
127
|
};
|
|
145
128
|
// 解压文件
|
|
146
|
-
|
|
147
|
-
return new Promise(
|
|
129
|
+
const uncopressingFile = filePath => {
|
|
130
|
+
return new Promise(resolve => {
|
|
148
131
|
console.log('开始解压文件:', filePath);
|
|
149
|
-
compressing.zip.uncompress(filePath, CACHE_PATH).then(
|
|
132
|
+
compressing.zip.uncompress(filePath, CACHE_PATH).then(() => {
|
|
150
133
|
console.log('文件解压成功');
|
|
151
134
|
resolve(true);
|
|
152
|
-
}).catch(
|
|
135
|
+
}).catch(err => {
|
|
153
136
|
console.error('文件解压失败:', err);
|
|
154
137
|
Sentry.captureException('文件解压失败:' + JSON.stringify(err));
|
|
155
138
|
resolve(false);
|
|
@@ -160,165 +143,116 @@ var uncopressingFile = function uncopressingFile(filePath) {
|
|
|
160
143
|
// Promise 版本的 downloadDriver,onProgress 作为参数,成功 resolve,失败 reject
|
|
161
144
|
function downloadDriver(onProgress) {
|
|
162
145
|
console.log('=== downloadDriver 函数被调用 ===');
|
|
163
|
-
console.log('onProgress 参数:',
|
|
164
|
-
return new Promise(
|
|
146
|
+
console.log('onProgress 参数:', typeof onProgress);
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
165
148
|
console.log('=== 开始创建Promise ===');
|
|
166
|
-
|
|
167
|
-
|
|
149
|
+
const url = 'http://ljtools.zhuanstatic.com/download/iTunesDriver/iTunesOL_Lite_64_12.10.0.7.zip';
|
|
150
|
+
const dest = filePath;
|
|
168
151
|
console.log('开始下载驱动文件:', url);
|
|
169
152
|
console.log('目标路径:', dest);
|
|
170
153
|
|
|
171
154
|
// 检查目标目录是否存在
|
|
172
|
-
|
|
155
|
+
const destDir = path.dirname(dest);
|
|
173
156
|
console.log('目标目录:', destDir);
|
|
174
157
|
console.log('目录是否存在:', fs.existsSync(destDir));
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
158
|
+
const fileStream = _fsExtra.default.createWriteStream(dest);
|
|
159
|
+
let received = 0;
|
|
160
|
+
let total = 0;
|
|
178
161
|
|
|
179
162
|
// 进度回调限流:进度变化超过5%时调用
|
|
180
|
-
|
|
181
|
-
|
|
163
|
+
let lastProgressPercent = 0;
|
|
164
|
+
const PROGRESS_THRESHOLD = 5; // 5%阈值
|
|
182
165
|
|
|
183
|
-
|
|
184
|
-
|
|
166
|
+
const throttledProgressCallback = percent => {
|
|
167
|
+
const shouldCall = Math.abs(percent - lastProgressPercent) >= PROGRESS_THRESHOLD;
|
|
185
168
|
if (shouldCall && onProgress) {
|
|
186
169
|
onProgress(percent);
|
|
187
170
|
lastProgressPercent = percent;
|
|
188
|
-
console.log(
|
|
171
|
+
console.log(`下载进度: ${percent}% (${received}/${total})`);
|
|
189
172
|
}
|
|
190
173
|
};
|
|
191
174
|
console.log('=== 开始创建request ===');
|
|
192
|
-
(0, _request.default)(url).on('response',
|
|
175
|
+
(0, _request.default)(url).on('response', response => {
|
|
193
176
|
console.log('下载响应状态:', response.statusCode);
|
|
194
177
|
if (response.statusCode !== 200) {
|
|
195
|
-
reject(new Error(
|
|
178
|
+
reject(new Error(`下载失败: ${response.statusMessage}`));
|
|
196
179
|
return;
|
|
197
180
|
}
|
|
198
181
|
total = parseInt(response.headers['content-length'], 10);
|
|
199
182
|
console.log('文件总大小:', total, 'bytes');
|
|
200
|
-
}).on('data',
|
|
183
|
+
}).on('data', chunk => {
|
|
201
184
|
received += chunk.length;
|
|
202
185
|
if (total) {
|
|
203
|
-
|
|
186
|
+
const percent = Math.round(received / total * 100);
|
|
204
187
|
throttledProgressCallback(percent);
|
|
205
188
|
}
|
|
206
|
-
}).on('error',
|
|
189
|
+
}).on('error', err => {
|
|
207
190
|
console.error('驱动下载失败', err);
|
|
208
191
|
Sentry.captureException('驱动下载失败:' + JSON.stringify(err));
|
|
209
192
|
fileStream.end(); // 确保关闭文件流
|
|
210
193
|
reject(err);
|
|
211
|
-
}).pipe(fileStream).once('close',
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
215
|
-
case 0:
|
|
216
|
-
console.log('=== CLOSE 事件被触发 ===');
|
|
217
|
-
console.log('文件下载完成,开始解压...');
|
|
194
|
+
}).pipe(fileStream).once('close', async () => {
|
|
195
|
+
console.log('=== CLOSE 事件被触发 ===');
|
|
196
|
+
console.log('文件下载完成,开始解压...');
|
|
218
197
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
Sentry.captureException('解压失败');
|
|
243
|
-
reject(new Error('解压失败'));
|
|
244
|
-
}
|
|
245
|
-
_context2.next = 16;
|
|
246
|
-
break;
|
|
247
|
-
case 11:
|
|
248
|
-
_context2.prev = 11;
|
|
249
|
-
_context2.t0 = _context2["catch"](3);
|
|
250
|
-
console.error('解压或安装过程中出错:', _context2.t0);
|
|
251
|
-
Sentry.captureException('解压或安装过程中出错:' + JSON.stringify(_context2.t0));
|
|
252
|
-
reject(_context2.t0);
|
|
253
|
-
case 16:
|
|
254
|
-
case "end":
|
|
255
|
-
return _context2.stop();
|
|
198
|
+
// 确保最后一次进度回调被调用(100%)
|
|
199
|
+
if (onProgress && total) {
|
|
200
|
+
onProgress(100);
|
|
201
|
+
console.log('下载完成: 100%');
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
// 下载完成后解压并安装
|
|
205
|
+
const uncopressing = await uncopressingFile(filePath);
|
|
206
|
+
console.log('解压结果:', uncopressing);
|
|
207
|
+
if (uncopressing) {
|
|
208
|
+
console.log('开始安装驱动...');
|
|
209
|
+
installDriver().then(() => {
|
|
210
|
+
console.log('驱动安装成功');
|
|
211
|
+
resolve();
|
|
212
|
+
}).catch(err => {
|
|
213
|
+
console.error('驱动安装失败:', err);
|
|
214
|
+
Sentry.captureException('驱动安装失败:' + JSON.stringify(err));
|
|
215
|
+
reject(err);
|
|
216
|
+
});
|
|
217
|
+
} else {
|
|
218
|
+
console.error('解压失败');
|
|
219
|
+
Sentry.captureException('解压失败');
|
|
220
|
+
reject(new Error('解压失败'));
|
|
256
221
|
}
|
|
257
|
-
}
|
|
258
|
-
|
|
222
|
+
} catch (err) {
|
|
223
|
+
console.error('解压或安装过程中出错:', err);
|
|
224
|
+
Sentry.captureException('解压或安装过程中出错:' + JSON.stringify(err));
|
|
225
|
+
reject(err);
|
|
226
|
+
}
|
|
227
|
+
}).once('error', err => {
|
|
259
228
|
console.error('文件流写入错误:', err);
|
|
260
229
|
Sentry.captureException('文件流写入错误:' + JSON.stringify(err));
|
|
261
230
|
reject(err);
|
|
262
231
|
});
|
|
263
232
|
});
|
|
264
233
|
}
|
|
265
|
-
function checkHasDriver() {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return checkCache();
|
|
290
|
-
case 10:
|
|
291
|
-
if (!_context3.sent) {
|
|
292
|
-
_context3.next = 14;
|
|
293
|
-
break;
|
|
294
|
-
}
|
|
295
|
-
_context3.t1 = 2;
|
|
296
|
-
_context3.next = 15;
|
|
297
|
-
break;
|
|
298
|
-
case 14:
|
|
299
|
-
_context3.t1 = 0;
|
|
300
|
-
case 15:
|
|
301
|
-
hasCache = _context3.t1;
|
|
302
|
-
state = hasDriver + hasCache;
|
|
303
|
-
_context3.t2 = state;
|
|
304
|
-
_context3.next = _context3.t2 === 3 ? 20 : _context3.t2 === 1 ? 20 : _context3.t2 === 2 ? 21 : 26;
|
|
305
|
-
break;
|
|
306
|
-
case 20:
|
|
307
|
-
return _context3.abrupt("return", true);
|
|
308
|
-
case 21:
|
|
309
|
-
_context3.next = 23;
|
|
310
|
-
return uncopressingFile(filePath);
|
|
311
|
-
case 23:
|
|
312
|
-
uncopressing = _context3.sent;
|
|
313
|
-
if (uncopressing) installDriver();
|
|
314
|
-
return _context3.abrupt("return", true);
|
|
315
|
-
case 26:
|
|
316
|
-
return _context3.abrupt("return", false);
|
|
317
|
-
case 27:
|
|
318
|
-
case "end":
|
|
319
|
-
return _context3.stop();
|
|
320
|
-
}
|
|
321
|
-
}, _callee3);
|
|
322
|
-
}));
|
|
323
|
-
return _checkHasDriver.apply(this, arguments);
|
|
234
|
+
async function checkHasDriver() {
|
|
235
|
+
// 是否存在驱动进程
|
|
236
|
+
const hasDriver = (await checkProcess()) ? 1 : 0;
|
|
237
|
+
// 是否存在安装包
|
|
238
|
+
const hasCache = (await checkCache()) ? 2 : 0;
|
|
239
|
+
const state = hasDriver + hasCache;
|
|
240
|
+
switch (state) {
|
|
241
|
+
// 存在驱动进程 + 存在安装包
|
|
242
|
+
case 3:
|
|
243
|
+
|
|
244
|
+
// 仅存在驱动进程
|
|
245
|
+
case 1:
|
|
246
|
+
return true;
|
|
247
|
+
|
|
248
|
+
// 仅存在安装包 进行解压安装
|
|
249
|
+
case 2:
|
|
250
|
+
const uncopressing = await uncopressingFile(filePath);
|
|
251
|
+
if (uncopressing) await installDriver();
|
|
252
|
+
return true;
|
|
253
|
+
|
|
254
|
+
// state = 0,
|
|
255
|
+
default:
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
324
258
|
}
|
|
@@ -1,45 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.deviceHelper = void 0;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var DeviceHelper = /*#__PURE__*/function () {
|
|
11
|
-
function DeviceHelper() {
|
|
12
|
-
(0, _classCallCheck2.default)(this, DeviceHelper);
|
|
7
|
+
class DeviceHelper {
|
|
8
|
+
constructor() {
|
|
13
9
|
this.udidList = [];
|
|
14
10
|
}
|
|
15
|
-
(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}, {
|
|
33
|
-
key: "hasUdid",
|
|
34
|
-
value: function hasUdid(udid) {
|
|
35
|
-
return this.udidList.includes(udid);
|
|
36
|
-
}
|
|
37
|
-
}, {
|
|
38
|
-
key: "clearUdidList",
|
|
39
|
-
value: function clearUdidList() {
|
|
40
|
-
this.udidList = [];
|
|
41
|
-
}
|
|
42
|
-
}]);
|
|
43
|
-
return DeviceHelper;
|
|
44
|
-
}();
|
|
45
|
-
var deviceHelper = exports.deviceHelper = new DeviceHelper();
|
|
11
|
+
addUdid(udid) {
|
|
12
|
+
this.udidList.push(udid);
|
|
13
|
+
}
|
|
14
|
+
getUdidList() {
|
|
15
|
+
return this.udidList;
|
|
16
|
+
}
|
|
17
|
+
removeUdid(udid) {
|
|
18
|
+
this.udidList = this.udidList.filter(item => item !== udid);
|
|
19
|
+
}
|
|
20
|
+
hasUdid(udid) {
|
|
21
|
+
return this.udidList.includes(udid);
|
|
22
|
+
}
|
|
23
|
+
clearUdidList() {
|
|
24
|
+
this.udidList = [];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const deviceHelper = exports.deviceHelper = new DeviceHelper();
|