Skip to content

Commit

Permalink
fix update checK
Browse files Browse the repository at this point in the history
  • Loading branch information
ari-party committed Jun 21, 2024
1 parent 6c3c532 commit 8b1a724
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 30 deletions.
4 changes: 4 additions & 0 deletions packages/mtc-artillery-overlay/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 80,
"tabWidth": 2
}
25 changes: 25 additions & 0 deletions packages/mtc-artillery-overlay/src/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 packages/mtc-artillery-overlay/src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ serde_json = "1"
octocrab = "0.38.0"
open = "5.1.4"
native-dialog = "0.7.0"
tokio = { version = "1.38.0", features = ["full"] }
version-compare = "0.2.0"

[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
Expand Down
59 changes: 30 additions & 29 deletions packages/mtc-artillery-overlay/src/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,37 @@

use std::env;
use native_dialog::MessageDialog;
use tauri::Manager;
use tauri::{ Manager };
use version_compare::{ compare_to, Cmp };

const REPO_OWNER: &'static str = "ari-party";
const REPO_NAME: &'static str = "mtc-artillery";

async fn check_for_updates(current_version: String) {
let octocrab = octocrab::instance();
let binding = octocrab.repos(REPO_OWNER, REPO_NAME);
let release_handler = binding.releases();
let latest_release = release_handler.get_latest().await.unwrap();

let version_parts: Vec<&str> = latest_release.tag_name.split("v").collect();
let latest_version = version_parts.last().unwrap();

if compare_to(latest_version, current_version, Cmp::Gt).unwrap() {
let confirmation = MessageDialog::new()
.set_type(native_dialog::MessageType::Info)
.set_title("Artillery overlay")
.set_text(
"A new version is available, do you wish to visit the releases page?"
)
.show_confirm()
.unwrap();

if confirmation {
let _ = open::that("https://overlay.artillery-calculator.com");
}
}
}

fn main() {
dotenv::dotenv().ok();

Expand All @@ -20,37 +46,12 @@ fn main() {
.unwrap_or_else(|_| "production".into());

if tauri_env == "production" {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.spawn(check_for_updates(app.package_info().version.to_string()));

let _ = main.eval(
"window.location.replace('https://artillery-calculator.com')"
);

tauri::async_runtime::spawn(async {
let octocrab = octocrab::instance();
let binding = octocrab.repos(REPO_OWNER, REPO_NAME);
let release_handler = binding.releases();
let latest_release = release_handler.get_latest().await.unwrap();

let version_parts: Vec<&str> = latest_release.tag_name
.split("v")
.collect();
let latest_version = version_parts.last().unwrap();
let current_version = tauri::VERSION;

if *latest_version != current_version {
let confirmation = MessageDialog::new()
.set_type(native_dialog::MessageType::Info)
.set_title("Artillery overlay")
.set_text(
"A new version is available, do you wish to visit the releases page?"
)
.show_confirm()
.unwrap();

if confirmation {
let _ = open::that("https://overlay.artillery-calculator.com");
}
}
});
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion packages/mtc-artillery-overlay/src/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"package": {
"productName": "mtc-artillery-overlay",
"version": "0.2.0"
"version": "0.2.1"
},
"tauri": {
"allowlist": {
Expand Down

0 comments on commit 8b1a724

Please sign in to comment.