hunter-open-sdk 0.0.15 → 0.0.16
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.
|
@@ -36,7 +36,17 @@ var Service = /*#__PURE__*/function () {
|
|
|
36
36
|
mainWindow.webContents.send("checkDriver", true);
|
|
37
37
|
} else {
|
|
38
38
|
mainWindow.webContents.send("checkDriver", false);
|
|
39
|
-
|
|
39
|
+
// 修复:传入正确的进度回调函数
|
|
40
|
+
(0, _winDriver.downloadDriver)(function (percent) {
|
|
41
|
+
console.log('下载进度:', percent + '%');
|
|
42
|
+
mainWindow.webContents.send("downloadProgress", percent);
|
|
43
|
+
}).then(function () {
|
|
44
|
+
console.log('驱动下载安装成功');
|
|
45
|
+
mainWindow.webContents.send("checkDriver", true);
|
|
46
|
+
}).catch(function (err) {
|
|
47
|
+
console.error('驱动下载安装失败:', err);
|
|
48
|
+
mainWindow.webContents.send("checkDriver", false);
|
|
49
|
+
});
|
|
40
50
|
}
|
|
41
51
|
});
|
|
42
52
|
}
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.checkHasDriver = checkHasDriver;
|
|
8
8
|
exports.downloadDriver = downloadDriver;
|
|
9
9
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
10
11
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
12
|
var _utils = require("../../utils/utils");
|
|
12
13
|
var _utils2 = require("../../utils/utils.command");
|
|
@@ -152,14 +153,40 @@ var uncopressingFile = function uncopressingFile(filePath) {
|
|
|
152
153
|
|
|
153
154
|
// Promise 版本的 downloadDriver,onProgress 作为参数,成功 resolve,失败 reject
|
|
154
155
|
function downloadDriver(onProgress) {
|
|
156
|
+
console.log('=== downloadDriver 函数被调用 ===');
|
|
157
|
+
console.log('onProgress 参数:', (0, _typeof2.default)(onProgress));
|
|
155
158
|
return new Promise(function (resolve, reject) {
|
|
159
|
+
console.log('=== 开始创建Promise ===');
|
|
156
160
|
var url = 'http://ljtools.zhuanstatic.com/download/iTunesDriver/iTunesOL_Lite_64_12.10.0.7.zip';
|
|
157
161
|
var dest = filePath;
|
|
158
162
|
console.log('开始下载驱动文件:', url);
|
|
159
163
|
console.log('目标路径:', dest);
|
|
164
|
+
|
|
165
|
+
// 检查目标目录是否存在
|
|
166
|
+
var destDir = path.dirname(dest);
|
|
167
|
+
console.log('目标目录:', destDir);
|
|
168
|
+
console.log('目录是否存在:', fs.existsSync(destDir));
|
|
160
169
|
var fileStream = _fsExtra.default.createWriteStream(dest);
|
|
161
170
|
var received = 0;
|
|
162
171
|
var total = 0;
|
|
172
|
+
|
|
173
|
+
// 进度回调限流:每100ms最多调用一次,或者进度变化超过5%时调用
|
|
174
|
+
var lastProgressCall = 0;
|
|
175
|
+
var lastProgressPercent = 0;
|
|
176
|
+
var PROGRESS_THROTTLE_MS = 100; // 100ms限流
|
|
177
|
+
var PROGRESS_THRESHOLD = 5; // 5%阈值
|
|
178
|
+
|
|
179
|
+
var throttledProgressCallback = function throttledProgressCallback(percent) {
|
|
180
|
+
var now = Date.now();
|
|
181
|
+
var shouldCall = now - lastProgressCall >= PROGRESS_THROTTLE_MS || Math.abs(percent - lastProgressPercent) >= PROGRESS_THRESHOLD;
|
|
182
|
+
if (shouldCall && onProgress) {
|
|
183
|
+
onProgress(percent);
|
|
184
|
+
lastProgressCall = now;
|
|
185
|
+
lastProgressPercent = percent;
|
|
186
|
+
console.log("\u4E0B\u8F7D\u8FDB\u5EA6: ".concat(percent, "% (").concat(received, "/").concat(total, ")"));
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
console.log('=== 开始创建request ===');
|
|
163
190
|
(0, _request.default)(url).on('response', function (response) {
|
|
164
191
|
console.log('下载响应状态:', response.statusCode);
|
|
165
192
|
if (response.statusCode !== 200) {
|
|
@@ -170,10 +197,9 @@ function downloadDriver(onProgress) {
|
|
|
170
197
|
console.log('文件总大小:', total, 'bytes');
|
|
171
198
|
}).on('data', function (chunk) {
|
|
172
199
|
received += chunk.length;
|
|
173
|
-
if (
|
|
200
|
+
if (total) {
|
|
174
201
|
var percent = Math.round(received / total * 100);
|
|
175
|
-
|
|
176
|
-
console.log("\u4E0B\u8F7D\u8FDB\u5EA6: ".concat(percent, "% (").concat(received, "/").concat(total, ")"));
|
|
202
|
+
throttledProgressCallback(percent);
|
|
177
203
|
}
|
|
178
204
|
}).on('error', function (err) {
|
|
179
205
|
console.error('驱动下载失败', err);
|
|
@@ -184,11 +210,18 @@ function downloadDriver(onProgress) {
|
|
|
184
210
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
185
211
|
while (1) switch (_context2.prev = _context2.next) {
|
|
186
212
|
case 0:
|
|
213
|
+
console.log('=== FINISH 事件被触发 ===');
|
|
187
214
|
console.log('文件下载完成,开始解压...');
|
|
188
|
-
|
|
189
|
-
|
|
215
|
+
|
|
216
|
+
// 确保最后一次进度回调被调用(100%)
|
|
217
|
+
if (onProgress && total) {
|
|
218
|
+
onProgress(100);
|
|
219
|
+
console.log('下载完成: 100%');
|
|
220
|
+
}
|
|
221
|
+
_context2.prev = 3;
|
|
222
|
+
_context2.next = 6;
|
|
190
223
|
return uncopressingFile(filePath);
|
|
191
|
-
case
|
|
224
|
+
case 6:
|
|
192
225
|
uncopressing = _context2.sent;
|
|
193
226
|
console.log('解压结果:', uncopressing);
|
|
194
227
|
if (uncopressing) {
|
|
@@ -204,18 +237,18 @@ function downloadDriver(onProgress) {
|
|
|
204
237
|
console.error('解压失败');
|
|
205
238
|
reject(new Error('解压失败'));
|
|
206
239
|
}
|
|
207
|
-
_context2.next =
|
|
240
|
+
_context2.next = 15;
|
|
208
241
|
break;
|
|
209
|
-
case
|
|
210
|
-
_context2.prev =
|
|
211
|
-
_context2.t0 = _context2["catch"](
|
|
242
|
+
case 11:
|
|
243
|
+
_context2.prev = 11;
|
|
244
|
+
_context2.t0 = _context2["catch"](3);
|
|
212
245
|
console.error('解压或安装过程中出错:', _context2.t0);
|
|
213
246
|
reject(_context2.t0);
|
|
214
|
-
case
|
|
247
|
+
case 15:
|
|
215
248
|
case "end":
|
|
216
249
|
return _context2.stop();
|
|
217
250
|
}
|
|
218
|
-
}, _callee2, null, [[
|
|
251
|
+
}, _callee2, null, [[3, 11]]);
|
|
219
252
|
}))).on('error', function (err) {
|
|
220
253
|
console.error('文件流写入错误:', err);
|
|
221
254
|
reject(err);
|