mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
fix tray crash on linux
This commit is contained in:
parent
940bed5401
commit
469e9d2818
@ -1,5 +1,3 @@
|
|||||||
### New Features
|
### Bug Fixes
|
||||||
|
|
||||||
- 添加覆写脚本执行日志功能
|
- 修复托盘菜单在Linux下崩溃的问题
|
||||||
- 支持查看局域网网络信息
|
|
||||||
- 支持托盘菜单显示节点信息
|
|
||||||
|
|||||||
@ -193,13 +193,15 @@ const mihomoTraffic = async (): Promise<void> => {
|
|||||||
} else {
|
} else {
|
||||||
tray?.setTitle('')
|
tray?.setTitle('')
|
||||||
}
|
}
|
||||||
|
if (process.platform !== 'linux') {
|
||||||
|
tray?.setToolTip(
|
||||||
|
'↑' +
|
||||||
|
`${calcTraffic(json.up)}/s`.padStart(12) +
|
||||||
|
'\n↓' +
|
||||||
|
`${calcTraffic(json.down)}/s`.padStart(12)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
tray?.setToolTip(
|
|
||||||
'↑' +
|
|
||||||
`${calcTraffic(json.up)}/s`.padStart(12) +
|
|
||||||
'\n↓' +
|
|
||||||
`${calcTraffic(json.down)}/s`.padStart(12)
|
|
||||||
)
|
|
||||||
trafficRetry = 10
|
trafficRetry = 10
|
||||||
mainWindow?.webContents.send('mihomoTraffic', json)
|
mainWindow?.webContents.send('mihomoTraffic', json)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import {
|
|||||||
patchMihomoConfig
|
patchMihomoConfig
|
||||||
} from '../core/mihomoApi'
|
} from '../core/mihomoApi'
|
||||||
import { mainWindow, showMainWindow } from '..'
|
import { mainWindow, showMainWindow } from '..'
|
||||||
import { app, Menu, nativeImage, shell, Tray } from 'electron'
|
import { app, ipcMain, Menu, nativeImage, shell, Tray } from 'electron'
|
||||||
import { dataDir, logDir, mihomoCoreDir, mihomoWorkDir } from '../utils/dirs'
|
import { dataDir, logDir, mihomoCoreDir, mihomoWorkDir } from '../utils/dirs'
|
||||||
import { triggerSysProxy } from '../sys/sysproxy'
|
import { triggerSysProxy } from '../sys/sysproxy'
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ const buildContextMenu = async (): Promise<Menu> => {
|
|||||||
const { mode, tun } = await getControledMihomoConfig()
|
const { mode, tun } = await getControledMihomoConfig()
|
||||||
const { sysProxy, autoCloseConnection, proxyInTray = true } = await getAppConfig()
|
const { sysProxy, autoCloseConnection, proxyInTray = true } = await getAppConfig()
|
||||||
let groupsMenu: Electron.MenuItemConstructorOptions[] = []
|
let groupsMenu: Electron.MenuItemConstructorOptions[] = []
|
||||||
if (proxyInTray) {
|
if (proxyInTray && process.platform !== 'linux') {
|
||||||
try {
|
try {
|
||||||
const groups = await mihomoGroups()
|
const groups = await mihomoGroups()
|
||||||
groupsMenu = groups.map((group) => {
|
groupsMenu = groups.map((group) => {
|
||||||
@ -81,6 +81,7 @@ const buildContextMenu = async (): Promise<Menu> => {
|
|||||||
await patchControledMihomoConfig({ mode: 'rule' })
|
await patchControledMihomoConfig({ mode: 'rule' })
|
||||||
await patchMihomoConfig({ mode: 'rule' })
|
await patchMihomoConfig({ mode: 'rule' })
|
||||||
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
||||||
|
await updateTrayMenu()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -92,6 +93,7 @@ const buildContextMenu = async (): Promise<Menu> => {
|
|||||||
await patchControledMihomoConfig({ mode: 'global' })
|
await patchControledMihomoConfig({ mode: 'global' })
|
||||||
await patchMihomoConfig({ mode: 'global' })
|
await patchMihomoConfig({ mode: 'global' })
|
||||||
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
||||||
|
await updateTrayMenu()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -103,6 +105,7 @@ const buildContextMenu = async (): Promise<Menu> => {
|
|||||||
await patchControledMihomoConfig({ mode: 'direct' })
|
await patchControledMihomoConfig({ mode: 'direct' })
|
||||||
await patchMihomoConfig({ mode: 'direct' })
|
await patchMihomoConfig({ mode: 'direct' })
|
||||||
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
||||||
|
await updateTrayMenu()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
@ -119,6 +122,7 @@ const buildContextMenu = async (): Promise<Menu> => {
|
|||||||
await patchAppConfig({ sysProxy: { enable: !enable } })
|
await patchAppConfig({ sysProxy: { enable: !enable } })
|
||||||
} finally {
|
} finally {
|
||||||
mainWindow?.webContents.send('appConfigUpdated')
|
mainWindow?.webContents.send('appConfigUpdated')
|
||||||
|
await updateTrayMenu()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -135,6 +139,7 @@ const buildContextMenu = async (): Promise<Menu> => {
|
|||||||
}
|
}
|
||||||
await patchMihomoConfig({ tun: { enable } })
|
await patchMihomoConfig({ tun: { enable } })
|
||||||
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
||||||
|
await updateTrayMenu()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
...groupsMenu,
|
...groupsMenu,
|
||||||
@ -184,6 +189,8 @@ export async function createTray(): Promise<void> {
|
|||||||
const { useDockIcon = true } = await getAppConfig()
|
const { useDockIcon = true } = await getAppConfig()
|
||||||
if (process.platform === 'linux') {
|
if (process.platform === 'linux') {
|
||||||
tray = new Tray(pngIcon)
|
tray = new Tray(pngIcon)
|
||||||
|
const menu = await buildContextMenu()
|
||||||
|
tray.setContextMenu(menu)
|
||||||
}
|
}
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
const icon = nativeImage.createFromPath(templateIcon)
|
const icon = nativeImage.createFromPath(templateIcon)
|
||||||
@ -209,7 +216,8 @@ export async function createTray(): Promise<void> {
|
|||||||
tray?.addListener('click', async () => {
|
tray?.addListener('click', async () => {
|
||||||
await updateTrayMenu()
|
await updateTrayMenu()
|
||||||
})
|
})
|
||||||
} else {
|
}
|
||||||
|
if (process.platform === 'win32') {
|
||||||
tray?.addListener('click', () => {
|
tray?.addListener('click', () => {
|
||||||
if (mainWindow?.isVisible()) {
|
if (mainWindow?.isVisible()) {
|
||||||
mainWindow?.close()
|
mainWindow?.close()
|
||||||
@ -221,9 +229,24 @@ export async function createTray(): Promise<void> {
|
|||||||
await updateTrayMenu()
|
await updateTrayMenu()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if (process.platform === 'linux') {
|
||||||
|
tray?.addListener('click', () => {
|
||||||
|
if (mainWindow?.isVisible()) {
|
||||||
|
mainWindow?.close()
|
||||||
|
} else {
|
||||||
|
showMainWindow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
ipcMain.on('updateTrayMenu', async () => {
|
||||||
|
await updateTrayMenu()
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateTrayMenu(): Promise<void> {
|
async function updateTrayMenu(): Promise<void> {
|
||||||
const menu = await buildContextMenu()
|
const menu = await buildContextMenu()
|
||||||
tray?.popUpContextMenu(menu) // 弹出菜单
|
tray?.popUpContextMenu(menu) // 弹出菜单
|
||||||
|
if (process.platform === 'linux') {
|
||||||
|
tray?.setContextMenu(menu)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@ const OutboundModeSwitcher: React.FC = () => {
|
|||||||
if (autoCloseConnection) {
|
if (autoCloseConnection) {
|
||||||
await mihomoCloseAllConnections()
|
await mihomoCloseAllConnections()
|
||||||
}
|
}
|
||||||
|
window.electron.ipcRenderer.send('updateTrayMenu')
|
||||||
}
|
}
|
||||||
if (!mode) return null
|
if (!mode) return null
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -29,6 +29,7 @@ const SysproxySwitcher: React.FC = () => {
|
|||||||
const onChange = async (enable: boolean): Promise<void> => {
|
const onChange = async (enable: boolean): Promise<void> => {
|
||||||
await triggerSysProxy(enable)
|
await triggerSysProxy(enable)
|
||||||
await patchAppConfig({ sysProxy: { enable } })
|
await patchAppConfig({ sysProxy: { enable } })
|
||||||
|
window.electron.ipcRenderer.send('updateTrayMenu')
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -54,6 +54,7 @@ const TunSwitcher: React.FC = () => {
|
|||||||
await patchControledMihomoConfig({ tun: { enable } })
|
await patchControledMihomoConfig({ tun: { enable } })
|
||||||
}
|
}
|
||||||
await patchMihomoConfig({ tun: { enable } })
|
await patchMihomoConfig({ tun: { enable } })
|
||||||
|
window.electron.ipcRenderer.send('updateTrayMenu')
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -62,7 +62,6 @@ const Proxies: React.FC = () => {
|
|||||||
if (autoCloseConnection) {
|
if (autoCloseConnection) {
|
||||||
await mihomoCloseAllConnections()
|
await mihomoCloseAllConnections()
|
||||||
}
|
}
|
||||||
// window.electron.ipcRenderer.send('mihomoGroupsUpdated')
|
|
||||||
mutate()
|
mutate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -195,15 +195,18 @@ const Settings: React.FC = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
<SettingItem title="托盘菜单显示节点信息" divider>
|
{platform !== 'linux' && (
|
||||||
<Switch
|
<SettingItem title="托盘菜单显示节点信息" divider>
|
||||||
size="sm"
|
<Switch
|
||||||
isSelected={proxyInTray}
|
size="sm"
|
||||||
onValueChange={(v) => {
|
isSelected={proxyInTray}
|
||||||
patchAppConfig({ proxyInTray: v })
|
onValueChange={async (v) => {
|
||||||
}}
|
await patchAppConfig({ proxyInTray: v })
|
||||||
/>
|
}}
|
||||||
</SettingItem>
|
/>
|
||||||
|
</SettingItem>
|
||||||
|
)}
|
||||||
|
|
||||||
{platform === 'darwin' && (
|
{platform === 'darwin' && (
|
||||||
<>
|
<>
|
||||||
<SettingItem title="显示Dock图标" divider>
|
<SettingItem title="显示Dock图标" divider>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user