mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
shorten traffic display length
This commit is contained in:
parent
d4698583ba
commit
334f718f72
@ -6,3 +6,4 @@
|
||||
### Bug Fixes
|
||||
|
||||
- 修改混合端口后系统代理没有更新
|
||||
- 缩短MacOS网速显示长度
|
||||
|
||||
@ -186,11 +186,11 @@ const mihomoTraffic = async (): Promise<void> => {
|
||||
const json = JSON.parse(data) as IMihomoTrafficInfo
|
||||
if (showTraffic) {
|
||||
if (trafficHopping) {
|
||||
tray?.setTitle('↑' + `${calcTraffic(json.up)}/s`.padStart(12), {
|
||||
tray?.setTitle('↑' + `${calcTraffic(json.up)}/s`.padStart(9), {
|
||||
fontType: 'monospaced'
|
||||
})
|
||||
} else {
|
||||
tray?.setTitle('↓' + `${calcTraffic(json.down)}/s`.padStart(12), {
|
||||
tray?.setTitle('↓' + `${calcTraffic(json.down)}/s`.padStart(9), {
|
||||
fontType: 'monospaced'
|
||||
})
|
||||
}
|
||||
@ -201,9 +201,9 @@ const mihomoTraffic = async (): Promise<void> => {
|
||||
if (process.platform !== 'linux') {
|
||||
tray?.setToolTip(
|
||||
'↑' +
|
||||
`${calcTraffic(json.up)}/s`.padStart(12) +
|
||||
`${calcTraffic(json.up)}/s`.padStart(9) +
|
||||
'\n↓' +
|
||||
`${calcTraffic(json.down)}/s`.padStart(12)
|
||||
`${calcTraffic(json.down)}/s`.padStart(9)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
export function calcTraffic(byte: number): string {
|
||||
if (byte < 1024) return `${byte} B`
|
||||
byte /= 1024
|
||||
if (byte < 1024) return `${byte.toFixed(2)} KB`
|
||||
if (byte < 1024) return `${Math.round(byte)} KB`
|
||||
byte /= 1024
|
||||
if (byte < 1024) return `${byte.toFixed(2)} MB`
|
||||
if (byte < 1024) return `${Math.round(byte)} MB`
|
||||
byte /= 1024
|
||||
if (byte < 1024) return `${byte.toFixed(2)} GB`
|
||||
if (byte < 1024) return `${Math.round(byte)} GB`
|
||||
byte /= 1024
|
||||
if (byte < 1024) return `${byte.toFixed(2)} TB`
|
||||
if (byte < 1024) return `${Math.round(byte)} TB`
|
||||
byte /= 1024
|
||||
if (byte < 1024) return `${byte.toFixed(2)} PB`
|
||||
if (byte < 1024) return `${Math.round(byte)} PB`
|
||||
byte /= 1024
|
||||
if (byte < 1024) return `${byte.toFixed(2)} EB`
|
||||
if (byte < 1024) return `${Math.round(byte)} EB`
|
||||
byte /= 1024
|
||||
if (byte < 1024) return `${byte.toFixed(2)} ZB`
|
||||
if (byte < 1024) return `${Math.round(byte)} ZB`
|
||||
byte /= 1024
|
||||
return `${byte.toFixed(2)} YB`
|
||||
return `${Math.round(byte)} YB`
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user