diff --git a/CHANGELOG.md b/CHANGELOG.md index d5edd9f..33b5844 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### CLI - create default config, if not exits -- when the image uploaded, send a notification +- when the image uploaded, send a notification (can be turn off in config) ### Library -- rustls +- change openssl to rustls ## [0.1.0] - 2022-01-23 ### CLI diff --git a/config.toml b/config.toml index d773f4f..eff69ff 100644 --- a/config.toml +++ b/config.toml @@ -1,2 +1,5 @@ [imgur] id = '3e3ce0d7ac14d56' + +[notification] +enable = true diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 8320d29..559fff6 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -14,6 +14,8 @@ use imgurs::api::ImageInfo; use notify_rust::Notification; use std::process::exit; +use crate::config::toml::parse; + pub fn print_image_info(i: ImageInfo, notify: bool) { let d = UNIX_EPOCH + Duration::from_secs(i.data.datetime.try_into().unwrap()); let datetime = DateTime::::from(d); @@ -48,7 +50,9 @@ pub fn print_image_info(i: ImageInfo, notify: bool) { info!("Bandwidth {}", i.data.bandwidth); info!("Link {}", i.data.link); - if notify { + let config = parse().unwrap(); + + if notify && config.notification.enable { Notification::new() .summary("Imgurs") .body(&format!("Uploaded {}", i.data.link)) diff --git a/src/config/toml.rs b/src/config/toml.rs index 9a83a4c..133b2ef 100644 --- a/src/config/toml.rs +++ b/src/config/toml.rs @@ -6,6 +6,7 @@ use toml::from_str; #[derive(Debug, Deserialize)] pub struct Config { pub imgur: ConfigImgur, + pub notification: ConfigNotification } #[derive(Debug, Deserialize)] @@ -13,6 +14,11 @@ pub struct ConfigImgur { pub id: String, } +#[derive(Debug, Deserialize)] +pub struct ConfigNotification { + pub enable: bool, +} + pub fn parse() -> Result { let config_dir = config_dir().unwrap(); let file_dir: String = String::from(config_dir.to_string_lossy()) + "/imgurs/config.toml";