Allow disable traffic in tray

This commit is contained in:
pompurin404 2024-08-15 19:43:03 +08:00
parent 7ff61b697f
commit 6e9b7cdb10
No known key found for this signature in database
3 changed files with 38 additions and 18 deletions

View File

@ -144,6 +144,7 @@ export const stopMihomoTraffic = (): void => {
}
const mihomoTraffic = async (): Promise<void> => {
const { showTraffic = true } = await getAppConfig()
const controledMihomoConfig = await getControledMihomoConfig()
let server = controledMihomoConfig['external-controller']
const secret = controledMihomoConfig.secret ?? ''
@ -155,16 +156,20 @@ const mihomoTraffic = async (): Promise<void> => {
mihomoTrafficWs.onmessage = (e): void => {
const data = e.data as string
const json = JSON.parse(data) as IMihomoTrafficInfo
if (trafficHopping) {
tray?.setTitle('↑' + `${calcTraffic(json.up)}/s`.padStart(12), {
fontType: 'monospaced'
})
if (showTraffic) {
if (trafficHopping) {
tray?.setTitle('↑' + `${calcTraffic(json.up)}/s`.padStart(12), {
fontType: 'monospaced'
})
} else {
tray?.setTitle('↓' + `${calcTraffic(json.down)}/s`.padStart(12), {
fontType: 'monospaced'
})
}
trafficHopping = !trafficHopping
} else {
tray?.setTitle('↓' + `${calcTraffic(json.down)}/s`.padStart(12), {
fontType: 'monospaced'
})
tray?.setTitle('')
}
trafficHopping = !trafficHopping
tray?.setToolTip(
'↑' +

View File

@ -11,7 +11,8 @@ import {
checkUpdate,
patchControledMihomoConfig,
isPortable,
setPortable
setPortable,
restartCore
} from '@renderer/utils/ipc'
import { IoLogoGithub } from 'react-icons/io5'
import { platform, version } from '@renderer/utils/init'
@ -30,6 +31,7 @@ const Settings: React.FC = () => {
controlDns = true,
controlSniff = true,
useDockIcon = true,
showTraffic = true,
delayTestUrl,
delayTestTimeout,
autoCheckUpdate,
@ -124,15 +126,27 @@ const Settings: React.FC = () => {
/>
</SettingItem>
{platform === 'darwin' && (
<SettingItem title="显示Dock图标" divider>
<Switch
size="sm"
isSelected={useDockIcon}
onValueChange={(v) => {
patchAppConfig({ useDockIcon: v })
}}
/>
</SettingItem>
<>
<SettingItem title="显示Dock图标" divider>
<Switch
size="sm"
isSelected={useDockIcon}
onValueChange={async (v) => {
await patchAppConfig({ useDockIcon: v })
}}
/>
</SettingItem>
<SettingItem title="显示网速信息" divider>
<Switch
size="sm"
isSelected={showTraffic}
onValueChange={async (v) => {
await patchAppConfig({ showTraffic: v })
await restartCore()
}}
/>
</SettingItem>
</>
)}
{platform === 'win32' && (
<SettingItem title="数据存储路径" divider>

View File

@ -217,6 +217,7 @@ interface IAppConfig {
controlDns?: boolean
controlSniff?: boolean
useDockIcon?: boolean
showTraffic?: boolean
useNameserverPolicy: boolean
nameserverPolicy: { [key: string]: string | string[] }
}