Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
support change profile on tray menu
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Sep 18, 2024
1 parent 384f859 commit b4bcad6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

- 1.2.x YAML覆写语法有所变动,请更新后参考文档进行修改

### Features

- 支持托盘菜单切换订阅

### Bug Fixes

- 修复覆写更新后全局启用状态丢失的问题
21 changes: 21 additions & 0 deletions src/main/resolve/tray.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
changeCurrentProfile,
getAppConfig,
getControledMihomoConfig,
getProfileConfig,
patchAppConfig,
patchControledMihomoConfig
} from '../config'
Expand Down Expand Up @@ -75,6 +77,7 @@ const buildContextMenu = async (): Promise<Menu> => {
// 避免出错时无法创建托盘菜单
}
}
const { current, items = [] } = await getProfileConfig()

const contextMenu = [
{
Expand Down Expand Up @@ -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: '打开目录',
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/src/hooks/use-profile-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const ProfileConfigProvider: React.FC<{ children: ReactNode }> = ({ child
alert(e)
} finally {
mutateProfileConfig()
window.electron.ipcRenderer.send('updateTrayMenu')
}
}

Expand All @@ -43,6 +44,7 @@ export const ProfileConfigProvider: React.FC<{ children: ReactNode }> = ({ child
alert(e)
} finally {
mutateProfileConfig()
window.electron.ipcRenderer.send('updateTrayMenu')
}
}

Expand All @@ -53,6 +55,7 @@ export const ProfileConfigProvider: React.FC<{ children: ReactNode }> = ({ child
alert(e)
} finally {
mutateProfileConfig()
window.electron.ipcRenderer.send('updateTrayMenu')
}
}

Expand All @@ -63,6 +66,7 @@ export const ProfileConfigProvider: React.FC<{ children: ReactNode }> = ({ child
alert(e)
} finally {
mutateProfileConfig()
window.electron.ipcRenderer.send('updateTrayMenu')
}
}

Expand All @@ -73,6 +77,7 @@ export const ProfileConfigProvider: React.FC<{ children: ReactNode }> = ({ child
alert(e)
} finally {
mutateProfileConfig()
window.electron.ipcRenderer.send('updateTrayMenu')
}
}

Expand Down

0 comments on commit b4bcad6

Please sign in to comment.