From 178ac3c12b5668e902381ec0fd7d93fa772e53a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Tue, 23 Apr 2024 16:10:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E5=AE=B9=E4=BC=98=E5=8C=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/gui/src/bridge/update/backend.js | 22 +++++++------ packages/gui/src/bridge/update/front.js | 38 +++++++++++------------ 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/packages/gui/src/bridge/update/backend.js b/packages/gui/src/bridge/update/backend.js index f0e6195c..62e633d9 100644 --- a/packages/gui/src/bridge/update/backend.js +++ b/packages/gui/src/bridge/update/backend.js @@ -3,17 +3,16 @@ import { autoUpdater } from 'electron-updater' import path from 'path' import request from 'request' import progress from 'request-progress' -// win是所有窗口的引用 import fs from 'fs' import AdmZip from 'adm-zip' -import logger from '../../utils/util.log' +import log from '../../utils/util.log' import appPathUtil from '../../utils/util.apppath' // eslint-disable-next-line no-unused-vars const isMac = process.platform === 'darwin' const isLinux = process.platform === 'linux' function downloadFile (uri, filePath, onProgress, onSuccess, onError) { - logger.info('download url', uri) + log.info('download url', uri) progress(request(uri), { // throttle: 2000, // Throttle the progress event to 2000ms, defaults to 1000ms // delay: 1000, // Only start to emit after 1000ms delay, defaults to 0ms @@ -21,11 +20,11 @@ function downloadFile (uri, filePath, onProgress, onSuccess, onError) { }) .on('progress', function (state) { onProgress(state.percent * 100) - logger.log('progress', state.percent) + log.log('progress', state.percent) }) .on('error', function (err) { // Do something with err - logger.error('下载升级包失败', err) + log.error('下载升级包失败', err) onError(err) }) .on('end', function () { @@ -35,7 +34,11 @@ function downloadFile (uri, filePath, onProgress, onSuccess, onError) { .pipe(fs.createWriteStream(filePath)) } -// 检测更新,在你想要检查更新的时候执行,renderer事件触发后的操作自行编写 +/** + * 检测更新,在你想要检查更新的时候执行,renderer事件触发后的操作自行编写 + * + * @param win win是所有窗口的引用 + */ function updateHandle (app, api, win, beforeQuit, quit, log) { // // 更新前,删除本地安装包 ↓ // const updaterCacheDirName = 'dev-sidecar-updater' @@ -64,7 +67,7 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { } } - logger.info('auto updater', autoUpdater.getFeedURL()) + log.info('auto updater', autoUpdater.getFeedURL()) autoUpdater.autoDownload = false let partPackagePath = null @@ -72,7 +75,7 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { function downloadPart (app, value) { const appPath = appPathUtil.getAppRootPath(app) const fileDir = path.join(appPath, 'update') - logger.info('download dir', fileDir) + log.info('download dir:', fileDir) try { fs.accessSync(fileDir, fs.constants.F_OK) } catch (e) { @@ -85,7 +88,7 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { }, () => { // 文件下载完成 win.webContents.send('update', { key: 'progress', value: 100 }) - logger.info('升级包下载成功:', filePath) + log.info('升级包下载成功:', filePath) partPackagePath = filePath win.webContents.send('update', { key: 'downloaded', @@ -177,7 +180,6 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { } else if (arg.key === 'downloadPart') { // 下载增量更新版本 log.info('autoUpdater downloadPart') - // autoUpdater.downloadUpdate() downloadPart(app, arg.value) } }) diff --git a/packages/gui/src/bridge/update/front.js b/packages/gui/src/bridge/update/front.js index 0ba5e918..9f98dc23 100644 --- a/packages/gui/src/bridge/update/front.js +++ b/packages/gui/src/bridge/update/front.js @@ -10,7 +10,7 @@ function install (app, api) { if (fromUser != null) { updateParams.fromUser = fromUser } - api.ipc.send('update', { key: 'checkForUpdate' }) + api.ipc.send('update', { key: 'checkForUpdate', fromUser }) }, downloadUpdate () { api.ipc.send('update', { key: 'downloadUpdate' }) @@ -38,12 +38,13 @@ function install (app, api) { } else if (type === 'progress') { progressUpdate(message.value) } else if (type === 'error') { + updateParams.downloading = false const error = message.error - app.$message.error('Error: ' + (error == null ? '未知错误' : (error.stack || error).toString())) + app.$message.error((error == null ? '未知错误' : (error.stack || error).toString())) } } - function noNewVersion (value) { + function noNewVersion () { updateParams.newVersion = false if (updateParams.fromUser) { app.$message.info('当前已经是最新版本') @@ -55,6 +56,7 @@ function install (app, api) { } function goManualUpdate (value) { + updateParams.newVersion = false app.$confirm({ title: '暂不支持自动升级', cancelText: '取消', @@ -63,20 +65,14 @@ function install (app, api) { function openGithubUrl () { api.ipc.openExternal('https://github.com/docmirror/dev-sidecar/releases') } - return