no message

This commit is contained in:
kuaifan 2025-03-06 16:16:43 +08:00
parent b605c70e91
commit f54bad5d79
3 changed files with 52 additions and 17 deletions

1
electron/.gitignore vendored
View File

@ -10,3 +10,4 @@ cache/*
.devload .devload
.native .native
.build

43
electron/build.js vendored
View File

@ -695,6 +695,20 @@ if (["dev"].includes(argv[2])) {
}); });
} else { } 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 = [ const questions = [
{ {
type: 'checkbox', type: 'checkbox',
@ -710,6 +724,7 @@ if (["dev"].includes(argv[2])) {
value: platforms[1] value: platforms[1]
} }
], ],
default: (cachedConfig && cachedConfig.platform) || [],
validate: (answer) => { validate: (answer) => {
if (answer.length < 1) { if (answer.length < 1) {
return '请至少选择一个系统'; return '请至少选择一个系统';
@ -721,7 +736,7 @@ if (["dev"].includes(argv[2])) {
type: 'checkbox', type: 'checkbox',
name: 'arch', name: 'arch',
message: "选择系统架构", message: "选择系统架构",
choices: ({platform}) => { choices: ({ platform }) => {
const array = [ const array = [
{ {
name: "arm64", name: "arm64",
@ -740,6 +755,7 @@ if (["dev"].includes(argv[2])) {
} }
return array; return array;
}, },
default: (cachedConfig && cachedConfig.arch) || [],
validate: (answer) => { validate: (answer) => {
if (answer.length < 1) { if (answer.length < 1) {
return '请至少选择一个架构'; return '请至少选择一个架构';
@ -757,33 +773,39 @@ if (["dev"].includes(argv[2])) {
}, { }, {
name: "是", name: "是",
value: true value: true
}] }],
default: (cachedConfig && cachedConfig.publish !== undefined) ?
(cachedConfig.publish ? 1 : 0) : 0
}, },
{ {
type: 'list', type: 'list',
name: 'release', name: 'release',
message: "选择升级方式", message: "选择升级方式",
when: ({publish}) => publish, when: ({ publish }) => publish,
choices: [{ choices: [{
name: "弹出提示", name: "弹出提示",
value: true value: true
}, { }, {
name: "静默", name: "静默",
value: false value: false
}] }],
default: (cachedConfig && cachedConfig.release !== undefined) ?
(cachedConfig.release ? 0 : 1) : 0
}, },
{ {
type: 'list', type: 'list',
name: 'notarize', name: 'notarize',
message: ({platform}) => platform.length > 1 ? "选择是否公证仅MacOS" : "选择是否公证", message: ({ platform }) => platform.length > 1 ? "选择是否公证仅MacOS" : "选择是否公证",
when: ({platform}) => platform.find(item => item === 'build-mac'), when: ({ platform }) => platform.find(item => item === 'build-mac'),
choices: [{ choices: [{
name: "否", name: "否",
value: false value: false
}, { }, {
name: "是", name: "是",
value: true value: true
}] }],
default: (cachedConfig && cachedConfig.notarize !== undefined) ?
(cachedConfig.notarize ? 1 : 0) : 0
} }
]; ];
@ -796,6 +818,13 @@ if (["dev"].includes(argv[2])) {
notarize: false notarize: false
}, answers); }, 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 (answers.publish) {
if (!PUBLISH_KEY && (!GITHUB_TOKEN || !utils.strExists(GITHUB_REPOSITORY, "/"))) { if (!PUBLISH_KEY && (!GITHUB_TOKEN || !utils.strExists(GITHUB_REPOSITORY, "/"))) {

25
electron/electron.js vendored
View File

@ -1411,15 +1411,17 @@ ipcMain.handle('getStore', (event, args) => {
//================================================================ //================================================================
let autoUpdating = 0 let autoUpdating = 0
autoUpdater.logger = loger if (autoUpdater) {
autoUpdater.autoDownload = false autoUpdater.logger = loger
autoUpdater.autoInstallOnAppQuit = true autoUpdater.autoDownload = false
autoUpdater.on('update-available', info => { autoUpdater.autoInstallOnAppQuit = true
mainWindow.webContents.send("updateAvailable", info) autoUpdater.on('update-available', info => {
}) mainWindow.webContents.send("updateAvailable", info)
autoUpdater.on('update-downloaded', info => { })
mainWindow.webContents.send("updateDownloaded", 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()) { if (autoUpdating + 3600 > utils.dayjs().unix()) {
return // 限制1小时仅执行一次 return // 限制1小时仅执行一次
} }
if (!autoUpdater) {
return
}
if (args.provider) { if (args.provider) {
autoUpdater.setFeedURL(args) autoUpdater.setFeedURL(args)
} }
@ -1494,7 +1499,7 @@ ipcMain.on('updateQuitAndInstall', (event, args) => {
// 退出并安装更新 // 退出并安装更新
setTimeout(_ => { setTimeout(_ => {
mainWindow.hide() mainWindow.hide()
autoUpdater.quitAndInstall(true, true) autoUpdater?.quitAndInstall(true, true)
}, 600) }, 600)
}) })