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

93
src-tauri/Cargo.lock generated
View File

@@ -479,7 +479,7 @@ dependencies = [
"http-body 0.4.6", "http-body 0.4.6",
"hyper 0.14.32", "hyper 0.14.32",
"itoa", "itoa",
"matchit", "matchit 0.7.3",
"memchr", "memchr",
"mime", "mime",
"percent-encoding", "percent-encoding",
@@ -494,25 +494,23 @@ dependencies = [
[[package]] [[package]]
name = "axum" name = "axum"
version = "0.7.9" version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" checksum = "8a18ed336352031311f4e0b4dd2ff392d4fbb370777c9d18d7fc9d7359f73871"
dependencies = [ dependencies = [
"async-trait", "axum-core 0.5.5",
"axum-core 0.4.5",
"bytes", "bytes",
"futures-util", "futures-util",
"http 1.3.1", "http 1.3.1",
"http-body 1.0.1", "http-body 1.0.1",
"http-body-util", "http-body-util",
"itoa", "itoa",
"matchit", "matchit 0.8.4",
"memchr", "memchr",
"mime", "mime",
"percent-encoding", "percent-encoding",
"pin-project-lite", "pin-project-lite",
"rustversion", "serde_core",
"serde",
"sync_wrapper 1.0.2", "sync_wrapper 1.0.2",
"tower 0.5.2", "tower 0.5.2",
"tower-layer", "tower-layer",
@@ -538,19 +536,17 @@ dependencies = [
[[package]] [[package]]
name = "axum-core" name = "axum-core"
version = "0.4.5" version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" checksum = "59446ce19cd142f8833f856eb31f3eb097812d1479ab224f54d72428ca21ea22"
dependencies = [ dependencies = [
"async-trait",
"bytes", "bytes",
"futures-util", "futures-core",
"http 1.3.1", "http 1.3.1",
"http-body 1.0.1", "http-body 1.0.1",
"http-body-util", "http-body-util",
"mime", "mime",
"pin-project-lite", "pin-project-lite",
"rustversion",
"sync_wrapper 1.0.2", "sync_wrapper 1.0.2",
"tower-layer", "tower-layer",
"tower-service", "tower-service",
@@ -1289,22 +1285,23 @@ dependencies = [
[[package]] [[package]]
name = "console-api" name = "console-api"
version = "0.8.1" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8030735ecb0d128428b64cd379809817e620a40e5001c54465b99ec5feec2857" checksum = "e8599749b6667e2f0c910c1d0dff6901163ff698a52d5a39720f61b5be4b20d3"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"prost 0.13.5", "prost 0.14.1",
"prost-types 0.13.5", "prost-types 0.14.1",
"tonic 0.12.3", "tonic 0.14.2",
"tonic-prost",
"tracing-core", "tracing-core",
] ]
[[package]] [[package]]
name = "console-subscriber" name = "console-subscriber"
version = "0.4.1" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6539aa9c6a4cd31f4b1c040f860a1eac9aa80e7df6b05d506a6e7179936d6a01" checksum = "fb4915b7d8dd960457a1b6c380114c2944f728e7c65294ab247ae6b6f1f37592"
dependencies = [ dependencies = [
"console-api", "console-api",
"crossbeam-channel", "crossbeam-channel",
@@ -1313,14 +1310,14 @@ dependencies = [
"hdrhistogram", "hdrhistogram",
"humantime", "humantime",
"hyper-util", "hyper-util",
"prost 0.13.5", "prost 0.14.1",
"prost-types 0.13.5", "prost-types 0.14.1",
"serde", "serde",
"serde_json", "serde_json",
"thread_local", "thread_local",
"tokio", "tokio",
"tokio-stream", "tokio-stream",
"tonic 0.12.3", "tonic 0.14.2",
"tracing", "tracing",
"tracing-core", "tracing-core",
"tracing-subscriber", "tracing-subscriber",
@@ -4131,6 +4128,12 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94"
[[package]]
name = "matchit"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
[[package]] [[package]]
name = "md-5" name = "md-5"
version = "0.10.6" version = "0.10.6"
@@ -5613,12 +5616,12 @@ dependencies = [
[[package]] [[package]]
name = "prost" name = "prost"
version = "0.13.5" version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2796faa41db3ec313a31f7624d9286acf277b52de526150b7e69f3debf891ee5" checksum = "7231bd9b3d3d33c86b58adbac74b5ec0ad9f496b19d22801d773636feaa95f3d"
dependencies = [ dependencies = [
"bytes", "bytes",
"prost-derive 0.13.5", "prost-derive 0.14.1",
] ]
[[package]] [[package]]
@@ -5636,9 +5639,9 @@ dependencies = [
[[package]] [[package]]
name = "prost-derive" name = "prost-derive"
version = "0.13.5" version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d" checksum = "9120690fafc389a67ba3803df527d0ec9cbbc9cc45e4cc20b332996dfb672425"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"itertools 0.14.0", "itertools 0.14.0",
@@ -5658,11 +5661,11 @@ dependencies = [
[[package]] [[package]]
name = "prost-types" name = "prost-types"
version = "0.13.5" version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52c2c1bf36ddb1a1c396b3601a3cec27c2462e45f07c386894ec3ccf5332bd16" checksum = "b9b4db3d6da204ed77bb26ba83b6122a73aeb2e87e25fbf7ad2e84c4ccbf8f72"
dependencies = [ dependencies = [
"prost 0.13.5", "prost 0.14.1",
] ]
[[package]] [[package]]
@@ -8240,13 +8243,12 @@ dependencies = [
[[package]] [[package]]
name = "tonic" name = "tonic"
version = "0.12.3" version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877c5b330756d856ffcc4553ab34a5684481ade925ecc54bcd1bf02b1d0d4d52" checksum = "eb7613188ce9f7df5bfe185db26c5814347d110db17920415cf2fbcad85e7203"
dependencies = [ dependencies = [
"async-stream",
"async-trait", "async-trait",
"axum 0.7.9", "axum 0.8.6",
"base64 0.22.1", "base64 0.22.1",
"bytes", "bytes",
"h2 0.4.12", "h2 0.4.12",
@@ -8258,11 +8260,11 @@ dependencies = [
"hyper-util", "hyper-util",
"percent-encoding", "percent-encoding",
"pin-project", "pin-project",
"prost 0.13.5", "socket2 0.6.1",
"socket2 0.5.10", "sync_wrapper 1.0.2",
"tokio", "tokio",
"tokio-stream", "tokio-stream",
"tower 0.4.13", "tower 0.5.2",
"tower-layer", "tower-layer",
"tower-service", "tower-service",
"tracing", "tracing",
@@ -8281,6 +8283,17 @@ dependencies = [
"tonic 0.10.2", "tonic 0.10.2",
] ]
[[package]]
name = "tonic-prost"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66bd50ad6ce1252d87ef024b3d64fe4c3cf54a86fb9ef4c631fdd0ded7aeaa67"
dependencies = [
"bytes",
"prost 0.14.1",
"tonic 0.14.2",
]
[[package]] [[package]]
name = "tonic-web" name = "tonic-web"
version = "0.10.2" version = "0.10.2"
@@ -8329,11 +8342,15 @@ checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-util", "futures-util",
"indexmap 2.12.0",
"pin-project-lite", "pin-project-lite",
"slab",
"sync_wrapper 1.0.2", "sync_wrapper 1.0.2",
"tokio", "tokio",
"tokio-util",
"tower-layer", "tower-layer",
"tower-service", "tower-service",
"tracing",
] ]
[[package]] [[package]]

View File

@@ -42,7 +42,7 @@ serde = { version = "1.0.228", features = ["derive"] }
reqwest = { version = "0.12.24", features = ["json", "cookies"] } reqwest = { version = "0.12.24", features = ["json", "cookies"] }
regex = "1.12.2" regex = "1.12.2"
sysproxy = { git = "https://github.com/clash-verge-rev/sysproxy-rs" } sysproxy = { git = "https://github.com/clash-verge-rev/sysproxy-rs" }
tauri = { version = "2.9.1", features = [ tauri = { version = "2.9.2", features = [
"protocol-asset", "protocol-asset",
"devtools", "devtools",
"tray-icon", "tray-icon",
@@ -77,7 +77,7 @@ backoff = { version = "0.4.0", features = ["tokio"] }
compact_str = { version = "0.9.0", features = ["serde"] } compact_str = { version = "0.9.0", features = ["serde"] }
tauri-plugin-http = "2.5.4" tauri-plugin-http = "2.5.4"
flexi_logger = "0.31.7" flexi_logger = "0.31.7"
console-subscriber = { version = "0.4.1", optional = true } console-subscriber = { version = "0.5.0", optional = true }
tauri-plugin-devtools = { version = "2.0.1" } tauri-plugin-devtools = { version = "2.0.1" }
tauri-plugin-mihomo = { git = "https://github.com/clash-verge-rev/tauri-plugin-mihomo" } tauri-plugin-mihomo = { git = "https://github.com/clash-verge-rev/tauri-plugin-mihomo" }
clash_verge_logger = { git = "https://github.com/clash-verge-rev/clash-verge-logger" } clash_verge_logger = { git = "https://github.com/clash-verge-rev/clash-verge-logger" }

View File

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

View File

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

View File

@@ -341,7 +341,8 @@ export const ProfileItem = (props: Props) => {
try { try {
// 调用后端更新(后端会自动处理回退逻辑) // 调用后端更新(后端会自动处理回退逻辑)
await updateProfile(itemData.uid, option); const payload = Object.keys(option).length > 0 ? option : undefined;
await updateProfile(itemData.uid, payload);
// 更新成功,刷新列表 // 更新成功,刷新列表
mutate("getProfiles"); mutate("getProfiles");