Add basic linux notification support

This commit is contained in:
Federico Terzi 2019-09-06 22:30:20 +02:00
parent 1b34e626c4
commit 3114c7b7ff
3 changed files with 40 additions and 9 deletions

View File

@ -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();

25
src/ui/linux.rs Normal file
View File

@ -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 {
}

View File

@ -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
}