From e816e414341c426db2cfd4bd0d847731dbe3e6c0 Mon Sep 17 00:00:00 2001 From: Isaac Lins Date: Mon, 17 Nov 2025 15:38:43 +0100 Subject: [PATCH] feat: update version handling and dependencies for improved version checks --- Cargo.lock | 1 + psst-core/src/lib.rs | 4 ++++ psst-gui/Cargo.toml | 1 + psst-gui/src/data/update_checker.rs | 17 ++++++++++++++--- psst-gui/src/ui/preferences.rs | 2 +- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e2aafc7a..373e0c18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3940,6 +3940,7 @@ dependencies = [ "regex", "rustfm-scrobble", "sanitize_html", + "semver 1.0.26", "serde", "serde_json", "souvlaki", diff --git a/psst-core/src/lib.rs b/psst-core/src/lib.rs index d2e0dad2..679a69a9 100644 --- a/psst-core/src/lib.rs +++ b/psst-core/src/lib.rs @@ -3,6 +3,10 @@ use git_version::git_version; pub const GIT_VERSION: &str = git_version!(); +pub const BUILD_VERSION: &str = match option_env!("RELEASE_VERSION") { + Some(version) => version, + None => env!("CARGO_PKG_VERSION"), +}; pub const BUILD_TIME: &str = include!(concat!(env!("OUT_DIR"), "/build-time.txt")); pub const REMOTE_URL: &str = include!(concat!(env!("OUT_DIR"), "/remote-url.txt")); diff --git a/psst-gui/Cargo.toml b/psst-gui/Cargo.toml index 0a9d82d6..5836a60f 100644 --- a/psst-gui/Cargo.toml +++ b/psst-gui/Cargo.toml @@ -36,6 +36,7 @@ ureq = { version = "3.0.11", features = ["json", "socks-proxy"] } url = { version = "2.5.4" } infer = "0.19.0" base64 = "0.22.1" +semver = "1.0.26" # GUI druid = { git = "https://github.com/jpochyla/druid", branch = "psst", features = [ diff --git a/psst-gui/src/data/update_checker.rs b/psst-gui/src/data/update_checker.rs index 972ff610..b0044d47 100644 --- a/psst-gui/src/data/update_checker.rs +++ b/psst-gui/src/data/update_checker.rs @@ -1,4 +1,5 @@ use druid::{Data, Lens}; +use semver::Version; use serde::{Deserialize, Serialize}; use std::{ env, @@ -13,7 +14,7 @@ use std::process::Command; use url::Url; const GITHUB_API_URL: &str = "https://api.github.com/repos/isaaclins/psst/releases/latest"; -const CURRENT_VERSION: &str = env!("CARGO_PKG_VERSION"); +const CURRENT_VERSION: &str = psst_core::BUILD_VERSION; const UPDATE_CHECK_INTERVAL: Duration = Duration::from_secs(24 * 60 * 60); // 24 hours #[derive(Clone, Debug, Data, Serialize, Deserialize, PartialEq)] @@ -115,8 +116,18 @@ impl UpdateInfo { let remote = remote.trim_start_matches('v'); let current = current.trim_start_matches('v'); - // For date-based versions like "2025.11.15-abc1234" - // Just do a string comparison since they're chronologically ordered + if remote == current { + return false; + } + + if let (Ok(remote_semver), Ok(current_semver)) = + (Version::parse(remote), Version::parse(current)) + { + return remote_semver > current_semver; + } + + // For date-based versions like "2025.11.15-abc1234" just fall back to a string comparison; + // the lexical order preserves chronology when using ISO-style dates. remote > current } diff --git a/psst-gui/src/ui/preferences.rs b/psst-gui/src/ui/preferences.rs index 4bdde0a7..ebbe77dd 100644 --- a/psst-gui/src/ui/preferences.rs +++ b/psst-gui/src/ui/preferences.rs @@ -1498,7 +1498,7 @@ fn updates_tab_widget() -> impl Widget { .with_spacer(theme::grid(2.0)) .with_child(Label::new(format!( "Current Version: {}", - env!("CARGO_PKG_VERSION") + psst_core::BUILD_VERSION ))) .with_spacer(theme::grid(1.0)) .with_child(