fix: profile auto refresh #5274

This commit is contained in:
Slinetrac
2025-11-01 17:08:17 +08:00
committed by Tunglies
parent b3b8eeb577
commit 9dc50da167
6 changed files with 74 additions and 50 deletions

View File

@@ -180,7 +180,7 @@ pub async fn create_profile(item: PrfItem, file_data: Option<String>) -> CmdResu
/// 更新配置文件
#[tauri::command]
pub async fn update_profile(index: String, option: Option<PrfOption>) -> CmdResult {
match feat::update_profile(index, option, Some(true)).await {
match feat::update_profile(index, option, Some(true), Some(true)).await {
Ok(_) => Ok(()),
Err(e) => {
log::error!(target: "app", "{}", e);

View File

@@ -492,7 +492,7 @@ impl Timer {
is_current
);
feat::update_profile(uid.clone(), None, Some(is_current)).await
feat::update_profile(uid.clone(), None, Some(is_current), None).await
})
.await
{

View File

@@ -23,7 +23,10 @@ pub async fn toggle_proxy_profile(profile_index: String) {
}
}
async fn should_update_profile(uid: String) -> Result<Option<(String, Option<PrfOption>)>> {
async fn should_update_profile(
uid: String,
ignore_auto_update: bool,
) -> Result<Option<(String, Option<PrfOption>)>> {
let profiles = Config::profiles().await;
let profiles = profiles.latest_ref();
let item = profiles.get_item(&uid)?;
@@ -35,11 +38,12 @@ async fn should_update_profile(uid: String) -> Result<Option<(String, Option<Prf
} else if item.url.is_none() {
log::warn!(target: "app", "[订阅更新] {uid} 缺少URL无法更新");
bail!("failed to get the profile item url");
} else if !item
.option
.as_ref()
.and_then(|o| o.allow_auto_update)
.unwrap_or(true)
} else if !ignore_auto_update
&& !item
.option
.as_ref()
.and_then(|o| o.allow_auto_update)
.unwrap_or(true)
{
log::info!(target: "app", "[订阅更新] {} 禁止自动更新,跳过更新", uid);
Ok(None)
@@ -123,11 +127,13 @@ pub async fn update_profile(
uid: String,
option: Option<PrfOption>,
auto_refresh: Option<bool>,
ignore_auto_update: Option<bool>,
) -> Result<()> {
logging!(info, Type::Config, "[订阅更新] 开始更新订阅 {}", uid);
let auto_refresh = auto_refresh.unwrap_or(true);
let ignore_auto_update = ignore_auto_update.unwrap_or(false);
let url_opt = should_update_profile(uid.clone()).await?;
let url_opt = should_update_profile(uid.clone(), ignore_auto_update).await?;
let should_refresh = match url_opt {
Some((url, opt)) => {