add option in config to disable notifications

This commit is contained in:
MedzikUser 2022-01-24 20:48:24 +01:00
parent af6830da0c
commit 5edeac60fd
4 changed files with 16 additions and 3 deletions

View File

@ -10,10 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased] ## [Unreleased]
### CLI ### CLI
- create default config, if not exits - 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 ### Library
- rustls - change openssl to rustls
## [0.1.0] - 2022-01-23 ## [0.1.0] - 2022-01-23
### CLI ### CLI

View File

@ -1,2 +1,5 @@
[imgur] [imgur]
id = '3e3ce0d7ac14d56' id = '3e3ce0d7ac14d56'
[notification]
enable = true

View File

@ -14,6 +14,8 @@ use imgurs::api::ImageInfo;
use notify_rust::Notification; use notify_rust::Notification;
use std::process::exit; use std::process::exit;
use crate::config::toml::parse;
pub fn print_image_info(i: ImageInfo, notify: bool) { pub fn print_image_info(i: ImageInfo, notify: bool) {
let d = UNIX_EPOCH + Duration::from_secs(i.data.datetime.try_into().unwrap()); let d = UNIX_EPOCH + Duration::from_secs(i.data.datetime.try_into().unwrap());
let datetime = DateTime::<Utc>::from(d); let datetime = DateTime::<Utc>::from(d);
@ -48,7 +50,9 @@ pub fn print_image_info(i: ImageInfo, notify: bool) {
info!("Bandwidth {}", i.data.bandwidth); info!("Bandwidth {}", i.data.bandwidth);
info!("Link {}", i.data.link); info!("Link {}", i.data.link);
if notify { let config = parse().unwrap();
if notify && config.notification.enable {
Notification::new() Notification::new()
.summary("Imgurs") .summary("Imgurs")
.body(&format!("Uploaded {}", i.data.link)) .body(&format!("Uploaded {}", i.data.link))

View File

@ -6,6 +6,7 @@ use toml::from_str;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Config { pub struct Config {
pub imgur: ConfigImgur, pub imgur: ConfigImgur,
pub notification: ConfigNotification
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
@ -13,6 +14,11 @@ pub struct ConfigImgur {
pub id: String, pub id: String,
} }
#[derive(Debug, Deserialize)]
pub struct ConfigNotification {
pub enable: bool,
}
pub fn parse() -> Result<Config, String> { pub fn parse() -> Result<Config, String> {
let config_dir = config_dir().unwrap(); let config_dir = config_dir().unwrap();
let file_dir: String = String::from(config_dir.to_string_lossy()) + "/imgurs/config.toml"; let file_dir: String = String::from(config_dir.to_string_lossy()) + "/imgurs/config.toml";