Skip to content

Commit

Permalink
upgrade self_update
Browse files Browse the repository at this point in the history
  • Loading branch information
Woife5 committed Sep 17, 2023
1 parent c7c0d72 commit 96b9b5c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 55 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.4.2

- update `self_update` dependency, which is now able to replace running files on Windows.

# 0.4.1

- add a dependency for `tar` decompression
Expand Down
29 changes: 25 additions & 4 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
name = "kopfrechner"
authors = ["Wolfgang Schwendtbauer"]
repository = "https://github.com/Woife5/kopfrechner"
version = "0.4.1"
version = "0.4.2"
edition = "2021"

[dependencies]
colored = "2.0.4"
dialoguer = "0.10.4"
rand = "0.8.5"
self_update = { version = "0.37.0", features = [ "archive-zip", "archive-tar", "compression-zip-deflate" ] }
self_update = { version = "0.38.0", features = [ "archive-zip", "archive-tar", "compression-zip-deflate" ] }

# Cargo-dist config
[profile.dist]
Expand Down
51 changes: 2 additions & 49 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
pub mod main_menu;
pub mod modes;

use colored::Colorize;
use dialoguer::{theme::ColorfulTheme, Select};
use main_menu::{get_mode, get_modes, Mode};
use modes::{multiplication, number_tower};
use self_update::cargo_crate_version;
use modes::{multiplication, number_tower, update};

pub fn run() {
let mode = Select::with_theme(&ColorfulTheme::default())
Expand All @@ -22,54 +20,9 @@ pub fn run() {
match mode {
Mode::Multiply => multiplication::prepare_and_run(),
Mode::NumberTower => number_tower::prepare_and_run(),
Mode::Update => do_update(),
Mode::Update => update::do_update(),
Mode::Exit => std::process::exit(0),
}

println!();
}

fn do_update() {
println!("Checking for updates...");

let updater = self_update::backends::github::Update::configure()
.repo_owner("woife5")
.repo_name("kopfrechner")
.bin_name("kopfrechner")
.show_download_progress(true)
.current_version(cargo_crate_version!())
.build();

if let Err(e) = updater {
println!("Failed to check for updates: {}", e);
return;
}

let status = updater.unwrap().update();

if let Err(e) = status {
println!("Failed to check for updates: {}", e);
return;
}

let status = status.unwrap();

if status.updated() {
println!("Updated to version {}", status.version().blue().bold());
println!("The program will exit now, please restart it to use the new version.");

#[cfg(windows)]
println!(
"{}",
"Rerun the update check to clean up any temporary files."
.yellow()
.bold()
);

let _ = std::io::stdin().read_line(&mut String::new());
std::process::exit(0);
}

#[cfg(windows)]
println!("{}", "Temp directory has been cleaned up.".yellow().bold());
}
1 change: 1 addition & 0 deletions src/modes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::io::{self, Write};

pub mod multiplication;
pub mod number_tower;
pub mod update;

fn get_number_input(prompt: String) -> Option<usize> {
loop {
Expand Down
36 changes: 36 additions & 0 deletions src/modes/update.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use colored::Colorize;
use self_update::cargo_crate_version;

pub fn do_update() {
println!("Checking for updates...");

let updater = self_update::backends::github::Update::configure()
.repo_owner("woife5")
.repo_name("kopfrechner")
.bin_name("kopfrechner")
.show_download_progress(true)
.current_version(cargo_crate_version!())
.build();

if let Err(e) = updater {
println!("Failed to check for updates: {}", e);
return;
}

let status = updater.unwrap().update();

if let Err(e) = status {
println!("Failed to check for updates: {}", e);
return;
}

let status = status.unwrap();

if status.updated() {
println!("Updated to version {}", status.version().blue().bold());
println!("The program will exit now, please restart it to use the new version.");

let _ = std::io::stdin().read_line(&mut String::new());
std::process::exit(0);
}
}

0 comments on commit 96b9b5c

Please sign in to comment.