diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 5704d398..27494ce3 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -1,9 +1,12 @@ -use crate::constants; -use crate::error::Result; +use std::time::Duration; + use reqwest::Client as Reqwest; use serde::{Deserialize, Serialize}; use tauri::{Invoke, Runtime}; +use crate::constants; +use crate::error::Result; + pub fn get_handlers() -> Box) + Send + Sync> { Box::new(tauri::generate_handler![ get_current_exe_dir, @@ -67,6 +70,7 @@ async fn get_latest_version() -> Result { Reqwest::builder() .build()? .get("https://hoyo-gacha.lgou2w.com/release/latest") + .timeout(Duration::from_secs(15)) .send() .await? .json::() @@ -93,6 +97,7 @@ async fn update_app(latest_version: LatestVersion) -> Result<()> { .build()? .get("https://hoyo-gacha.lgou2w.com/release/download") .query(&[("id", latest_version.id.to_string())]) + .timeout(Duration::from_secs(15)) .send() .await? .error_for_status()?; diff --git a/src/components/common/VersionChecker.tsx b/src/components/common/VersionChecker.tsx index 86fca6cd..ac28e1b5 100644 --- a/src/components/common/VersionChecker.tsx +++ b/src/components/common/VersionChecker.tsx @@ -47,14 +47,31 @@ export default function VersionChecker () { }, [latestVersion.data, setBusy]) if (!version.data) { - return 版本更新不可用 + return ( + 版本更新不可用 + ) } - if (latestVersion.isLoading) return 加载中... - if (latestVersion.isError) return 检查最新版本失败 + if (latestVersion.isLoading) { + return ( + 检查更新中... + ) + } + + if (latestVersion.isError) { + return ( + + 检查最新版本失败:{latestVersion.error.message} + + ) + } const needUpdate = isNeedUpdate(version.data, latestVersion.data) - if (!needUpdate) return 已是最新版本 + if (!needUpdate) { + return ( + 已是最新版本 + ) + } return (