diff --git a/Changelog.md b/Changelog.md index e53b4ebf3..b8e9235b9 100644 --- a/Changelog.md +++ b/Changelog.md @@ -24,6 +24,8 @@
🐞 修复问题 +- 修复应用退出时无条件重写 `clash.yaml`、`verge.yaml` 和 `profiles.yaml` 导致文件创建时间丢失的问题 + - 修复检测更新后又发布新版时,应用内更新失败 - 修复订阅响应过大导致内存占用过高,限制单次下载为 4 MiB - 修复全局模式默认停在 `DIRECT` 或 `REJECT` 导致流量未经代理,现自动切换到第一个策略组 diff --git a/crates/clash-verge-draft/src/lib.rs b/crates/clash-verge-draft/src/lib.rs index c9bf560e5..0dcf1c5a6 100644 --- a/crates/clash-verge-draft/src/lib.rs +++ b/crates/clash-verge-draft/src/lib.rs @@ -74,12 +74,16 @@ impl Draft { result } - /// Commits and clears the draft. + /// Commits and clears the draft, reporting whether one was staged. #[inline] - pub fn apply(&self) { + pub fn apply(&self) -> bool { let mut guard = self.inner.data.lock(); - if let Some(d) = guard.1.take() { - guard.0 = d; + match guard.1.take() { + Some(d) => { + guard.0 = d; + true + } + None => false, } } diff --git a/src-tauri/src/config/config.rs b/src-tauri/src/config/config.rs index 59e6f921d..a0cb4191d 100644 --- a/src-tauri/src/config/config.rs +++ b/src-tauri/src/config/config.rs @@ -280,25 +280,29 @@ impl Config { } /// Commits drafts during exit/restart/shutdown so user changes are not lost. + /// A config with nothing staged keeps its file, so its timestamps stay put. pub async fn apply_all_and_save_file() { logging!(debug, Type::Config, "save all draft data"); let save_clash_task = AsyncHandler::spawn(|| async { let clash = Self::clash().await; - clash.apply(); - logging_error!(Type::Config, clash.data_arc().save_config().await); + if clash.apply() { + logging_error!(Type::Config, clash.data_arc().save_config().await); + } }); let save_verge_task = AsyncHandler::spawn(|| async { let verge = Self::verge().await; - verge.apply(); - logging_error!(Type::Config, verge.data_arc().save_file().await); + if verge.apply() { + logging_error!(Type::Config, verge.data_arc().save_file().await); + } }); let save_profiles_task = AsyncHandler::spawn(|| async { let _profile_write = super::profiles::PROFILE_WRITE_LOCK.lock().await; let profiles = Self::profiles().await; - profiles.apply(); - logging_error!(Type::Config, profiles.data_arc().save_file().await); + if profiles.apply() { + logging_error!(Type::Config, profiles.data_arc().save_file().await); + } }); let _ = tokio::join!(save_clash_task, save_verge_task, save_profiles_task);