From baf789c2daa56c741f416d4473d05491e0e76f0b Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sat, 3 Apr 2021 18:50:11 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=A2=9E=E9=87=8F=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/gui/src/background.js | 2 +- packages/gui/src/bridge/update/backend.js | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/gui/src/background.js b/packages/gui/src/background.js index 451d737..dec9ad6 100644 --- a/packages/gui/src/background.js +++ b/packages/gui/src/background.js @@ -210,7 +210,7 @@ if (!isFirstInstance) { } try { createWindow() - const context = { win, app, beforeQuit, quit, ipcMain, dialog, log } + const context = { win, app, beforeQuit, quit, ipcMain, dialog, log, api: DevSidecar.api } backend.install(context) // 模块安装 } catch (err) { log.info('err', err) diff --git a/packages/gui/src/bridge/update/backend.js b/packages/gui/src/bridge/update/backend.js index 9b65600..312b5b2 100644 --- a/packages/gui/src/bridge/update/backend.js +++ b/packages/gui/src/bridge/update/backend.js @@ -8,6 +8,7 @@ import fs from 'fs' import AdmZip from 'adm-zip' import logger from '../../utils/util.log' import appPathUtil from '../../utils/util.apppath' +import DevSidecar from '@docmirror/dev-sidecar' // eslint-disable-next-line no-unused-vars const isMac = process.platform === 'darwin' @@ -34,7 +35,7 @@ function downloadFile (uri, filePath, onProgress, onSuccess, onError) { } // 检测更新,在你想要检查更新的时候执行,renderer事件触发后的操作自行编写 -function updateHandle (app, win, beforeQuit, quit, log) { +function updateHandle (app, api, win, beforeQuit, quit, log) { // // 更新前,删除本地安装包 ↓ // const updaterCacheDirName = 'dev-sidecar-updater' // const updatePendingPath = path.join(autoUpdater.app.baseCachePath, updaterCacheDirName, 'pending') @@ -85,9 +86,14 @@ function updateHandle (app, win, beforeQuit, quit, log) { }) } - function updatePart (app, value, partPackagePath, quit) { + function updatePart (app, api, value, partPackagePath, quit) { const appPath = appPathUtil.getAppRootPath() - const target = path.join(appPath, 'resources') + const platform = api.shell.getSystemPlatform() + let target = path.join(appPath, 'resources') + if (platform === 'mac') { + target = path.join(appPath, 'Contents/Resources') + } + log.info('开始解压缩,安装升级包', partPackagePath, target) app.relaunch() // 解压缩 @@ -131,7 +137,7 @@ function updateHandle (app, win, beforeQuit, quit, log) { ipcMain.on('update', (e, arg) => { if (arg.key === 'doUpdateNow') { if (partPackagePath) { - updatePart(app, arg.value, partPackagePath) + updatePart(app, api, arg.value, partPackagePath) return } // some code here to handle event @@ -180,6 +186,6 @@ export default { // updateUrl = 'http://dev-sidecar.docmirror.cn/update/' // updateUrl = 'http://localhost/dev-sidecar/' } - updateHandle(app, win, beforeQuit, quit, log) + updateHandle(app, api, win, beforeQuit, quit, log) } }