5 Commits

Author SHA1 Message Date
97cdf4829a push to 2.3 2022-11-28 19:23:30 -08:00
7244c24fe4 Fix sorting 2022-11-28 19:20:05 -08:00
7f1a6c6bc1 Bump to 2.2.0 2022-11-14 18:20:32 -08:00
856cffd740 No timeouts while downloading 2022-11-14 18:15:24 -08:00
686d24f7b5 Hotfix: Fix initialization of mod if Among Us path is known 2022-09-26 19:02:17 -07:00
3 changed files with 41 additions and 21 deletions

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "town-of-us-updater" name = "town-of-us-updater"
version = "2.0.0" version = "2.3.0"
edition = "2021" edition = "2021"
build = "src/build.rs" build = "src/build.rs"

View File

@@ -1,3 +1,4 @@
use crate::AmongUsVersion;
use crate::AppData; use crate::AppData;
use druid::{ use druid::{
widget::*, BoxConstraints, Env, Event, EventCtx, FileDialogOptions, LayoutCtx, LifeCycle, widget::*, BoxConstraints, Env, Event, EventCtx, FileDialogOptions, LayoutCtx, LifeCycle,
@@ -44,14 +45,22 @@ impl AmongUsLauncherWidget {
// Iterate first to find labels: // Iterate first to find labels:
let mut flexbox_array: Vec<druid::widget::Flex<AppData>> = Vec::new(); let mut flexbox_array: Vec<druid::widget::Flex<AppData>> = Vec::new();
let mut auv_array: Vec<String> = Vec::new(); let mut auv_array: Vec<AmongUsVersion> = Vec::new();
for i in &collection { for i in &collection {
let existing_ver_smash = i.as_ref().unwrap().file_name(); let existing_ver_smash = i.as_ref().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 among_us_version = AmongUsVersion::from(ver_smash_split.next().unwrap());
if !auv_array.contains(&auv.to_string()) { if !auv_array.contains(&among_us_version) {
let label_text = format!("Among Us {}", auv); auv_array.push(among_us_version);
}
}
auv_array.sort();
for among_us_version in &auv_array {
println!("{}", among_us_version);
let label_text = format!("Among Us {}", among_us_version);
let flex: druid::widget::Flex<AppData> = druid::widget::Flex::column() let flex: druid::widget::Flex<AppData> = druid::widget::Flex::column()
.with_flex_child( .with_flex_child(
druid::widget::Label::new(label_text.as_str()).with_text_size(24.0), druid::widget::Label::new(label_text.as_str()).with_text_size(24.0),
@@ -59,8 +68,6 @@ impl AmongUsLauncherWidget {
) )
.with_default_spacer(); .with_default_spacer();
flexbox_array.push(flex); flexbox_array.push(flex);
auv_array.push(auv.to_string());
}
} }
println!("Installs list:"); println!("Installs list:");
@@ -68,12 +75,12 @@ impl AmongUsLauncherWidget {
for i in collection { for i in collection {
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 among_us_version = AmongUsVersion::from(ver_smash_split.next().unwrap());
let button_string: String = let button_string: String =
format!("Town of Us {}", ver_smash_split.next().unwrap()); format!("Town of Us {}", ver_smash_split.next().unwrap());
for (index, j) in auv_array.iter().enumerate() { for (index, j) in auv_array.iter().enumerate() {
if j == auv { if j == &among_us_version {
let mut clone: PathBuf = PathBuf::from(data.installs_path.clone()); let mut clone: PathBuf = PathBuf::from(data.installs_path.clone());
clone.push(existing_ver_smash.clone()); clone.push(existing_ver_smash.clone());
@@ -106,6 +113,8 @@ impl AmongUsLauncherWidget {
} }
} }
flexbox_array.reverse();
for i in flexbox_array { for i in flexbox_array {
flex.add_flex_child(i, 1.0); flex.add_flex_child(i, 1.0);
} }
@@ -128,6 +137,11 @@ impl Widget<AppData> for AmongUsLauncherWidget {
self.build_widget(data); self.build_widget(data);
ctx.children_changed(); ctx.children_changed();
} }
Event::KeyDown(evt) => {
if evt.code == druid::Code::F5 {
ctx.submit_command(ATTEMPT_INSTALL);
}
}
_ => { _ => {
self.root.event(ctx, event, data, env); self.root.event(ctx, event, data, env);
} }
@@ -141,7 +155,7 @@ impl Widget<AppData> for AmongUsLauncherWidget {
self.root.update(ctx, data, env); self.root.update(ctx, data, env);
if old_data.among_us_path.is_empty() && !data.among_us_path.is_empty() { if old_data.among_us_path.is_empty() && !data.among_us_path.is_empty() {
ctx.submit_command(ATTEMPT_INSTALL); ctx.submit_command(ATTEMPT_INSTALL);
println!("Detect Stuff"); // println!("Detect Stuff");
} }
// println!("Update!"); // println!("Update!");
self.build_widget(data); self.build_widget(data);

View File

@@ -121,10 +121,13 @@ impl AppDelegate<AppData> for Delegate {
fn window_added( fn window_added(
&mut self, &mut self,
_id: WindowId, _id: WindowId,
_data: &mut AppData, data: &mut AppData,
_env: &Env, _env: &Env,
_ctx: &mut DelegateCtx, ctx: &mut DelegateCtx,
) { ) {
if !data.among_us_path.is_empty() {
ctx.submit_command(ATTEMPT_INSTALL);
}
} }
fn command( fn command(
&mut self, &mut self,
@@ -198,10 +201,12 @@ impl AppDelegate<AppData> for Delegate {
"Downloading Town of Us... Please be patient! [{}]", "Downloading Town of Us... Please be patient! [{}]",
ver_url.1.clone() ver_url.1.clone()
); );
let zip = reqwest::blocking::get(ver_url.1.clone()) let client = reqwest::blocking::Client::builder()
.unwrap() .timeout(None)
.bytes() .build()
.unwrap(); .unwrap();
let zip_request = client.get(ver_url.1.clone()).build().unwrap();
let zip = client.execute(zip_request).unwrap().bytes().unwrap();
fs::write(download_path.clone(), zip).unwrap(); fs::write(download_path.clone(), zip).unwrap();
} }
@@ -228,6 +233,7 @@ impl AppDelegate<AppData> for Delegate {
); );
} }
} }
data.initialized = !data.initialized;
return Handled::Yes; return Handled::Yes;
} }