Notifications

This commit is contained in:
veeso
2021-09-28 12:44:51 +02:00
parent f0a91b1579
commit 198d421ab0
31 changed files with 1363 additions and 198 deletions
+63 -1
View File
@@ -27,7 +27,7 @@
*/
// Locals
use crate::config::{
params::UserConfig,
params::{UserConfig, DEFAULT_NOTIFICATION_TRANSFER_THRESHOLD},
serialization::{deserialize, serialize, SerializerError, SerializerErrorKind},
};
use crate::filetransfer::FileTransferProtocol;
@@ -254,6 +254,37 @@ impl ConfigClient {
};
}
/// ### get_notifications
///
/// Get value of `notifications`
pub fn get_notifications(&self) -> bool {
self.config.user_interface.notifications.unwrap_or(true)
}
/// ### set_notifications
///
/// Set new value for `notifications`
pub fn set_notifications(&mut self, value: bool) {
self.config.user_interface.notifications = Some(value);
}
/// ### get_notification_threshold
///
/// Get value of `notification_threshold`
pub fn get_notification_threshold(&self) -> u64 {
self.config
.user_interface
.notification_threshold
.unwrap_or(DEFAULT_NOTIFICATION_TRANSFER_THRESHOLD)
}
/// ### set_notification_threshold
///
/// Set new value for `notification_threshold`
pub fn set_notification_threshold(&mut self, value: u64) {
self.config.user_interface.notification_threshold = Some(value);
}
// SSH Keys
/// ### save_ssh_key
@@ -657,6 +688,37 @@ mod tests {
assert_eq!(client.get_remote_file_fmt(), None);
}
#[test]
fn test_system_config_notifications() {
let tmp_dir: TempDir = TempDir::new().ok().unwrap();
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
let mut client: ConfigClient = ConfigClient::new(cfg_path.as_path(), key_path.as_path())
.ok()
.unwrap();
assert_eq!(client.get_notifications(), true); // Null ?
client.set_notifications(true);
assert_eq!(client.get_notifications(), true);
client.set_notifications(false);
assert_eq!(client.get_notifications(), false);
}
#[test]
fn test_system_config_remote_notification_threshold() {
let tmp_dir: TempDir = TempDir::new().ok().unwrap();
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
let mut client: ConfigClient = ConfigClient::new(cfg_path.as_path(), key_path.as_path())
.ok()
.unwrap();
assert_eq!(
client.get_notification_threshold(),
DEFAULT_NOTIFICATION_TRANSFER_THRESHOLD
); // Null ?
client.set_notification_threshold(1024);
assert_eq!(client.get_notification_threshold(), 1024);
client.set_notification_threshold(64);
assert_eq!(client.get_notification_threshold(), 64);
}
#[test]
fn test_system_config_ssh_keys() {
let tmp_dir: TempDir = TempDir::new().ok().unwrap();