support change profile on tray menu

#126
This commit is contained in:
pompurin404 2024-09-18 21:15:55 +08:00
parent b72476952a
commit fe5ddcf0c2
No known key found for this signature in database
3 changed files with 30 additions and 0 deletions

View File

@ -2,6 +2,10 @@
- 1.2.x YAML覆写语法有所变动请更新后参考文档进行修改
### Features
- 支持托盘菜单切换订阅
### Bug Fixes
- 修复覆写更新后全局启用状态丢失的问题

View File

@ -1,6 +1,8 @@
import {
changeCurrentProfile,
getAppConfig,
getControledMihomoConfig,
getProfileConfig,
patchAppConfig,
patchControledMihomoConfig
} from '../config'
@ -75,6 +77,7 @@ const buildContextMenu = async (): Promise<Menu> => {
// 避免出错时无法创建托盘菜单
}
}
const { current, items = [] } = await getProfileConfig()
const contextMenu = [
{
@ -163,6 +166,24 @@ const buildContextMenu = async (): Promise<Menu> => {
},
...groupsMenu,
{ type: 'separator' },
{
type: 'submenu',
label: '订阅配置',
submenu: items.map((item) => {
return {
type: 'radio',
label: item.name,
checked: item.id === current,
click: async (): Promise<void> => {
if (item.id === current) return
await changeCurrentProfile(item.id)
mainWindow?.webContents.send('profileConfigUpdated')
ipcMain.emit('updateTrayMenu')
}
}
})
},
{ type: 'separator' },
{
type: 'submenu',
label: '打开目录',

View File

@ -33,6 +33,7 @@ export const ProfileConfigProvider: React.FC<{ children: ReactNode }> = ({ child
alert(e)
} finally {
mutateProfileConfig()
window.electron.ipcRenderer.send('updateTrayMenu')
}
}
@ -43,6 +44,7 @@ export const ProfileConfigProvider: React.FC<{ children: ReactNode }> = ({ child
alert(e)
} finally {
mutateProfileConfig()
window.electron.ipcRenderer.send('updateTrayMenu')
}
}
@ -53,6 +55,7 @@ export const ProfileConfigProvider: React.FC<{ children: ReactNode }> = ({ child
alert(e)
} finally {
mutateProfileConfig()
window.electron.ipcRenderer.send('updateTrayMenu')
}
}
@ -63,6 +66,7 @@ export const ProfileConfigProvider: React.FC<{ children: ReactNode }> = ({ child
alert(e)
} finally {
mutateProfileConfig()
window.electron.ipcRenderer.send('updateTrayMenu')
}
}
@ -73,6 +77,7 @@ export const ProfileConfigProvider: React.FC<{ children: ReactNode }> = ({ child
alert(e)
} finally {
mutateProfileConfig()
window.electron.ipcRenderer.send('updateTrayMenu')
}
}