diff --git a/.gitignore b/.gitignore index c41cc9e..96ef6c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/target \ No newline at end of file +/target +Cargo.lock diff --git a/Cargo.lock b/Cargo.lock index cbdd877..a9a15cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2329,7 +2329,7 @@ dependencies = [ [[package]] name = "webhook_sender" -version = "1.2.0" +version = "1.2.2" dependencies = [ "eframe", "egui-notify", diff --git a/Cargo.toml b/Cargo.toml index 7fe2996..dc71ced 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "webhook_sender" -version = "1.2.1" +version = "1.2.2" edition = "2021" authors = ["Xanthus58 "] license = "MIT" diff --git a/src/app.rs b/src/app.rs index c62666d..7166b32 100644 --- a/src/app.rs +++ b/src/app.rs @@ -17,9 +17,6 @@ pub struct MyApp { webhook: String, username: String, avatar_url: String, - update_check: i32, - update_available: bool, - update_notification: bool, embed: bool, embed_title: String, embed_footer: String, @@ -28,6 +25,7 @@ pub struct MyApp { embed_thumbnail: String, embed_field_title: String, embed_field_value: String, + update_delay: i32, } impl Default for MyApp { @@ -42,9 +40,6 @@ impl Default for MyApp { webhook: "".to_string(), username: "Xans Webhook Sender".to_string(), avatar_url: "https://cdn.discordapp.com/avatars/292971545956188160/eab559efa07f0f3dd13d21ac5f26c4ce.png?size=1024".to_string(), - update_check: 0, - update_available: false, - update_notification: false, embed: false, embed_title: "".to_string(), embed_footer: "".to_string(), @@ -53,6 +48,7 @@ impl Default for MyApp { embed_thumbnail: "".to_string(), embed_field_title: "".to_string(), embed_field_value: "".to_string(), + update_delay: 0, } } } @@ -205,45 +201,32 @@ impl eframe::App for MyApp { } } - if ui.checkbox(&mut self.embed, "Embed?").clicked() { - println!("\nEmbed: {}", &self.embed); - cb(self.toasts.success("Embed toggled!")); + //Various UI elements and checks for application updates + let update = ui.button("Update"); + if update.hovered() { + egui::show_tooltip(ui.ctx(), egui::Id::new("my_tooltip"), |ui| { + ui.label("Download any updates if available"); + }); } - }); - - //Various UI elements and checks for application updates - if self.update_check == 0 { - cb(self.toasts.info("Checking for updates... Please wait")); - println!("\nChecking for updates..."); - } - if self.update_check == 100 { - self.update_check = 110; - let x = update(); - if x.is_err() { - self.update_available = true + if update.clicked() { + cb(self.toasts.info("Updating... See console for logs")); + println!("\nChecking for updates..."); + self.update_delay = 5 } - else { - cb(self.toasts.info("No update available")); - println!("\nNo update available"); + if self.update_delay < 101 && self.update_delay > 2 { + self.update_delay += 1; + } + if self.update_delay == 100 { + download_update().expect("Failed to download update"); + self.update_delay = 110; } - } - else if self.update_check < 105 && !self.update_available { - self.update_check += 1; - } - if self.update_available { - ui.separator(); - if !self.update_notification { - cb(self.toasts.info("Update available!")); - println!("\nUpdate available!"); - self.update_notification = true; + //UI elements for the embed toggle + if ui.checkbox(&mut self.embed, "Embed?").clicked() { + println!("\nEmbed: {}", &self.embed); + cb(self.toasts.success("Embed toggled!")); } - ui.label("There is an update available!"); - ui.horizontal(|ui| { - ui.label("You can download the update from"); - ui.hyperlink_to("here", "https://github.com/Xanthus58/webhook_sender/releases/latest"); - }); - } + }); self.toasts.show(ctx); // Requests to render toasts }); }); diff --git a/src/app/api_handler.rs b/src/app/api_handler.rs index d653271..a3fd79b 100644 --- a/src/app/api_handler.rs +++ b/src/app/api_handler.rs @@ -92,12 +92,13 @@ pub async fn send_embed( Ok(()) } -pub fn update() -> Result<(), Box> { +pub fn download_update() -> Result<(), Box> { let status = self_update::backends::github::Update::configure() .repo_owner("Xanthus58") .repo_name("webhook_sender") .bin_name("github") .show_download_progress(true) + .no_confirm(true) .current_version(cargo_crate_version!()) .build()? .update()?;