From e574e728d49d0b6e1fbd1e70aa6bd8376226f14a Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 14 Nov 2024 11:40:38 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/build.js | 1 + electron/electron.js | 15 +++++++++------ electron/package.json | 7 +++++++ resources/assets/js/components/RightBottom.vue | 4 +++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/electron/build.js b/electron/build.js index 5fa22bac0..f0ec95f23 100644 --- a/electron/build.js +++ b/electron/build.js @@ -293,6 +293,7 @@ function startBuild(data) { console.log("Notarize: " + (notarize ? 'Yes' : 'No')); // drawio cloneDrawio(systemInfo) + // todo: download updater } // language fse.copySync(path.resolve(__dirname, "../public/language"), path.resolve(electronDir, "language")) diff --git a/electron/electron.js b/electron/electron.js index 843c4cbbb..a202787fe 100644 --- a/electron/electron.js +++ b/electron/electron.js @@ -187,7 +187,7 @@ function createMainWindow() { /** * 创建更新程序子进程 */ -function createUpdaterWindow() { +function createUpdaterWindow(loadingTip) { // 检查平台是否支持 if (!['darwin', 'win32'].includes(process.platform)) { return; @@ -197,9 +197,9 @@ function createUpdaterWindow() { // 构建updater应用路径 let updaterPath; if (isWin) { - updaterPath = path.join(__dirname, 'updater', 'updater.exe'); + updaterPath = path.join(process.resourcesPath, '..', 'updater', 'updater.exe'); } else { - updaterPath = path.join(__dirname, 'updater', 'updater'); + updaterPath = path.join(process.resourcesPath, '..', 'updater', 'updater'); } // 检查updater应用是否存在 @@ -209,7 +209,7 @@ function createUpdaterWindow() { } // 创建锁文件 - fs.writeFileSync(updaterLockFile, '1'); + fs.writeFileSync(updaterLockFile, loadingTip || ''); // 启动子进程,传入锁文件路径作为第一个参数 const child = spawn(updaterPath, [updaterLockFile], { @@ -1271,7 +1271,10 @@ ipcMain.on('mainWindowActive', (event) => { /** * 退出并安装更新 */ -ipcMain.on('updateQuitAndInstall', (event) => { +ipcMain.on('updateQuitAndInstall', (event, args) => { + if (!utils.isJson(args)) { + args = {} + } event.returnValue = "ok" // 关闭所有子窗口 @@ -1281,7 +1284,7 @@ ipcMain.on('updateQuitAndInstall', (event) => { }) // 启动更新子窗口 - createUpdaterWindow() + createUpdaterWindow(args.loadingTip) // 退出并安装更新 setTimeout(_ => { diff --git a/electron/package.json b/electron/package.json index 6c08a00a5..905e65a16 100755 --- a/electron/package.json +++ b/electron/package.json @@ -77,6 +77,13 @@ "electron.js", "utils.js" ], + "extraFiles": [ + { + "from": "updater", + "to": "updater", + "filter": ["**/*"] + } + ], "npmRebuild": false, "publish": { "provider": "generic" diff --git a/resources/assets/js/components/RightBottom.vue b/resources/assets/js/components/RightBottom.vue index f9cb553ca..d1c059838 100644 --- a/resources/assets/js/components/RightBottom.vue +++ b/resources/assets/js/components/RightBottom.vue @@ -218,7 +218,9 @@ export default { updateQuitAndInstall() { this.updateIng = true setTimeout(() => { - this.$Electron.sendMessage('updateQuitAndInstall') + this.$Electron.sendMessage('updateQuitAndInstall', { + loadingTip: this.$L('正在安装更新,请稍候...') + }) }, 301) },