Fix compilation error on Windows

This commit is contained in:
Federico Terzi 2020-06-09 21:45:17 +02:00
parent 0d2a6fe95d
commit e98daedd6b
2 changed files with 31 additions and 25 deletions

View File

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

View File

@ -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<Event>) {
// Create a channel to receive the events.
let (tx, rx) = channel();