Skip to content

Commit

Permalink
feat: Threshold before showing update notification (#98)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
GeckoEidechse authored Dec 1, 2022
1 parent d61f3fe commit 0ffbf97
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 7 deletions.
156 changes: 150 additions & 6 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ tauri-plugin-store = { git = "https://github.com/tauri-apps/tauri-plugin-store",
json5 = "0.4.1"
# Async recursion for recursive mod install
async-recursion = "1.0.0"
# For parsing timestamps
chrono = "0.4.23"

[features]
# by default Tauri runs in production mode
Expand Down
33 changes: 32 additions & 1 deletion src-tauri/src/github/release_notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 0ffbf97

Please sign in to comment.