Skip to content

Commit

Permalink
make update notifications an optional feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jhspetersson committed Sep 26, 2023
1 parent cf418ef commit 2bd38d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ license = "MIT/Apache-2.0"
edition = "2021"

[features]
default = ["users"]
default = ["users", "update-notifications"]
update-notifications = ["dep:update-informer"]

[dependencies]
bytecount = "0.6"
Expand Down Expand Up @@ -43,7 +44,7 @@ sha3 = "0.10"
svg = "0.13"
toml = "0.8"
tree_magic_mini = { version = "3.0", features = [ "tree_magic_db" ] }
update-informer = "1.1.0"
update-informer = { version = "1.1.0", optional = true }
wana_kana = "3.0"
zip = "0.6"

Expand Down
21 changes: 13 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ use std::env;
use std::io::{IsTerminal, stdout};
use std::path::PathBuf;
use std::process::ExitCode;
#[cfg(feature = "update-notifications")]
use std::time::Duration;

use nu_ansi_term::Color::*;
use rustyline::error::ReadlineError;
use rustyline::DefaultEditor;
#[cfg(feature = "update-notifications")]
use update_informer::{registry, Check};

mod config;
Expand Down Expand Up @@ -163,16 +165,19 @@ fn main() -> ExitCode {

config.save();

if let Some(exit_value) = exit_value {
return ExitCode::from(exit_value);
}
#[cfg(feature = "update-notifications")]
if stdout().is_terminal() {
let name = env!("CARGO_PKG_NAME");
let version = env!("CARGO_PKG_VERSION");
let informer = update_informer::new(registry::Crates, name, version).interval(Duration::from_secs(60 * 60));

let name = env!("CARGO_PKG_NAME");
let version = env!("CARGO_PKG_VERSION");
let informer = update_informer::new(registry::Crates, name, version).interval(Duration::from_secs(60 * 60));
if let Some(version) = informer.check_version().ok().flatten() {
println!("\nNew version is available! : {}", version);
}
}

if let Some(version) = informer.check_version().ok().flatten() {
println!("\n A New version is available! : {}", version);
if let Some(exit_value) = exit_value {
return ExitCode::from(exit_value);
}

ExitCode::SUCCESS
Expand Down

0 comments on commit 2bd38d5

Please sign in to comment.