feat: enhance profile update logic to include auto-update option handling

This commit is contained in:
Tunglies
2025-10-18 17:36:42 +08:00
parent c2d7bf296a
commit 8e20b1b0a0
2 changed files with 11 additions and 5 deletions

View File

@@ -572,19 +572,23 @@ pub async fn patch_profiles_config_by_profile_index(profile_index: String) -> Cm
pub async fn patch_profile(index: String, profile: PrfItem) -> CmdResult {
// 保存修改前检查是否有更新 update_interval
let profiles = Config::profiles().await;
let update_interval_changed = if let Ok(old_profile) = profiles.latest_ref().get_item(&index) {
let should_refresh_timer = if let Ok(old_profile) = profiles.latest_ref().get_item(&index) {
let old_interval = old_profile.option.as_ref().and_then(|o| o.update_interval);
let new_interval = profile.option.as_ref().and_then(|o| o.update_interval);
old_interval != new_interval
let old_allow_auto_update = old_profile
.option
.as_ref()
.and_then(|o| o.allow_auto_update);
let new_allow_auto_update = profile.option.as_ref().and_then(|o| o.allow_auto_update);
(old_interval != new_interval) || (old_allow_auto_update != new_allow_auto_update)
} else {
false
};
// 保存修改
wrap_err!(profiles_patch_item_safe(index.clone(), profile).await)?;
// 如果更新间隔变更,异步刷新定时器
if update_interval_changed {
// 如果更新间隔或允许自动更新变更,异步刷新定时器
if should_refresh_timer {
let index_clone = index.clone();
crate::process::AsyncHandler::spawn(move || async move {
logging!(info, Type::Timer, "定时器更新间隔已变更,正在刷新定时器...");

View File

@@ -264,7 +264,9 @@ impl Timer {
if let Some(items) = Config::profiles().await.latest_ref().get_items() {
for item in items.iter() {
if let Some(option) = item.option.as_ref()
&& let Some(allow_auto_update) = option.allow_auto_update
&& let (Some(interval), Some(uid)) = (option.update_interval, &item.uid)
&& allow_auto_update
&& interval > 0
{
logging!(