mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-13 13:30:31 +08:00
fix: tray not update when delete profile (#6549)
This commit is contained in:
parent
fac897ae29
commit
27217a4b76
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,3 +15,4 @@ scripts/_env.sh
|
||||
target
|
||||
CLAUDE.md
|
||||
.vfox.toml
|
||||
.vfox/
|
||||
|
||||
@ -173,6 +173,13 @@ pub async fn delete_profile(index: String) -> CmdResult {
|
||||
// 使用Send-safe helper函数
|
||||
let should_update = profiles_delete_item_safe(&index).await.stringify_err()?;
|
||||
profiles_save_file_safe().await.stringify_err()?;
|
||||
if let Err(e) = Tray::global().update_tooltip().await {
|
||||
logging!(warn, Type::Cmd, "Warning: 异步更新托盘提示失败: {e}");
|
||||
}
|
||||
|
||||
if let Err(e) = Tray::global().update_menu().await {
|
||||
logging!(warn, Type::Cmd, "Warning: 异步更新托盘菜单失败: {e}");
|
||||
}
|
||||
if should_update {
|
||||
Config::profiles().await.apply();
|
||||
match CoreManager::global().update_config().await {
|
||||
|
||||
@ -263,16 +263,20 @@ impl IProfiles {
|
||||
pub async fn delete_item(&mut self, uid: &String) -> Result<bool> {
|
||||
let current = self.current.as_ref().unwrap_or(uid);
|
||||
let current = current.clone();
|
||||
let (merge_uid, script_uid, rules_uid, proxies_uid, groups_uid) = {
|
||||
let delete_uids = {
|
||||
let item = self.get_item(uid)?;
|
||||
let option = item.option.as_ref();
|
||||
(
|
||||
option.and_then(|e| e.merge.clone()),
|
||||
option.and_then(|e| e.script.clone()),
|
||||
option.and_then(|e| e.rules.clone()),
|
||||
option.and_then(|e| e.proxies.clone()),
|
||||
option.and_then(|e| e.groups.clone()),
|
||||
)
|
||||
option.map_or(Vec::new(), |op| {
|
||||
[
|
||||
op.merge.clone(),
|
||||
op.script.clone(),
|
||||
op.rules.clone(),
|
||||
op.proxies.clone(),
|
||||
op.groups.clone(),
|
||||
]
|
||||
.into_iter()
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
};
|
||||
let mut items = self.items.take().unwrap_or_default();
|
||||
|
||||
@ -281,22 +285,12 @@ impl IProfiles {
|
||||
let _ = dirs::app_profiles_dir()?.join(file.as_str()).remove_if_exists().await;
|
||||
}
|
||||
|
||||
// remove related extension items (merge, script, rules, proxies, groups)
|
||||
if let Some(file) = Self::take_item_file_by_uid(&mut items, merge_uid.as_deref()) {
|
||||
let _ = dirs::app_profiles_dir()?.join(file.as_str()).remove_if_exists().await;
|
||||
}
|
||||
if let Some(file) = Self::take_item_file_by_uid(&mut items, script_uid.as_deref()) {
|
||||
let _ = dirs::app_profiles_dir()?.join(file.as_str()).remove_if_exists().await;
|
||||
}
|
||||
if let Some(file) = Self::take_item_file_by_uid(&mut items, rules_uid.as_deref()) {
|
||||
let _ = dirs::app_profiles_dir()?.join(file.as_str()).remove_if_exists().await;
|
||||
}
|
||||
if let Some(file) = Self::take_item_file_by_uid(&mut items, proxies_uid.as_deref()) {
|
||||
let _ = dirs::app_profiles_dir()?.join(file.as_str()).remove_if_exists().await;
|
||||
}
|
||||
if let Some(file) = Self::take_item_file_by_uid(&mut items, groups_uid.as_deref()) {
|
||||
let _ = dirs::app_profiles_dir()?.join(file.as_str()).remove_if_exists().await;
|
||||
for delete_uid in delete_uids {
|
||||
if let Some(file) = Self::take_item_file_by_uid(&mut items, delete_uid.as_deref()) {
|
||||
let _ = dirs::app_profiles_dir()?.join(file.as_str()).remove_if_exists().await;
|
||||
}
|
||||
}
|
||||
|
||||
// delete the original uid
|
||||
if current == *uid {
|
||||
self.current = None;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user