Skip to content

Commit

Permalink
Add update improvements
Browse files Browse the repository at this point in the history
Added an update button and overall improved the update process.

Fixed the issue where application will freeze if a new version is detected.
  • Loading branch information
Zephira58 committed Sep 13, 2022
1 parent b50474c commit 24e4796
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 44 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/target
Cargo.lock
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "webhook_sender"
version = "1.2.1"
version = "1.2.2"
edition = "2021"
authors = ["Xanthus58 <xanthus58@protonmail.com>"]
license = "MIT"
Expand Down
63 changes: 23 additions & 40 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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(),
Expand All @@ -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,
}
}
}
Expand Down Expand Up @@ -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
});
});
Expand Down
3 changes: 2 additions & 1 deletion src/app/api_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ pub async fn send_embed(
Ok(())
}

pub fn update() -> Result<(), Box<dyn (::std::error::Error)>> {
pub fn download_update() -> Result<(), Box<dyn (::std::error::Error)>> {
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()?;
Expand Down

0 comments on commit 24e4796

Please sign in to comment.