Add option to show/hide notifications. See #95

This commit is contained in:
Federico Terzi 2020-04-15 18:56:39 +02:00
parent 7907980447
commit 72f34b401b
3 changed files with 20 additions and 3 deletions

View File

@ -66,6 +66,8 @@ fn default_restore_clipboard_delay() -> i32 { 300 }
fn default_exclude_default_entries() -> bool {false}
fn default_secure_input_watcher_enabled() -> bool {true}
fn default_secure_input_notification() -> bool {true}
fn default_show_notifications() -> bool {true}
fn default_show_icon() -> bool {true}
fn default_secure_input_watcher_interval() -> i32 {5000}
fn default_matches() -> Vec<Match> { Vec::new() }
fn default_global_vars() -> Vec<MatchVariable> { Vec::new() }
@ -156,6 +158,12 @@ pub struct Configs {
#[serde(default = "default_exclude_default_entries")]
pub exclude_default_entries: bool,
#[serde(default = "default_show_notifications")]
pub show_notifications: bool,
#[serde(default = "default_show_icon")]
pub show_icon: bool,
#[serde(default = "default_matches")]
pub matches: Vec<Match>,
@ -205,6 +213,8 @@ impl Configs {
validate_field!(result, self.secure_input_watcher_enabled, default_secure_input_watcher_enabled());
validate_field!(result, self.secure_input_watcher_interval, default_secure_input_watcher_interval());
validate_field!(result, self.secure_input_notification, default_secure_input_notification());
validate_field!(result, self.show_notifications, default_show_notifications());
validate_field!(result, self.show_icon, default_show_icon());
result
}

View File

@ -257,8 +257,12 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa
let mut enabled_ref = self.enabled.borrow_mut();
*enabled_ref = status;
let config = self.config_manager.default_config();
if config.show_notifications {
self.ui_manager.notify(message);
}
}
fn on_passive(&self) {
let config = self.config_manager.active_config();
@ -351,7 +355,8 @@ impl <'a, S: KeyboardManager, C: ClipboardManager,
SystemEvent::SecureInputEnabled(app_name, path) => {
info!("SecureInput has been acquired by {}, preventing espanso from working correctly. Full path: {}", app_name, path);
if self.config_manager.default_config().secure_input_notification {
let config = self.config_manager.default_config();
if config.secure_input_notification && config.show_notifications {
self.ui_manager.notify_delay(&format!("{} has activated SecureInput. Espanso won't work until you disable it.", app_name), 5000);
}
},

View File

@ -350,7 +350,9 @@ fn daemon_background(receive_channel: Receiver<Event>, config_set: ConfigSet, is
let config_manager = RuntimeConfigManager::new(config_set, system_manager);
let ui_manager = ui::get_uimanager();
if config_manager.default_config().show_notifications {
ui_manager.notify("espanso is running!");
}
let clipboard_manager = clipboard::get_manager();