mirror of
https://github.com/veeso/termscp.git
synced 2026-09-27 06:21:22 -07:00
Notifications
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user