From 09ea1b52e24fdbf79388b00263343218a704100b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9D=A4=E6=98=AF=E7=BA=B1=E9=9B=BE=E9=85=B1=E5=93=9F?= =?UTF-8?q?=EF=BD=9E?= <49941141+Dragon1573@users.noreply.github.com> Date: Sun, 22 Nov 2026 16:24:08 +0800 Subject: [PATCH] feat(updater): allow choosing the update download channel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a `update_channel` verge setting. `auto` keeps the configured endpoints with mirror fallbacks; `github` checks and downloads from GitHub only; `github_proxy` does the same through the Core's mixed port. The background check now goes through the same channel-aware check. Refs: clash-verge-rev/clash-verge-rev#8706 Assisted-by: Claude:claude-opus-5.5 [gh-stack] [codegraph] Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: ❤是纱雾酱哟~ <49941141+Dragon1573@users.noreply.github.com> --- src-tauri/src/config/verge.rs | 5 ++++ src-tauri/src/core/updater.rs | 52 +++++++++++++++++++++++++++++------ src-tauri/src/feat/effects.rs | 1 + src/services/bindings.ts | 4 +++ 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/config/verge.rs b/src-tauri/src/config/verge.rs index 26d11c21f..81163571a 100644 --- a/src-tauri/src/config/verge.rs +++ b/src-tauri/src/config/verge.rs @@ -112,6 +112,10 @@ pub struct IVerge { pub auto_switch_selector_group: Option, pub auto_check_update: Option, + + /// `auto`, `github` or `github_proxy` + pub update_channel: Option, + pub default_latency_test: Option, pub default_latency_timeout: Option, @@ -461,6 +465,7 @@ impl IVerge { patch_opt_field!(self, patch, auto_close_connection); patch_opt_field!(self, patch, auto_switch_selector_group); patch_opt_field!(self, patch, auto_check_update); + patch_opt_field!(self, patch, update_channel); patch_opt_field!(self, patch, default_latency_test); patch_opt_field!(self, patch, default_latency_timeout); patch_opt_field!(self, patch, enable_auto_delay_detection); diff --git a/src-tauri/src/core/updater.rs b/src-tauri/src/core/updater.rs index 25a938bc4..234e305e5 100644 --- a/src-tauri/src/core/updater.rs +++ b/src-tauri/src/core/updater.rs @@ -1,4 +1,8 @@ -use crate::{config::Config, singleton, utils::dirs}; +use crate::{ + config::{Config, MixedPort}, + singleton, + utils::dirs, +}; use anyhow::{Context as _, Result}; use chrono::Utc; use clash_verge_logging::{Type, logging}; @@ -197,16 +201,40 @@ pub enum DownloadEvent { } const MIRRORS: [&str; 2] = ["https://update.hwdns.net/", "https://gh-proxy.org/"]; +const GITHUB_ENDPOINT: &str = + "https://github.com/clash-verge-rev/clash-verge-rev/releases/download/updater/update.json"; /// A source delivering less than this per window is dropped for the next one. const MIN_PROGRESS: u64 = 1024 * 1024; const PROGRESS_WINDOW: Duration = Duration::from_secs(30); -/// The manifest's URL, then the other mirror, then GitHub itself. -fn download_sources(url: &tauri::Url) -> Vec { +#[derive(Clone, Copy, PartialEq, Eq)] +enum UpdateChannel { + /// The configured endpoints with mirror fallbacks. + Auto, + Github, + /// GitHub through the Core's mixed port. + GithubProxy, +} + +impl UpdateChannel { + async fn current() -> Self { + match Config::verge().await.latest_arc().update_channel.as_deref() { + Some("github") => Self::Github, + Some("github_proxy") => Self::GithubProxy, + _ => Self::Auto, + } + } +} + +/// The manifest's URL, then the other mirror, then GitHub itself; only GitHub outside `Auto`. +fn download_sources(url: &tauri::Url, channel: UpdateChannel) -> Vec { let origin = MIRRORS .iter() .find_map(|mirror| url.as_str().strip_prefix(mirror)) .unwrap_or(url.as_str()); + if channel != UpdateChannel::Auto { + return vec![tauri::Url::parse(origin).unwrap_or_else(|_| url.clone())]; + } let mut sources = vec![url.clone()]; if origin.starts_with("https://github.com/") { let candidates = MIRRORS.iter().map(|mirror| format!("{mirror}{origin}")); @@ -224,7 +252,7 @@ fn download_sources(url: &tauri::Url) -> Vec { /// Tries every source with a throughput floor, then again stopping only on a stall, so a link /// that is slow everywhere still finishes. async fn download(update: &Update, on_event: impl Fn(DownloadEvent) + Sync) -> Result> { - let sources = download_sources(&update.download_url); + let sources = download_sources(&update.download_url, UpdateChannel::current().await); let mut last_error = None; for floor in [MIN_PROGRESS, 1] { for url in &sources { @@ -282,7 +310,16 @@ impl SilentUpdater { /// Checks the server; Windows receives `/LANG` to suppress the NSIS language dialog, /// see `packages/windows/installer.nsi`. async fn check(app_handle: &tauri::AppHandle) -> Result> { - let updater_builder = app_handle.updater_builder(); + let channel = UpdateChannel::current().await; + let mut updater_builder = app_handle.updater_builder(); + if channel != UpdateChannel::Auto { + updater_builder = updater_builder.endpoints(vec![tauri::Url::parse(GITHUB_ENDPOINT)?])?; + } + if channel == UpdateChannel::GithubProxy { + let port = MixedPort::desired().await; + // The resulting `Update` keeps this proxy for its download. + updater_builder = updater_builder.proxy(tauri::Url::parse(&format!("http://127.0.0.1:{port}"))?); + } #[cfg(target_os = "windows")] let updater_builder = { let verge_lang = Config::verge().await.latest_arc().language.clone(); @@ -583,8 +620,7 @@ impl SilentUpdater { logging!(info, Type::System, "Silent updater: checking for updates..."); - let updater = app_handle.updater()?; - let update = match updater.check().await { + let update = match Self::check(app_handle).await { Ok(Some(update)) => update, Ok(None) => { logging!(info, Type::System, "Silent updater: no update available"); @@ -592,7 +628,7 @@ impl SilentUpdater { } Err(e) => { logging!(warn, Type::System, "Silent updater: check failed: {e}"); - return Err(e.into()); + return Err(e); } }; diff --git a/src-tauri/src/feat/effects.rs b/src-tauri/src/feat/effects.rs index 61cfba67c..575865256 100644 --- a/src-tauri/src/feat/effects.rs +++ b/src-tauri/src/feat/effects.rs @@ -92,6 +92,7 @@ verge_registry! { auto_close_connection => NoEffect; auto_switch_selector_group => NoEffect; auto_check_update => NoEffect; + update_channel => NoEffect; default_latency_test => NoEffect; default_latency_timeout => NoEffect; enable_auto_delay_detection => NoEffect; diff --git a/src/services/bindings.ts b/src/services/bindings.ts index acfa5855d..0aa677c13 100644 --- a/src/services/bindings.ts +++ b/src/services/bindings.ts @@ -418,6 +418,8 @@ export type IVerge_Deserialize = { auto_close_connection?: boolean | null auto_switch_selector_group?: boolean | null auto_check_update?: boolean | null + /** `auto`, `github` or `github_proxy` */ + update_channel?: string | null default_latency_test?: string | null default_latency_timeout?: number | null enable_auto_delay_detection?: boolean | null @@ -509,6 +511,8 @@ export type IVerge_Serialize = { auto_close_connection: boolean | null auto_switch_selector_group: boolean | null auto_check_update: boolean | null + /** `auto`, `github` or `github_proxy` */ + update_channel: string | null default_latency_test: string | null default_latency_timeout: number | null enable_auto_delay_detection: boolean | null