diff --git a/src/context/macos.rs b/src/context/macos.rs index 7d8bfd7..190a971 100644 --- a/src/context/macos.rs +++ b/src/context/macos.rs @@ -59,13 +59,6 @@ impl MacContext { context } - - pub fn get_data_dir() -> PathBuf { - let data_dir = dirs::data_dir().expect("Can't obtain data_dir(), terminating."); - let espanso_dir = data_dir.join("espanso"); - create_dir_all(&espanso_dir).expect("Error creating espanso data directory"); - espanso_dir - } } impl super::Context for MacContext { diff --git a/src/context/mod.rs b/src/context/mod.rs index 7018f22..b6ab1c0 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -9,11 +9,20 @@ pub(crate) mod macos; use std::sync::mpsc::Sender; use crate::event::Event; +use std::path::PathBuf; +use std::fs::create_dir_all; pub trait Context { fn eventloop(&self); } +pub fn get_data_dir() -> PathBuf { + let data_dir = dirs::data_dir().expect("Can't obtain data_dir(), terminating."); + let espanso_dir = data_dir.join("espanso"); + create_dir_all(&espanso_dir).expect("Error creating espanso data directory"); + espanso_dir +} + // MAC IMPLEMENTATION #[cfg(target_os = "macos")] pub fn new(send_channel: Sender) -> Box { diff --git a/src/main.rs b/src/main.rs index 1d6c001..73f09c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,15 +40,16 @@ fn main() { .value_name("FILE") .help("Sets a custom config directory. If not specified, reads the default $HOME/.espanso/default.yaml file, creating it if not present.") .takes_value(true)) - .arg(Arg::with_name("dump") - .long("dump") - .help("Prints all current configuration options.")) .arg(Arg::with_name("v") .short("v") .multiple(true) .help("Sets the level of verbosity")) + .subcommand(SubCommand::with_name("dump") + .about("Prints all current configuration options.")) .subcommand(SubCommand::with_name("detect") - .about("Tool to detect current window properties, to simplify filters creation")) + .about("Tool to detect current window properties, to simplify filters creation.")) + .subcommand(SubCommand::with_name("daemon") + .about("Start the daemon without spawning a new process.")) .get_matches(); @@ -87,7 +88,7 @@ fn main() { exit(1); }); - if matches.is_present("dump") { + if let Some(matches) = matches.subcommand_matches("dump") { println!("{:#?}", config_set); return; } @@ -97,10 +98,15 @@ fn main() { return; } - daemon_main(config_set); + if let Some(matches) = matches.subcommand_matches("daemon") { + daemon_main(config_set); + return; + } } fn daemon_main(config_set: ConfigSet) { + info!("starting daemon..."); + let (send_channel, receive_channel) = mpsc::channel(); let context = context::new(send_channel); @@ -137,6 +143,8 @@ fn daemon_background(receive_channel: Receiver, config_set: ConfigSet) { vec!(&engine, &matcher), ); + info!("espanso is running!"); + event_manager.eventloop(); }