From e98daedd6b7e96b6a773822f3a5e7f7413876a78 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Tue, 9 Jun 2020 21:45:17 +0200 Subject: [PATCH] Fix compilation error on Windows --- src/context/windows.rs | 1 + src/main.rs | 55 +++++++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/context/windows.rs b/src/context/windows.rs index ec92b57..667d349 100644 --- a/src/context/windows.rs +++ b/src/context/windows.rs @@ -160,6 +160,7 @@ extern "C" fn keypress_callback( // Send the char through the channel match string { Ok(string) => { + println!("{}", string); let event = Event::Key(KeyEvent::Char(string)); (*_self).send_channel.send(event).unwrap(); } diff --git a/src/main.rs b/src/main.rs index 8ef5638..5f394df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -407,31 +407,7 @@ fn daemon_main(config_set: ConfigSet) { }) .expect("Unable to spawn worker monitor thread"); - if !cfg!(target_os = "windows") { - // On Unix, also listen for signals so that we can terminate the - // worker if the daemon receives a signal - use signal_hook::{iterator::Signals, SIGTERM, SIGINT}; - let signals = Signals::new(&[SIGTERM, SIGINT]).expect("unable to register for signals"); - let config_set = config_set.clone(); - thread::Builder::new() - .name("signal monitor".to_string()) - .spawn(move || { - for signal in signals.forever() { - info!("Received signal: {:?}, terminating worker", signal); - send_command_or_warn( - Service::Worker, - config_set.default.clone(), - IPCCommand::exit_worker(), - ); - - std::thread::sleep(Duration::from_millis(200)); - - info!("terminating espanso."); - std::process::exit(0); - } - }) - .expect("Unable to spawn worker monitor thread"); - } + register_signals(config_set.default.clone()); std::thread::sleep(Duration::from_millis(200)); @@ -497,6 +473,35 @@ fn daemon_main(config_set: ConfigSet) { } } +#[cfg(target_os = "windows")] +fn register_signals(_: Configs) {} + +#[cfg(not(target_os = "windows"))] +fn register_signals(config: Configs) { + // On Unix, also listen for signals so that we can terminate the + // worker if the daemon receives a signal + use signal_hook::{iterator::Signals, SIGTERM, SIGINT}; + let signals = Signals::new(&[SIGTERM, SIGINT]).expect("unable to register for signals"); + thread::Builder::new() + .name("signal monitor".to_string()) + .spawn(move || { + for signal in signals.forever() { + info!("Received signal: {:?}, terminating worker", signal); + send_command_or_warn( + Service::Worker, + config, + IPCCommand::exit_worker(), + ); + + std::thread::sleep(Duration::from_millis(200)); + + info!("terminating espanso."); + std::process::exit(0); + } + }) + .expect("Unable to spawn signal monitor thread"); +} + fn watcher_background(sender: Sender) { // Create a channel to receive the events. let (tx, rx) = channel();