refactor: update_core_config, simplify logic and delete invalid notifications

This commit is contained in:
huzibaca 2024-11-30 05:43:59 +08:00
parent 857574cbc1
commit 29ccabc054
No known key found for this signature in database
GPG Key ID: D4364EE4851DC302
7 changed files with 16 additions and 37 deletions

View File

@ -30,7 +30,10 @@ pub async fn use_tun(mut config: Mapping, enable: bool, origin_dns_val: Mapping)
val.as_mapping().cloned().unwrap_or(Mapping::new())
});
let ipv6_key = Value::from("ipv6");
let ipv6_val = config.get(&ipv6_key).and_then(|v| v.as_bool()).unwrap_or(false);
let ipv6_val = config
.get(&ipv6_key)
.and_then(|v| v.as_bool())
.unwrap_or(false);
if enable {
revise!(dns_val, "enable", true);

View File

@ -137,16 +137,14 @@ pub async fn patch_clash(patch: Mapping) -> Result<()> {
if patch.get("secret").is_some() || patch.get("external-controller").is_some() {
Config::generate().await?;
CoreManager::global().restart_core().await?;
handle::Handle::refresh_clash();
} else {
if patch.get("mode").is_some() {
log_err!(handle::Handle::update_systray_part());
}
Config::runtime().latest().patch_config(patch);
update_core_config(false).await?;
CoreManager::global().update_config().await?;
}
handle::Handle::refresh_clash();
<Result<()>>::Ok(())
};
match res {
@ -246,11 +244,11 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> {
should_update_systray_part = true;
}
if should_restart_core {
Config::generate().await?;
CoreManager::global().restart_core().await?;
}
if should_update_clash_config {
update_core_config(false).await?;
CoreManager::global().update_config().await?;
handle::Handle::refresh_clash();
}
if should_update_launch {
sysopt::Sysopt::global().update_launch()?;
@ -316,29 +314,17 @@ pub async fn update_profile(uid: String, option: Option<PrfOption>) -> Result<()
};
if should_update {
update_core_config(true).await?;
}
Ok(())
}
/// 更新订阅
async fn update_core_config(notice: bool) -> Result<()> {
match CoreManager::global().update_config().await {
Ok(_) => {
handle::Handle::refresh_clash();
if notice {
handle::Handle::notice_message("set_config::ok", "ok");
}
Ok(())
}
Err(err) => {
if notice {
handle::Handle::notice_message("set_config::error", format!("{err}"));
}
Err(err)
log::error!(target: "app", "{err}");
}
}
}
Ok(())
}
/// copy env variable

View File

@ -352,7 +352,6 @@
"Match Whole Word": "Match Whole Word",
"Use Regular Expression": "Use Regular Expression",
"Profile Imported Successfully": "Profile Imported Successfully",
"Clash Config Updated": "Clash Config Updated",
"Profile Switched": "Profile Switched",
"Profile Reactivated": "Profile Reactivated",
"Only YAML Files Supported": "Only YAML Files Supported",

View File

@ -354,7 +354,6 @@
"Match Whole Word": "تطبیق کل کلمه",
"Use Regular Expression": "استفاده از عبارت منظم",
"Profile Imported Successfully": "پروفایل با موفقیت وارد شد",
"Clash Config Updated": "پیکربندی Clash به‌روزرسانی شد",
"Profile Switched": "پروفایل تغییر یافت",
"Profile Reactivated": "پروفایل مجدداً فعال شد",
"Only YAML Files Supported": "فقط فایل‌های YAML پشتیبانی می‌شوند",

View File

@ -354,7 +354,6 @@
"Match Whole Word": "Полное совпадение слова",
"Use Regular Expression": "Использовать регулярные выражения",
"Profile Imported Successfully": "Профиль успешно импортирован",
"Clash Config Updated": "Clash конфигурация Обновлена",
"Profile Switched": "Профиль изменен",
"Profile Reactivated": "Профиль повторно активирован",
"Only YAML Files Supported": "Поддерживаются только файлы YAML",

View File

@ -354,7 +354,6 @@
"Match Whole Word": "全字匹配",
"Use Regular Expression": "使用正则表达式",
"Profile Imported Successfully": "导入订阅成功",
"Clash Config Updated": "Clash 配置已更新",
"Profile Switched": "订阅已切换",
"Profile Reactivated": "订阅已激活",
"Only YAML Files Supported": "仅支持 YAML 文件",

View File

@ -77,12 +77,6 @@ const Layout = () => {
navigate("/profile");
Notice.error(msg);
break;
case "set_config::ok":
Notice.success(t("Clash Config Updated"));
break;
case "set_config::error":
Notice.error(msg);
break;
default:
break;
}