diff --git a/changelog.md b/changelog.md index 4f1c043..1e82298 100644 --- a/changelog.md +++ b/changelog.md @@ -6,3 +6,4 @@ ### Bug Fixes - 修改混合端口后系统代理没有更新 +- 缩短MacOS网速显示长度 diff --git a/src/main/core/mihomoApi.ts b/src/main/core/mihomoApi.ts index 3557570..f8b4708 100644 --- a/src/main/core/mihomoApi.ts +++ b/src/main/core/mihomoApi.ts @@ -186,11 +186,11 @@ const mihomoTraffic = async (): Promise => { 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 => { 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) ) } diff --git a/src/main/utils/calc.ts b/src/main/utils/calc.ts index 9a1a92a..c5e1c11 100644 --- a/src/main/utils/calc.ts +++ b/src/main/utils/calc.ts @@ -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` }