diff options
-rw-r--r-- | src-tauri/Cargo.lock | 156 | ||||
-rw-r--r-- | src-tauri/Cargo.toml | 2 | ||||
-rw-r--r-- | src-tauri/src/github/release_notes.rs | 33 |
3 files changed, 184 insertions, 7 deletions
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index d9407e49..0cc15796 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -54,6 +54,15 @@ dependencies = [ ] [[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] name = "anyhow" version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -65,6 +74,7 @@ version = "1.1.0" dependencies = [ "anyhow", "async-recursion", + "chrono", "json5", "libthermite", "powershell_script", @@ -346,6 +356,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] +name = "chrono" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-integer", + "num-traits", + "time 0.1.45", + "wasm-bindgen", + "winapi", +] + +[[package]] name = "cipher" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -386,6 +411,16 @@ dependencies = [ ] [[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + +[[package]] name = "color_quant" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -583,6 +618,50 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" [[package]] +name = "cxx" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4a41a86530d0fe7f5d9ea779916b7cadd2d4f9add748b99c2c029cbbdfaf453" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06416d667ff3e3ad2df1cd8cd8afae5da26cf9cec4d0825040f88b5ca659a2f0" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "820a9a2af1669deeef27cb271f476ffd196a2c4b6731336011e0ba63e2c7cf71" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a08a6e2fcc370a089ad3b4aaf54db3b1b4cee38ddabce5896b33eb693275f470" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] name = "darling" version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1377,6 +1456,30 @@ dependencies = [ ] [[package]] +name = "iana-time-zone" +version = "0.1.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +dependencies = [ + "cxx", + "cxx-build", +] + +[[package]] name = "ico" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1647,6 +1750,15 @@ dependencies = [ ] [[package]] +name = "link-cplusplus" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" +dependencies = [ + "cc", +] + +[[package]] name = "lock_api" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1696,7 +1808,7 @@ dependencies = [ "dirs-next", "objc-foundation", "objc_id", - "time", + "time 0.3.17", ] [[package]] @@ -2371,7 +2483,7 @@ dependencies = [ "indexmap", "line-wrap", "serde", - "time", + "time 0.3.17", "xml-rs", ] @@ -2794,6 +2906,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] +name = "scratch" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" + +[[package]] name = "security-framework" version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2938,7 +3056,7 @@ dependencies = [ "serde", "serde_json", "thiserror", - "time", + "time 0.3.17", "url", "uuid 1.2.2", ] @@ -3411,7 +3529,7 @@ dependencies = [ "tauri-utils", "tempfile", "thiserror", - "time", + "time 0.3.17", "tokio", "url", "uuid 1.2.2", @@ -3458,7 +3576,7 @@ dependencies = [ "sha2", "tauri-utils", "thiserror", - "time", + "time 0.3.17", "uuid 1.2.2", "walkdir", ] @@ -3594,6 +3712,15 @@ dependencies = [ ] [[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] name = "terminal_size" version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3640,6 +3767,17 @@ dependencies = [ [[package]] name = "time" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + +[[package]] +name = "time" version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" @@ -3974,6 +4112,12 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" @@ -4540,7 +4684,7 @@ dependencies = [ "hmac", "pbkdf2", "sha1", - "time", + "time 0.3.17", "zstd", ] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index be27418e..1eea9941 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -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 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] |