From f54bad5d79da59f6cea38d774eb073b8bff03c26 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 6 Mar 2025 16:16:43 +0800 Subject: [PATCH] no message --- electron/.gitignore | 1 + electron/build.js | 43 ++++++++++++++++++++++++++++++++++++------- electron/electron.js | 25 +++++++++++++++---------- 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/electron/.gitignore b/electron/.gitignore index 2e2add236..ad0eee747 100644 --- a/electron/.gitignore +++ b/electron/.gitignore @@ -10,3 +10,4 @@ cache/* .devload .native +.build \ No newline at end of file diff --git a/electron/build.js b/electron/build.js index 276c1d1e7..934935fb0 100644 --- a/electron/build.js +++ b/electron/build.js @@ -695,6 +695,20 @@ if (["dev"].includes(argv[2])) { }); } else { // 手编译(默认) + + let cachedConfig = {}; + try { + const buildConfigPath = path.join(__dirname, '.build'); + if (fs.existsSync(buildConfigPath)) { + const configContent = fs.readFileSync(buildConfigPath, 'utf-8'); + if (configContent.trim()) { + cachedConfig = JSON.parse(configContent); + } + } + } catch (error) { + console.warn('读取缓存配置失败:', error.message); + } + const questions = [ { type: 'checkbox', @@ -710,6 +724,7 @@ if (["dev"].includes(argv[2])) { value: platforms[1] } ], + default: (cachedConfig && cachedConfig.platform) || [], validate: (answer) => { if (answer.length < 1) { return '请至少选择一个系统'; @@ -721,7 +736,7 @@ if (["dev"].includes(argv[2])) { type: 'checkbox', name: 'arch', message: "选择系统架构", - choices: ({platform}) => { + choices: ({ platform }) => { const array = [ { name: "arm64", @@ -740,6 +755,7 @@ if (["dev"].includes(argv[2])) { } return array; }, + default: (cachedConfig && cachedConfig.arch) || [], validate: (answer) => { if (answer.length < 1) { return '请至少选择一个架构'; @@ -757,33 +773,39 @@ if (["dev"].includes(argv[2])) { }, { name: "是", value: true - }] + }], + default: (cachedConfig && cachedConfig.publish !== undefined) ? + (cachedConfig.publish ? 1 : 0) : 0 }, { type: 'list', name: 'release', message: "选择升级方式", - when: ({publish}) => publish, + when: ({ publish }) => publish, choices: [{ name: "弹出提示", value: true }, { name: "静默", value: false - }] + }], + default: (cachedConfig && cachedConfig.release !== undefined) ? + (cachedConfig.release ? 0 : 1) : 0 }, { type: 'list', name: 'notarize', - message: ({platform}) => platform.length > 1 ? "选择是否公证(仅MacOS)" : "选择是否公证", - when: ({platform}) => platform.find(item => item === 'build-mac'), + message: ({ platform }) => platform.length > 1 ? "选择是否公证(仅MacOS)" : "选择是否公证", + when: ({ platform }) => platform.find(item => item === 'build-mac'), choices: [{ name: "否", value: false }, { name: "是", value: true - }] + }], + default: (cachedConfig && cachedConfig.notarize !== undefined) ? + (cachedConfig.notarize ? 1 : 0) : 0 } ]; @@ -796,6 +818,13 @@ if (["dev"].includes(argv[2])) { notarize: false }, answers); + // 缓存当前配置 + try { + fs.writeFileSync(path.join(__dirname, '.build'), JSON.stringify(answers, null, 4), 'utf-8'); + } catch (error) { + console.warn('保存配置缓存失败:', error.message); + } + // 发布判断环境变量 if (answers.publish) { if (!PUBLISH_KEY && (!GITHUB_TOKEN || !utils.strExists(GITHUB_REPOSITORY, "/"))) { diff --git a/electron/electron.js b/electron/electron.js index 9b18510f3..a9845df8a 100644 --- a/electron/electron.js +++ b/electron/electron.js @@ -1411,15 +1411,17 @@ ipcMain.handle('getStore', (event, args) => { //================================================================ let autoUpdating = 0 -autoUpdater.logger = loger -autoUpdater.autoDownload = false -autoUpdater.autoInstallOnAppQuit = true -autoUpdater.on('update-available', info => { - mainWindow.webContents.send("updateAvailable", info) -}) -autoUpdater.on('update-downloaded', info => { - mainWindow.webContents.send("updateDownloaded", info) -}) +if (autoUpdater) { + autoUpdater.logger = loger + autoUpdater.autoDownload = false + autoUpdater.autoInstallOnAppQuit = true + autoUpdater.on('update-available', info => { + mainWindow.webContents.send("updateAvailable", info) + }) + autoUpdater.on('update-downloaded', info => { + mainWindow.webContents.send("updateDownloaded", info) + }) +} /** * 检查更新 @@ -1429,6 +1431,9 @@ ipcMain.on('updateCheckAndDownload', (event, args) => { if (autoUpdating + 3600 > utils.dayjs().unix()) { return // 限制1小时仅执行一次 } + if (!autoUpdater) { + return + } if (args.provider) { autoUpdater.setFeedURL(args) } @@ -1494,7 +1499,7 @@ ipcMain.on('updateQuitAndInstall', (event, args) => { // 退出并安装更新 setTimeout(_ => { mainWindow.hide() - autoUpdater.quitAndInstall(true, true) + autoUpdater?.quitAndInstall(true, true) }, 600) })