refactor: update update_icon method to require a non-optional verge reference and adjust related calls (#5417)

This commit is contained in:
Tunglies
2025-11-12 07:36:24 +08:00
committed by GitHub
parent 92a3f0cae3
commit f3a3d0e8b0
6 changed files with 27 additions and 26 deletions

View File

@@ -348,7 +348,7 @@ impl Tray {
/// 更新托盘图标
#[cfg(target_os = "macos")]
pub async fn update_icon(&self, verge: Option<&IVerge>) -> Result<()> {
pub async fn update_icon(&self, verge: &IVerge) -> Result<()> {
if handle::Handle::global().is_exiting() {
logging!(debug, Type::Tray, "应用正在退出,跳过托盘图标更新");
return Ok(());
@@ -368,11 +368,6 @@ impl Tray {
}
};
let verge = match verge {
Some(v) => v,
None => &Config::verge().await.data_arc(),
};
let system_mode = verge.enable_system_proxy.as_ref().unwrap_or(&false);
let tun_mode = verge.enable_tun_mode.as_ref().unwrap_or(&false);
@@ -395,7 +390,7 @@ impl Tray {
}
#[cfg(not(target_os = "macos"))]
pub async fn update_icon(&self, verge: Option<&IVerge>) -> Result<()> {
pub async fn update_icon(&self, verge: &IVerge) -> Result<()> {
if handle::Handle::global().is_exiting() {
logging!(debug, Type::Tray, "应用正在退出,跳过托盘图标更新");
return Ok(());
@@ -415,11 +410,6 @@ impl Tray {
}
};
let verge = match verge {
Some(v) => v,
None => &Config::verge().await.data_arc(),
};
let system_mode = verge.enable_system_proxy.as_ref().unwrap_or(&false);
let tun_mode = verge.enable_tun_mode.as_ref().unwrap_or(&false);
@@ -510,8 +500,9 @@ impl Tray {
logging!(debug, Type::Tray, "应用正在退出,跳过托盘局部更新");
return Ok(());
}
let verge = Config::verge().await.data_arc();
self.update_menu().await?;
self.update_icon(None).await?;
self.update_icon(&verge).await?;
self.update_tooltip().await?;
Ok(())
}