feat: enhance profile update logic to include auto-update option handling
This commit is contained in:
@@ -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 {
|
pub async fn patch_profile(index: String, profile: PrfItem) -> CmdResult {
|
||||||
// 保存修改前检查是否有更新 update_interval
|
// 保存修改前检查是否有更新 update_interval
|
||||||
let profiles = Config::profiles().await;
|
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 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);
|
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 {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
// 保存修改
|
|
||||||
wrap_err!(profiles_patch_item_safe(index.clone(), profile).await)?;
|
wrap_err!(profiles_patch_item_safe(index.clone(), profile).await)?;
|
||||||
|
|
||||||
// 如果更新间隔变更,异步刷新定时器
|
// 如果更新间隔或允许自动更新变更,异步刷新定时器
|
||||||
if update_interval_changed {
|
if should_refresh_timer {
|
||||||
let index_clone = index.clone();
|
let index_clone = index.clone();
|
||||||
crate::process::AsyncHandler::spawn(move || async move {
|
crate::process::AsyncHandler::spawn(move || async move {
|
||||||
logging!(info, Type::Timer, "定时器更新间隔已变更,正在刷新定时器...");
|
logging!(info, Type::Timer, "定时器更新间隔已变更,正在刷新定时器...");
|
||||||
|
|||||||
@@ -264,7 +264,9 @@ impl Timer {
|
|||||||
if let Some(items) = Config::profiles().await.latest_ref().get_items() {
|
if let Some(items) = Config::profiles().await.latest_ref().get_items() {
|
||||||
for item in items.iter() {
|
for item in items.iter() {
|
||||||
if let Some(option) = item.option.as_ref()
|
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)
|
&& let (Some(interval), Some(uid)) = (option.update_interval, &item.uid)
|
||||||
|
&& allow_auto_update
|
||||||
&& interval > 0
|
&& interval > 0
|
||||||
{
|
{
|
||||||
logging!(
|
logging!(
|
||||||
|
|||||||
Reference in New Issue
Block a user