hunter-open-sdk 0.0.15 → 0.0.17
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,36 @@ 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
|
+
// 进度回调限流:进度变化超过5%时调用
|
|
174
|
+
var lastProgressPercent = 0;
|
|
175
|
+
var PROGRESS_THRESHOLD = 5; // 5%阈值
|
|
176
|
+
|
|
177
|
+
var throttledProgressCallback = function throttledProgressCallback(percent) {
|
|
178
|
+
var shouldCall = Math.abs(percent - lastProgressPercent) >= PROGRESS_THRESHOLD;
|
|
179
|
+
if (shouldCall && onProgress) {
|
|
180
|
+
onProgress(percent);
|
|
181
|
+
lastProgressPercent = percent;
|
|
182
|
+
console.log("\u4E0B\u8F7D\u8FDB\u5EA6: ".concat(percent, "% (").concat(received, "/").concat(total, ")"));
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
console.log('=== 开始创建request ===');
|
|
163
186
|
(0, _request.default)(url).on('response', function (response) {
|
|
164
187
|
console.log('下载响应状态:', response.statusCode);
|
|
165
188
|
if (response.statusCode !== 200) {
|
|
@@ -170,10 +193,9 @@ function downloadDriver(onProgress) {
|
|
|
170
193
|
console.log('文件总大小:', total, 'bytes');
|
|
171
194
|
}).on('data', function (chunk) {
|
|
172
195
|
received += chunk.length;
|
|
173
|
-
if (
|
|
196
|
+
if (total) {
|
|
174
197
|
var percent = Math.round(received / total * 100);
|
|
175
|
-
|
|
176
|
-
console.log("\u4E0B\u8F7D\u8FDB\u5EA6: ".concat(percent, "% (").concat(received, "/").concat(total, ")"));
|
|
198
|
+
throttledProgressCallback(percent);
|
|
177
199
|
}
|
|
178
200
|
}).on('error', function (err) {
|
|
179
201
|
console.error('驱动下载失败', err);
|
|
@@ -184,11 +206,18 @@ function downloadDriver(onProgress) {
|
|
|
184
206
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
185
207
|
while (1) switch (_context2.prev = _context2.next) {
|
|
186
208
|
case 0:
|
|
209
|
+
console.log('=== FINISH 事件被触发 ===');
|
|
187
210
|
console.log('文件下载完成,开始解压...');
|
|
188
|
-
|
|
189
|
-
|
|
211
|
+
|
|
212
|
+
// 确保最后一次进度回调被调用(100%)
|
|
213
|
+
if (onProgress && total) {
|
|
214
|
+
onProgress(100);
|
|
215
|
+
console.log('下载完成: 100%');
|
|
216
|
+
}
|
|
217
|
+
_context2.prev = 3;
|
|
218
|
+
_context2.next = 6;
|
|
190
219
|
return uncopressingFile(filePath);
|
|
191
|
-
case
|
|
220
|
+
case 6:
|
|
192
221
|
uncopressing = _context2.sent;
|
|
193
222
|
console.log('解压结果:', uncopressing);
|
|
194
223
|
if (uncopressing) {
|
|
@@ -204,18 +233,18 @@ function downloadDriver(onProgress) {
|
|
|
204
233
|
console.error('解压失败');
|
|
205
234
|
reject(new Error('解压失败'));
|
|
206
235
|
}
|
|
207
|
-
_context2.next =
|
|
236
|
+
_context2.next = 15;
|
|
208
237
|
break;
|
|
209
|
-
case
|
|
210
|
-
_context2.prev =
|
|
211
|
-
_context2.t0 = _context2["catch"](
|
|
238
|
+
case 11:
|
|
239
|
+
_context2.prev = 11;
|
|
240
|
+
_context2.t0 = _context2["catch"](3);
|
|
212
241
|
console.error('解压或安装过程中出错:', _context2.t0);
|
|
213
242
|
reject(_context2.t0);
|
|
214
|
-
case
|
|
243
|
+
case 15:
|
|
215
244
|
case "end":
|
|
216
245
|
return _context2.stop();
|
|
217
246
|
}
|
|
218
|
-
}, _callee2, null, [[
|
|
247
|
+
}, _callee2, null, [[3, 11]]);
|
|
219
248
|
}))).on('error', function (err) {
|
|
220
249
|
console.error('文件流写入错误:', err);
|
|
221
250
|
reject(err);
|