mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-18 16:30:32 +08:00
refactor(tray): remove timer for updating tray in plan, use update manually to prevent needless refresh to cause visuual flash
This commit is contained in:
parent
dd34ced070
commit
7838fa1e75
@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
config::{Config, IClashTemp},
|
config::{Config, IClashTemp},
|
||||||
core::Timer,
|
core::tray::Tray,
|
||||||
utils::{dirs, init::service_writer_config},
|
utils::{dirs, init::service_writer_config},
|
||||||
};
|
};
|
||||||
use anyhow::{Context as _, Result, bail};
|
use anyhow::{Context as _, Result, bail};
|
||||||
@ -578,7 +578,7 @@ impl ServiceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 防止服务安装成功后,内核未完全启动导致系统托盘无法获取代理节点信息
|
// 防止服务安装成功后,内核未完全启动导致系统托盘无法获取代理节点信息
|
||||||
Timer::global().add_update_tray_menu_task()?;
|
Tray::global().update_menu().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -142,25 +142,6 @@ impl Timer {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 每 3 秒更新系统托盘菜单,总共执行 3 次
|
|
||||||
pub fn add_update_tray_menu_task(&self) -> Result<()> {
|
|
||||||
let tid = self.timer_count.fetch_add(1, Ordering::SeqCst);
|
|
||||||
let task = TaskBuilder::default()
|
|
||||||
.set_task_id(tid)
|
|
||||||
.set_maximum_parallel_runnable_num(1)
|
|
||||||
.set_frequency_count_down_by_seconds(3, 3)
|
|
||||||
.spawn_async_routine(|| async move {
|
|
||||||
logging!(debug, Type::Timer, "Updating tray menu");
|
|
||||||
crate::core::tray::Tray::global().update_menu().await
|
|
||||||
})
|
|
||||||
.context("failed to create update tray menu timer task")?;
|
|
||||||
self.delay_timer
|
|
||||||
.write()
|
|
||||||
.add_task(task)
|
|
||||||
.context("failed to add update tray menu timer task")?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Refresh timer tasks with better error handling
|
/// Refresh timer tasks with better error handling
|
||||||
pub async fn refresh(&self) -> Result<()> {
|
pub async fn refresh(&self) -> Result<()> {
|
||||||
// Generate diff outside of lock to minimize lock contention
|
// Generate diff outside of lock to minimize lock contention
|
||||||
|
|||||||
@ -198,8 +198,6 @@ impl Tray {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: 初始化时,暂时使用此方法更新系统托盘菜单,有效避免代理节点菜单空白
|
|
||||||
crate::core::timer::Timer::global().add_update_tray_menu_task()?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user