diff --git a/src/i18n/lang/en-US/comp.ts b/src/i18n/lang/en-US/comp.ts index 5b1e574..29c0f37 100644 --- a/src/i18n/lang/en-US/comp.ts +++ b/src/i18n/lang/en-US/comp.ts @@ -39,7 +39,18 @@ export default { downloadFailed: 'Download failed, please try again or download manually', startFailed: 'Start download failed, please try again or download manually', noDownloadUrl: - 'No suitable installation package found for the current system, please download manually' + 'No suitable installation package found for the current system, please download manually', + installConfirmTitle: 'Install Update', + installConfirmContent: 'Do you want to close the application and install the update?', + manualInstallTip: + 'If the installer does not open automatically after closing the application, please find the file in your download folder and open it manually.', + yesInstall: 'Install Now', + noThanks: 'Later', + fileLocation: 'File Location', + copy: 'Copy Path', + copySuccess: 'Path copied to clipboard', + copyFailed: 'Copy failed', + backgroundDownload: 'Background Download' }, coffee: { title: 'Buy me a coffee', diff --git a/src/i18n/lang/zh-CN/comp.ts b/src/i18n/lang/zh-CN/comp.ts index 5dd6d9f..6290a5a 100644 --- a/src/i18n/lang/zh-CN/comp.ts +++ b/src/i18n/lang/zh-CN/comp.ts @@ -38,7 +38,17 @@ export default { nowUpdate: '立即更新', downloadFailed: '下载失败,请重试或手动下载', startFailed: '启动下载失败,请重试或手动下载', - noDownloadUrl: '未找到适合当前系统的安装包,请手动下载' + noDownloadUrl: '未找到适合当前系统的安装包,请手动下载', + installConfirmTitle: '安装更新', + installConfirmContent: '是否关闭应用并安装更新?', + manualInstallTip: '如果关闭应用后没有正常弹出安装程序,请至下载文件夹查找文件并手动打开。', + yesInstall: '立即安装', + noThanks: '稍后安装', + fileLocation: '文件位置', + copy: '复制路径', + copySuccess: '路径已复制到剪贴板', + copyFailed: '复制失败', + backgroundDownload: '后台下载' }, coffee: { title: '请我喝咖啡', diff --git a/src/main/modules/update.ts b/src/main/modules/update.ts index 7dfdefe..4f4f06f 100644 --- a/src/main/modules/update.ts +++ b/src/main/modules/update.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import { exec } from 'child_process'; +import { spawn } from 'child_process'; import { app, BrowserWindow, ipcMain } from 'electron'; import * as fs from 'fs'; import * as path from 'path'; @@ -53,38 +53,49 @@ export function setupUpdateHandlers(_mainWindow: BrowserWindow) { const { platform } = process; - // 关闭当前应用 - app.quit(); - - // 根据不同平台执行安装 - if (platform === 'win32') { - exec(`"${filePath}"`, (error) => { - if (error) { - console.error('Error starting installer:', error); - } - }); - } else if (platform === 'darwin') { - // 挂载 DMG 文件 - exec(`open "${filePath}"`, (error) => { - if (error) { - console.error('Error opening DMG:', error); - } - }); - } else if (platform === 'linux') { - const ext = path.extname(filePath); - if (ext === '.AppImage') { - exec(`chmod +x "${filePath}" && "${filePath}"`, (error) => { - if (error) { - console.error('Error running AppImage:', error); - } + // 先启动安装程序,再退出应用 + try { + if (platform === 'win32') { + // 使用spawn替代exec,并使用detached选项确保子进程独立运行 + const child = spawn(filePath, [], { + detached: true, + stdio: 'ignore' }); - } else if (ext === '.deb') { - exec(`pkexec dpkg -i "${filePath}"`, (error) => { - if (error) { - console.error('Error installing deb package:', error); - } + child.unref(); + } else if (platform === 'darwin') { + // 挂载 DMG 文件 + const child = spawn('open', [filePath], { + detached: true, + stdio: 'ignore' }); + child.unref(); + } else if (platform === 'linux') { + const ext = path.extname(filePath); + if (ext === '.AppImage') { + // 先添加执行权限 + fs.chmodSync(filePath, '755'); + const child = spawn(filePath, [], { + detached: true, + stdio: 'ignore' + }); + child.unref(); + } else if (ext === '.deb') { + const child = spawn('pkexec', ['dpkg', '-i', filePath], { + detached: true, + stdio: 'ignore' + }); + child.unref(); + } } + + // 给安装程序一点时间启动 + setTimeout(() => { + app.quit(); + }, 500); + } catch (error) { + console.error('启动安装程序失败:', error); + // 尽管出错,仍然尝试退出应用 + app.quit(); } }); } diff --git a/src/renderer/components/common/UpdateModal.vue b/src/renderer/components/common/UpdateModal.vue index 037f8d1..9416741 100644 --- a/src/renderer/components/common/UpdateModal.vue +++ b/src/renderer/components/common/UpdateModal.vue @@ -35,23 +35,22 @@
@@ -71,7 +70,7 @@