refactor(tray): deduplicate icon getters, update_icon, and menu+icon combo

- Consolidate 3 near-identical icon getter functions into load_icon/default_icon with IconKind enum
- Merge two platform-gated update_icon implementations into one
- Extract update_menu_and_icon to eliminate duplicate combo in feat/config.rs and feat/clash.rs
This commit is contained in:
Tunglies
2026-03-23 22:37:09 +08:00
parent 0932de9f6c
commit 670d7bae3b
3 changed files with 63 additions and 113 deletions
+2 -8
View File
@@ -5,7 +5,7 @@ use crate::{
process::AsyncHandler,
utils::{self, resolve::reset_resolve_done},
};
use clash_verge_logging::{Type, logging, logging_error};
use clash_verge_logging::{Type, logging};
use serde_yaml_ng::{Mapping, Value};
use smartstring::alias::String;
@@ -86,13 +86,7 @@ pub async fn change_clash_mode(mode: String) {
let clash_data = clash.data_arc();
if clash_data.save_config().await.is_ok() {
handle::Handle::refresh_clash();
logging_error!(Type::Tray, tray::Tray::global().update_menu().await);
logging_error!(
Type::Tray,
tray::Tray::global()
.update_icon(&Config::verge().await.data_arc())
.await
);
tray::Tray::global().update_menu_and_icon().await;
}
let is_auto_close_connection = Config::verge().await.data_arc().auto_close_connection.unwrap_or(false);
+1 -7
View File
@@ -20,13 +20,7 @@ pub async fn patch_clash(patch: &Mapping) -> Result<()> {
CoreManager::global().restart_core().await?;
} else {
if patch.get("mode").is_some() {
logging_error!(Type::Tray, tray::Tray::global().update_menu().await);
logging_error!(
Type::Tray,
tray::Tray::global()
.update_icon(&Config::verge().await.data_arc())
.await
);
tray::Tray::global().update_menu_and_icon().await;
}
Config::runtime().await.edit_draft(|d| d.patch_config(patch));
CoreManager::global().update_config().await?;