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
.native
.build

43
electron/build.js vendored
View File

@ -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, "/"))) {

25
electron/electron.js vendored
View File

@ -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)
})