From 198ac543553588ccca9abe14d56a332002c74645 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Thu, 7 May 2026 21:07:55 +0800 Subject: [PATCH] feat: add GitHub proxy endpoints for faster update checks Add hwdns.net and gh-proxy.org as proxy fallbacks before direct GitHub access, with 10s timeout per endpoint. Significantly improves update check speed in regions with slow GitHub connectivity. --- crates/dbx-core/src/update.rs | 40 +++++++++++++++++++++++------------ src-tauri/tauri.conf.json | 2 ++ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/crates/dbx-core/src/update.rs b/crates/dbx-core/src/update.rs index 4767d5ad53..49ce0e18ba 100644 --- a/crates/dbx-core/src/update.rs +++ b/crates/dbx-core/src/update.rs @@ -1,6 +1,10 @@ use serde::{Deserialize, Serialize}; -const LATEST_JSON_URL: &str = "https://github.com/t8y2/dbx/releases/latest/download/latest.json"; +const LATEST_JSON_URLS: &[&str] = &[ + "https://update.hwdns.net/https://github.com/t8y2/dbx/releases/latest/download/latest.json", + "https://gh-proxy.org/https://github.com/t8y2/dbx/releases/latest/download/latest.json", + "https://github.com/t8y2/dbx/releases/latest/download/latest.json", +]; const RELEASE_URL_PREFIX: &str = "https://github.com/t8y2/dbx/releases/tag/v"; #[derive(Debug, Deserialize)] @@ -21,18 +25,28 @@ pub struct UpdateInfo { } pub async fn fetch_latest_release() -> Result { - let client = reqwest::Client::new(); - client - .get(LATEST_JSON_URL) - .header(reqwest::header::USER_AGENT, "dbx-update-checker") - .send() - .await - .map_err(|e| format!("Failed to check updates: {e}"))? - .error_for_status() - .map_err(|e| format!("Failed to check updates: {e}"))? - .json::() - .await - .map_err(|e| format!("Failed to parse update response: {e}")) + let client = reqwest::Client::builder() + .timeout(std::time::Duration::from_secs(10)) + .build() + .map_err(|e| format!("Failed to create HTTP client: {e}"))?; + let mut last_err = String::new(); + for url in LATEST_JSON_URLS { + match client + .get(*url) + .header(reqwest::header::USER_AGENT, "dbx-update-checker") + .send() + .await + .and_then(|r| r.error_for_status()) + { + Ok(resp) => { + return resp.json::().await.map_err(|e| format!("Failed to parse update response: {e}")); + } + Err(e) => { + last_err = format!("{e}"); + } + } + } + Err(format!("Failed to check updates: {last_err}")) } pub fn build_update_info(release: TauriRelease, current_version: &str) -> UpdateInfo { diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 811ac26762..6e16b0b092 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -41,6 +41,8 @@ "updater": { "pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDkxNEYyMzE3QkJCNkM3REYKUldUZng3YTdGeU5Qa1NnTUZCRVhJVkxsOWZKQWFPVCtacUgySlNlcjRDU2RmZElCQnphd25pYUMK", "endpoints": [ + "https://update.hwdns.net/https://github.com/t8y2/dbx/releases/latest/download/latest.json", + "https://gh-proxy.org/https://github.com/t8y2/dbx/releases/latest/download/latest.json", "https://github.com/t8y2/dbx/releases/latest/download/latest.json" ] }