From 3114c7b7ffe580869c18d6d363eea11e521f4b7a Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Fri, 6 Sep 2019 22:30:20 +0200 Subject: [PATCH] Add basic linux notification support --- src/main.rs | 4 +++- src/ui/linux.rs | 25 +++++++++++++++++++++++++ src/ui/mod.rs | 20 ++++++++++++-------- 3 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 src/ui/linux.rs diff --git a/src/main.rs b/src/main.rs index b4204f1..dca6129 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use crate::matcher::Matcher; use crate::matcher::scrolling::ScrollingMatcher; use crate::engine::Engine; use crate::config::Configs; +use crate::ui::UIManager; use std::thread; use clap::{App, Arg}; use std::path::Path; @@ -50,7 +51,8 @@ fn main() { } fn espanso_main(configs: Configs) { - let ui_manager = UIManager::new(); + let ui_manager = ui::get_uimanager(); + ui_manager.notify("Hello guys"); let (txc, rxc) = mpsc::channel(); diff --git a/src/ui/linux.rs b/src/ui/linux.rs new file mode 100644 index 0000000..bdbbb15 --- /dev/null +++ b/src/ui/linux.rs @@ -0,0 +1,25 @@ +use std::process::Command; + +pub struct LinuxUIManager { + +} + +impl super::UIManager for LinuxUIManager { + fn initialize(&self) { + // TODO: check if notify-send is present and log an error otherwise. + } + + fn notify(&self, message: &str) { + let res = Command::new("notify-send") + .args(&["-t", "2000", "espanso", message]) + .output(); + + if let Err(_) = res { + // TODO: print error log + } + } +} + +impl LinuxUIManager { + +} \ No newline at end of file diff --git a/src/ui/mod.rs b/src/ui/mod.rs index c7c425c..8a65631 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -10,16 +10,20 @@ mod macos; pub trait UIManager { fn initialize(&self); fn notify(&self, message: &str); - - fn new() -> impl UIManager { - let manager = get_uimanager(); - manager.initialize(); - manager - } } // MAC IMPLEMENTATION #[cfg(target_os = "macos")] -fn get_uimanager() -> impl UIManager { - macos::MacUIManager{} +pub fn get_uimanager() -> impl UIManager { + let manager = macos::MacUIManager{}; + manager.initialize(); + manager +} + +// LINUX IMPLEMENTATION +#[cfg(target_os = "linux")] +pub fn get_uimanager() -> impl UIManager { + let manager = linux::LinuxUIManager{}; + manager.initialize(); + manager } \ No newline at end of file