mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-05 14:10:18 +08:00
refactor(core): derive refresh announcements from transaction commit
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::core::notify::{Refresh, announce};
|
||||
use anyhow::{Result, ensure};
|
||||
use clash_verge_draft::DraftTransaction;
|
||||
use serde::Serialize;
|
||||
@@ -10,7 +11,7 @@ use crate::{
|
||||
profiles::PROFILE_WRITE_LOCK,
|
||||
},
|
||||
constants::files::DNS_CONFIG,
|
||||
core::{CoreManager, handle::Handle},
|
||||
core::CoreManager,
|
||||
utils::dirs,
|
||||
};
|
||||
|
||||
@@ -25,6 +26,14 @@ pub async fn set_dns_override(
|
||||
profile_uid: String,
|
||||
enabled: bool,
|
||||
confirmation: Option<String>,
|
||||
) -> Result<DnsOverrideOutcome> {
|
||||
crate::core::notify::after_commit(Box::pin(set_dns_override_inner(profile_uid, enabled, confirmation))).await
|
||||
}
|
||||
|
||||
async fn set_dns_override_inner(
|
||||
profile_uid: String,
|
||||
enabled: bool,
|
||||
confirmation: Option<String>,
|
||||
) -> Result<DnsOverrideOutcome> {
|
||||
let _profile_write = PROFILE_WRITE_LOCK.lock().await;
|
||||
let _config_write = Config::lock_config_write().await;
|
||||
@@ -74,8 +83,8 @@ pub async fn set_dns_override(
|
||||
}
|
||||
|
||||
transaction.commit();
|
||||
Handle::refresh_verge();
|
||||
Handle::refresh_clash();
|
||||
verge.data_arc().save_file().await?;
|
||||
announce(Refresh::Verge);
|
||||
announce(Refresh::Clash);
|
||||
Ok(outcome)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user