Skip to content

Commit d890197

Browse files
✨ 手动触发更新
1 parent 429a063 commit d890197

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

menu.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { fileURLToPath } from 'url'
33
import path from 'path'
44
import { readFile } from 'fs/promises'
55

6+
import { update } from './updater.js'
7+
68
const __dirname = fileURLToPath(new URL('.', import.meta.url))
79

810
const packagePath = path.join(__dirname, 'package.json')
@@ -37,8 +39,20 @@ app.whenReady().then(() => {
3739
// 克隆原有菜单结构(支持嵌套)
3840
const newTemplate = applicationMenu.items.map(convertMenuItem)
3941

40-
// 查找 Help 菜单:中英文适配
41-
const helpMenu = newTemplate.find((item) => item.label === 'Help' || item.label === '帮助')
42+
// 查找 appmenu 菜单
43+
const appmenuMenu = newTemplate.find((item) => item.role === 'appmenu')
44+
const aboutIndex = appmenuMenu.submenu.findIndex((item) => item.role === 'about')
45+
if (aboutIndex !== -1) {
46+
appmenuMenu.submenu.splice(aboutIndex + 1, 0, {
47+
label: 'Check for Updates',
48+
click: function () {
49+
update()
50+
},
51+
})
52+
}
53+
54+
// 查找 help 菜单
55+
const helpMenu = newTemplate.find((item) => item.role === 'help')
4256

4357
if (helpMenu) {
4458
// 初始化 submenu 数组(如果不存在)

updater.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ app.on('ready', function () {
3636
logUpdater.info('UpdateCheckResult.updateInfo:\n', updateCheckResult.updateInfo)
3737
})
3838
})
39+
40+
export const update = function () {
41+
electronUpdater.autoUpdater.checkForUpdates().then((resp) => {
42+
logUpdater.info('手动触发更新菜单结果', resp)
43+
})
44+
}

0 commit comments

Comments
 (0)