aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/github/release_notes.rs
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2022-12-01 23:19:09 +0100
committerGitHub <noreply@github.com>2022-12-01 23:19:09 +0100
commit0ffbf9762dd10a1cf327901afa3792128f04b892 (patch)
treee5a1d2e3d30b451cbc0c41914617e3fde8596d07 /src-tauri/src/github/release_notes.rs
parentd61f3fe1b0c9f4461d33f289b3100465d77999ad (diff)
downloadFlightCore-0ffbf9762dd10a1cf327901afa3792128f04b892.tar.gz
FlightCore-0ffbf9762dd10a1cf327901afa3792128f04b892.zip
feat: Threshold before showing update notification (#98)
* feat: Threshold before showing update notification This way we don't spam the end-user with an update notification before an update is fully build and released * fix: Push missing dependencies * fix: Adjust delay to 2 hours
Diffstat (limited to 'src-tauri/src/github/release_notes.rs')
-rw-r--r--src-tauri/src/github/release_notes.rs33
1 files changed, 32 insertions, 1 deletions
diff --git a/src-tauri/src/github/release_notes.rs b/src-tauri/src/github/release_notes.rs
index 69669244..f139ead5 100644
--- a/src-tauri/src/github/release_notes.rs
+++ b/src-tauri/src/github/release_notes.rs
@@ -52,7 +52,38 @@ pub async fn check_is_flightcore_outdated() -> Result<bool, String> {
let version = format!("v{}", version);
// TODO: This shouldn't be a string compare but promper semver compare
- Ok(version != newest_release_version)
+ let is_outdated = version != newest_release_version;
+
+ // If outdated, check how new the update is
+ if is_outdated {
+ // Extract release date from JSON
+ let release_date = json_response
+ .get("published_at")
+ .and_then(|value| value.as_str())
+ .unwrap();
+
+ // Time to wait (2h) h * m * s
+ let threshold_seconds = 2 * 60 * 60;
+
+ // Get current time
+ let current_time = chrono::Utc::now();
+
+ // Get latest release time from GitHub API response
+ let result = chrono::DateTime::parse_from_rfc3339(release_date)
+ .unwrap()
+ .with_timezone(&chrono::Utc);
+
+ // Check if current time is outside of threshold
+ let diff = current_time - result;
+ if diff.num_seconds() < threshold_seconds {
+ // User would be outdated but the newest release is recent
+ // therefore we do not wanna show outdated warning.
+ return Ok(false);
+ }
+ return Ok(true);
+ }
+
+ Ok(is_outdated)
}
#[tauri::command]