Fully implemented tokio runtime. Added build script. Executable has an icon.

This commit is contained in:
2022-08-16 08:06:06 -07:00
parent 0b940aea70
commit 91579d333e
6 changed files with 41 additions and 20 deletions

View File

@@ -2,6 +2,7 @@
name = "town-of-us-updater" name = "town-of-us-updater"
version = "1.0.0" version = "1.0.0"
edition = "2021" edition = "2021"
build = "src/build.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -13,3 +14,7 @@ dirs = "4.0.0"
reqwest = {version = "0.11.11", features = ["blocking"]} reqwest = {version = "0.11.11", features = ["blocking"]}
iui = "0.3.0" iui = "0.3.0"
serde_json = "1.0" serde_json = "1.0"
tokio = {version="1", features=["full"]}
[build-dependencies]
embed-resource = "1.6"

BIN
assets/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

BIN
assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

1
assets/main.rc Normal file
View File

@@ -0,0 +1 @@
1 ICON "icon.ico"

5
src/build.rs Normal file
View File

@@ -0,0 +1,5 @@
extern crate embed_resource;
fn main() {
embed_resource::compile("assets/main.rc");
}

View File

@@ -63,7 +63,7 @@ fn unmod_among_us_folder(folder_path: &Path) {
fs::remove_dir_all(mono_path).unwrap_or_default(); fs::remove_dir_all(mono_path).unwrap_or_default();
} }
fn get_latest_updater_version() -> (String, String) { async fn get_latest_updater_version() -> Result<(String, String), reqwest::Error> {
let version = env!("CARGO_PKG_VERSION"); let version = env!("CARGO_PKG_VERSION");
let mut cur_vers = version.split('.'); let mut cur_vers = version.split('.');
@@ -71,10 +71,9 @@ fn get_latest_updater_version() -> (String, String) {
let minor_ver = cur_vers.next().unwrap().parse::<i32>().unwrap(); let minor_ver = cur_vers.next().unwrap().parse::<i32>().unwrap();
let patch_ver = cur_vers.next().unwrap().parse::<i32>().unwrap(); let patch_ver = cur_vers.next().unwrap().parse::<i32>().unwrap();
let body = reqwest::blocking::get( let body =
"https://git.dormedas.com/api/v1/repos/dormedas/town-of-us-updater/releases", reqwest::get("https://git.dormedas.com/api/v1/repos/dormedas/town-of-us-updater/releases");
); let root: serde_json::Value = serde_json::from_str(&body.await?.text().await?).unwrap();
let root: serde_json::Value = serde_json::from_str(&body.unwrap().text().unwrap()).unwrap();
for i in root.as_array().unwrap() { for i in root.as_array().unwrap() {
let tag_name = i["tag_name"].as_str().unwrap(); let tag_name = i["tag_name"].as_str().unwrap();
@@ -109,13 +108,15 @@ fn get_latest_updater_version() -> (String, String) {
} }
} }
(String::from("no"), String::from("yes")) Ok((String::from("no"), String::from("yes")))
} }
fn main() { #[tokio::main]
async fn main() {
let version = env!("CARGO_PKG_VERSION"); let version = env!("CARGO_PKG_VERSION");
println!("Updater Version: {}", version); println!("Updater Version: {}", version);
let _version_check_thread_handle = thread::spawn(move || get_latest_updater_version()); get_latest_updater_version().await.unwrap();
//let _version_check_thread_handle = thread::spawn(move || get_latest_updater_version());
// CREATE PROGRAM DIRECTORY // CREATE PROGRAM DIRECTORY
let mut data_path = dirs::data_dir().unwrap(); let mut data_path = dirs::data_dir().unwrap();
@@ -177,7 +178,9 @@ fn main() {
let among_us_version = let among_us_version =
determine_among_us_version(String::from(among_us_folder.to_str().unwrap())).unwrap(); determine_among_us_version(String::from(among_us_folder.to_str().unwrap())).unwrap();
let ver_url: (String, String, bool) = let ver_url: (String, String, bool) =
determine_town_of_us_url(among_us_version.to_string().clone()).unwrap(); determine_town_of_us_url(among_us_version.to_string().clone())
.await
.unwrap();
let version_smash = format!( let version_smash = format!(
"{}-{}", "{}-{}",
@@ -266,11 +269,15 @@ fn main() {
// for i in iter { // for i in iter {
let existing_ver_smash = i.unwrap().file_name(); let existing_ver_smash = i.unwrap().file_name();
let mut ver_smash_split = existing_ver_smash.to_str().unwrap().split("-"); let mut ver_smash_split = existing_ver_smash.to_str().unwrap().split("-");
let auv = ver_smash_split.next().unwrap();
let button_string: String = format!( let button_string: String = format!(
"Among Us {} ToU {}", "Among Us {} Town of Us {}",
ver_smash_split.next().unwrap(), auv,
ver_smash_split.next().unwrap() ver_smash_split.next().unwrap()
); );
let mut group_vbox = VerticalBox::new(&ui);
let mut group = Group::new(&ui, auv.clone());
let mut button = Button::new(&ui, button_string.as_str()); let mut button = Button::new(&ui, button_string.as_str());
button.on_clicked(&ui, { button.on_clicked(&ui, {
let ui = ui.clone(); let ui = ui.clone();
@@ -284,7 +291,9 @@ fn main() {
btn.set_text(&ui, "Launching Among Us..."); btn.set_text(&ui, "Launching Among Us...");
} }
}); });
vbox.append(&ui, button, LayoutStrategy::Stretchy); group_vbox.append(&ui, button, LayoutStrategy::Stretchy);
group.set_child(&ui, group_vbox);
vbox.append(&ui, group, LayoutStrategy::Stretchy);
println!("{}", existing_ver_smash.clone().to_str().unwrap()); println!("{}", existing_ver_smash.clone().to_str().unwrap());
} }
} }
@@ -321,13 +330,14 @@ fn main() {
} }
// Returns (Version, URL) // Returns (Version, URL)
fn determine_town_of_us_url(among_us_version: String) -> Option<(String, String, bool)> { async fn determine_town_of_us_url(among_us_version: String) -> Option<(String, String, bool)> {
let markdown = reqwest::blocking::get( let markdown =
"https://raw.githubusercontent.com/eDonnes124/Town-Of-Us-R/master/README.md", reqwest::get("https://raw.githubusercontent.com/eDonnes124/Town-Of-Us-R/master/README.md")
) .await
.unwrap() .unwrap()
.text() .text()
.unwrap(); .await
.unwrap();
let mut line = markdown.find(&among_us_version); let mut line = markdown.find(&among_us_version);
let mut line_offset = 0; let mut line_offset = 0;
let mut official_compatibility = false; let mut official_compatibility = false;