Skip to content

Commit

Permalink
chore: update version check
Browse files Browse the repository at this point in the history
  • Loading branch information
lgou2w committed Jul 13, 2024
1 parent 8326dd8 commit b044669
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
@@ -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<R: Runtime>() -> Box<dyn Fn(Invoke<R>) + Send + Sync> {
Box::new(tauri::generate_handler![
get_current_exe_dir,
Expand Down Expand Up @@ -67,6 +70,7 @@ async fn get_latest_version() -> Result<LatestVersion> {
Reqwest::builder()
.build()?
.get("https://hoyo-gacha.lgou2w.com/release/latest")
.timeout(Duration::from_secs(15))
.send()
.await?
.json::<LatestVersion>()
Expand All @@ -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()?;
Expand Down
25 changes: 21 additions & 4 deletions src/components/common/VersionChecker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,31 @@ export default function VersionChecker () {
}, [latestVersion.data, setBusy])

if (!version.data) {
return <Typography component="span" variant="body2" color="warning">版本更新不可用</Typography>
return (
<Typography component="span" variant="body2" color="warning">版本更新不可用</Typography>
)
}

if (latestVersion.isLoading) return <Typography component="span" variant="body2">加载中...</Typography>
if (latestVersion.isError) return <Typography component="span" variant="body2" color="error">检查最新版本失败</Typography>
if (latestVersion.isLoading) {
return (
<Typography component="span" variant="body2" color="secondary">检查更新中...</Typography>
)
}

if (latestVersion.isError) {
return (
<Typography component="span" variant="body2" color="error">
检查最新版本失败:{latestVersion.error.message}
</Typography>
)
}

const needUpdate = isNeedUpdate(version.data, latestVersion.data)
if (!needUpdate) return <Typography component="span" variant="body2" color="error">已是最新版本</Typography>
if (!needUpdate) {
return (
<Typography component="span" variant="body2" color="error">已是最新版本</Typography>
)
}

return (
<Button size="small" color="info"
Expand Down
2 changes: 1 addition & 1 deletion src/components/setting/SettingAbout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function SettingAbout () {
</Link>
<br />
当前版本:<Version variant="inherit" />
&nbsp;
<br />
<VersionChecker />
</Typography>
</Stack>
Expand Down

0 comments on commit b044669

Please sign in to comment.