mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-10 19:50:28 +08:00
fix: prevent tray traffic icon flickering on macOS
This commit is contained in:
parent
490f559306
commit
bc4b59c66b
@ -60,6 +60,8 @@ const ConnCard: React.FC<Props> = (props) => {
|
|||||||
const currentDownloadRef = useRef<number | undefined>(undefined)
|
const currentDownloadRef = useRef<number | undefined>(undefined)
|
||||||
const hasShowTrafficRef = useRef(false)
|
const hasShowTrafficRef = useRef(false)
|
||||||
const drawingRef = useRef(false)
|
const drawingRef = useRef(false)
|
||||||
|
// 保存待绘制的流量数据,避免跳过更新导致图标闪烁
|
||||||
|
const pendingTrafficRef = useRef<{ up: number; down: number } | null>(null)
|
||||||
|
|
||||||
// Chart.js 配置
|
// Chart.js 配置
|
||||||
const chartData = useMemo(() => {
|
const chartData = useMemo(() => {
|
||||||
@ -140,10 +142,17 @@ const ConnCard: React.FC<Props> = (props) => {
|
|||||||
})
|
})
|
||||||
if (platform === 'darwin') {
|
if (platform === 'darwin') {
|
||||||
if (showTraffic) {
|
if (showTraffic) {
|
||||||
|
// 保存最新流量数据,确保绘制完成后使用最新值
|
||||||
|
pendingTrafficRef.current = { up: info.up, down: info.down }
|
||||||
if (drawingRef.current) return
|
if (drawingRef.current) return
|
||||||
drawingRef.current = true
|
drawingRef.current = true
|
||||||
try {
|
try {
|
||||||
await drawSvg(info.up, info.down, currentUploadRef, currentDownloadRef)
|
// 循环处理待绘制数据,直到没有新数据
|
||||||
|
while (pendingTrafficRef.current) {
|
||||||
|
const { up, down } = pendingTrafficRef.current
|
||||||
|
pendingTrafficRef.current = null
|
||||||
|
await drawSvg(up, down, currentUploadRef, currentDownloadRef)
|
||||||
|
}
|
||||||
hasShowTrafficRef.current = true
|
hasShowTrafficRef.current = true
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user