Compare commits

..
Author SHA1 Message Date
❤是纱雾酱哟~andCopilot 09ea1b52e2 feat(updater): allow choosing the update download channel
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>
2026-11-22 16:24:08 +08:00
6 changed files with 66 additions and 20 deletions
+2 -2
View File
@@ -75,7 +75,7 @@
"react-dom": "19.3.1", "react-dom": "19.3.1",
"react-error-boundary": "6.1.6", "react-error-boundary": "6.1.6",
"react-hook-form": "^7.88.0", "react-hook-form": "^7.88.0",
"react-i18next": "18.0.3", "react-i18next": "18.0.1",
"react-markdown": "10.1.0", "react-markdown": "10.1.0",
"react-router": "^8.4.0", "react-router": "^8.4.0",
"rehype-raw": "^7.0.0", "rehype-raw": "^7.0.0",
@@ -116,7 +116,7 @@
"https-proxy-agent": "^9.1.0", "https-proxy-agent": "^9.1.0",
"husky": "^9.1.7", "husky": "^9.1.7",
"jiti": "^2.7.0", "jiti": "^2.7.0",
"knip": "6.47.0", "knip": "6.45.1",
"lint-staged": "^17.5.1", "lint-staged": "^17.5.1",
"sass": "^1.104.1", "sass": "^1.104.1",
"tar": "^7.5.22", "tar": "^7.5.22",
+10 -10
View File
@@ -284,8 +284,8 @@ importers:
specifier: ^7.88.0 specifier: ^7.88.0
version: 7.88.0(react@19.3.1) version: 7.88.0(react@19.3.1)
react-i18next: react-i18next:
specifier: 18.0.3 specifier: 18.0.1
version: 18.0.3(@types/react@19.3.0)(i18next@27.0.1(typescript@6.0.3))(react@19.3.1)(typescript@6.0.3) version: 18.0.1(@types/react@19.3.0)(i18next@27.0.1(typescript@6.0.3))(react@19.3.1)(typescript@6.0.3)
react-markdown: react-markdown:
specifier: 10.1.0 specifier: 10.1.0
version: 10.1.0(@types/react@19.3.0)(react@19.3.1)(supports-color@7.2.0) version: 10.1.0(@types/react@19.3.0)(react@19.3.1)(supports-color@7.2.0)
@@ -402,8 +402,8 @@ importers:
specifier: ^2.7.0 specifier: ^2.7.0
version: 2.7.0 version: 2.7.0
knip: knip:
specifier: 6.47.0 specifier: 6.45.1
version: 6.47.0 version: 6.45.1
lint-staged: lint-staged:
specifier: ^17.5.1 specifier: ^17.5.1
version: 17.5.1 version: 17.5.1
@@ -3345,8 +3345,8 @@ packages:
keyv@5.6.0: keyv@5.6.0:
resolution: {integrity: sha512-CYDD3SOtsHtyXeEORYRx2qBtpDJFjRTGXUtmNEMGyzYOKj1TE3tycdlho7kA1Ufx9OYWZzg52QFBGALTirzDSw==} resolution: {integrity: sha512-CYDD3SOtsHtyXeEORYRx2qBtpDJFjRTGXUtmNEMGyzYOKj1TE3tycdlho7kA1Ufx9OYWZzg52QFBGALTirzDSw==}
knip@6.47.0: knip@6.45.1:
resolution: {integrity: sha512-nYmQnk0YqDXIJrYViJz88c8xw3tBDkpuAmofo58EkVPnKr6DnRKYtf6oIqcGVHZvXDE+gtmFuYx277/QsWng+A==} resolution: {integrity: sha512-zp3zXKy2cZWiIttdlWU5fisKxVQaLSU6471ej0KGz1GdHdaHxpzTAO/LIyFNc3gU3v1W7LJaqvYumoO3l/u+6A==}
engines: {node: ^20.19.0 || >=22.12.0} engines: {node: ^20.19.0 || >=22.12.0}
hasBin: true hasBin: true
@@ -3792,8 +3792,8 @@ packages:
peerDependencies: peerDependencies:
react: ^16.8.0 || ^17 || ^18 || ^19 react: ^16.8.0 || ^17 || ^18 || ^19
react-i18next@18.0.3: react-i18next@18.0.1:
resolution: {integrity: sha512-S84rtVuaKuiRtoCOspbGEaDlFjka+KvK/A5YCOr4LQ41XF3iJOrJ5rqQTD/jJHFVUf6X1i4ZMN5PGGgpz8NN6g==} resolution: {integrity: sha512-kPWXI0E/lrPj3+/umcKNzYZVnWmEedLiamMzDIHfbs+5ANf6yzvlZsjKou8f7kaGkfMMDLIZBejV+4aSN1CyBw==}
engines: {node: '>=22'} engines: {node: '>=22'}
peerDependencies: peerDependencies:
'@types/react': '*' '@types/react': '*'
@@ -7297,7 +7297,7 @@ snapshots:
dependencies: dependencies:
'@keyv/serialize': 1.1.1 '@keyv/serialize': 1.1.1
knip@6.47.0: knip@6.45.1:
dependencies: dependencies:
formatly: 0.11.4 formatly: 0.11.4
get-tsconfig: 4.14.3 get-tsconfig: 4.14.3
@@ -7883,7 +7883,7 @@ snapshots:
dependencies: dependencies:
react: 19.3.1 react: 19.3.1
react-i18next@18.0.3(@types/react@19.3.0)(i18next@27.0.1(typescript@6.0.3))(react@19.3.1)(typescript@6.0.3): react-i18next@18.0.1(@types/react@19.3.0)(i18next@27.0.1(typescript@6.0.3))(react@19.3.1)(typescript@6.0.3):
dependencies: dependencies:
html-parse-stringify: 4.0.1 html-parse-stringify: 4.0.1
i18next: 27.0.1(typescript@6.0.3) i18next: 27.0.1(typescript@6.0.3)
+5
View File
@@ -112,6 +112,10 @@ pub struct IVerge {
pub auto_switch_selector_group: Option<bool>, pub auto_switch_selector_group: Option<bool>,
pub auto_check_update: Option<bool>, pub auto_check_update: Option<bool>,
/// `auto`, `github` or `github_proxy`
pub update_channel: Option<String>,
pub default_latency_test: Option<String>, pub default_latency_test: Option<String>,
pub default_latency_timeout: Option<i16>, pub default_latency_timeout: Option<i16>,
@@ -461,6 +465,7 @@ impl IVerge {
patch_opt_field!(self, patch, auto_close_connection); patch_opt_field!(self, patch, auto_close_connection);
patch_opt_field!(self, patch, auto_switch_selector_group); patch_opt_field!(self, patch, auto_switch_selector_group);
patch_opt_field!(self, patch, auto_check_update); 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_test);
patch_opt_field!(self, patch, default_latency_timeout); patch_opt_field!(self, patch, default_latency_timeout);
patch_opt_field!(self, patch, enable_auto_delay_detection); patch_opt_field!(self, patch, enable_auto_delay_detection);
+44 -8
View File
@@ -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 anyhow::{Context as _, Result};
use chrono::Utc; use chrono::Utc;
use clash_verge_logging::{Type, logging}; 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 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. /// A source delivering less than this per window is dropped for the next one.
const MIN_PROGRESS: u64 = 1024 * 1024; const MIN_PROGRESS: u64 = 1024 * 1024;
const PROGRESS_WINDOW: Duration = Duration::from_secs(30); const PROGRESS_WINDOW: Duration = Duration::from_secs(30);
/// The manifest's URL, then the other mirror, then GitHub itself. #[derive(Clone, Copy, PartialEq, Eq)]
fn download_sources(url: &tauri::Url) -> Vec<tauri::Url> { 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<tauri::Url> {
let origin = MIRRORS let origin = MIRRORS
.iter() .iter()
.find_map(|mirror| url.as_str().strip_prefix(mirror)) .find_map(|mirror| url.as_str().strip_prefix(mirror))
.unwrap_or(url.as_str()); .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()]; let mut sources = vec![url.clone()];
if origin.starts_with("https://github.com/") { if origin.starts_with("https://github.com/") {
let candidates = MIRRORS.iter().map(|mirror| format!("{mirror}{origin}")); let candidates = MIRRORS.iter().map(|mirror| format!("{mirror}{origin}"));
@@ -224,7 +252,7 @@ fn download_sources(url: &tauri::Url) -> Vec<tauri::Url> {
/// Tries every source with a throughput floor, then again stopping only on a stall, so a link /// Tries every source with a throughput floor, then again stopping only on a stall, so a link
/// that is slow everywhere still finishes. /// that is slow everywhere still finishes.
async fn download(update: &Update, on_event: impl Fn(DownloadEvent) + Sync) -> Result<Vec<u8>> { async fn download(update: &Update, on_event: impl Fn(DownloadEvent) + Sync) -> Result<Vec<u8>> {
let sources = download_sources(&update.download_url); let sources = download_sources(&update.download_url, UpdateChannel::current().await);
let mut last_error = None; let mut last_error = None;
for floor in [MIN_PROGRESS, 1] { for floor in [MIN_PROGRESS, 1] {
for url in &sources { for url in &sources {
@@ -282,7 +310,16 @@ impl SilentUpdater {
/// Checks the server; Windows receives `/LANG` to suppress the NSIS language dialog, /// Checks the server; Windows receives `/LANG` to suppress the NSIS language dialog,
/// see `packages/windows/installer.nsi`. /// see `packages/windows/installer.nsi`.
async fn check(app_handle: &tauri::AppHandle) -> Result<Option<Update>> { async fn check(app_handle: &tauri::AppHandle) -> Result<Option<Update>> {
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")] #[cfg(target_os = "windows")]
let updater_builder = { let updater_builder = {
let verge_lang = Config::verge().await.latest_arc().language.clone(); 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..."); logging!(info, Type::System, "Silent updater: checking for updates...");
let updater = app_handle.updater()?; let update = match Self::check(app_handle).await {
let update = match updater.check().await {
Ok(Some(update)) => update, Ok(Some(update)) => update,
Ok(None) => { Ok(None) => {
logging!(info, Type::System, "Silent updater: no update available"); logging!(info, Type::System, "Silent updater: no update available");
@@ -592,7 +628,7 @@ impl SilentUpdater {
} }
Err(e) => { Err(e) => {
logging!(warn, Type::System, "Silent updater: check failed: {e}"); logging!(warn, Type::System, "Silent updater: check failed: {e}");
return Err(e.into()); return Err(e);
} }
}; };
+1
View File
@@ -92,6 +92,7 @@ verge_registry! {
auto_close_connection => NoEffect; auto_close_connection => NoEffect;
auto_switch_selector_group => NoEffect; auto_switch_selector_group => NoEffect;
auto_check_update => NoEffect; auto_check_update => NoEffect;
update_channel => NoEffect;
default_latency_test => NoEffect; default_latency_test => NoEffect;
default_latency_timeout => NoEffect; default_latency_timeout => NoEffect;
enable_auto_delay_detection => NoEffect; enable_auto_delay_detection => NoEffect;
+4
View File
@@ -418,6 +418,8 @@ export type IVerge_Deserialize = {
auto_close_connection?: boolean | null auto_close_connection?: boolean | null
auto_switch_selector_group?: boolean | null auto_switch_selector_group?: boolean | null
auto_check_update?: boolean | null auto_check_update?: boolean | null
/** `auto`, `github` or `github_proxy` */
update_channel?: string | null
default_latency_test?: string | null default_latency_test?: string | null
default_latency_timeout?: number | null default_latency_timeout?: number | null
enable_auto_delay_detection?: boolean | null enable_auto_delay_detection?: boolean | null
@@ -509,6 +511,8 @@ export type IVerge_Serialize = {
auto_close_connection: boolean | null auto_close_connection: boolean | null
auto_switch_selector_group: boolean | null auto_switch_selector_group: boolean | null
auto_check_update: boolean | null auto_check_update: boolean | null
/** `auto`, `github` or `github_proxy` */
update_channel: string | null
default_latency_test: string | null default_latency_test: string | null
default_latency_timeout: number | null default_latency_timeout: number | null
enable_auto_delay_detection: boolean | null enable_auto_delay_detection: boolean | null