diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-09-22 11:00:05 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-09-22 11:00:05 +0300 |
commit | b07db29a19fdd3f28134f9b56b7675cf8f1410e0 (patch) | |
tree | 1e28f83456b4b6ba14490bd51210b4ceb223e898 | |
parent | d007ef7e003cffcc66c5f724ee6f3e3e41bc476b (diff) |
ui: add timer tick every 300ms
Check for pending events in the main process by receiving a timer event
every 300ms. This way loaded folders or received emails will get
recognized even if the appropriate informing signals got lost.
-rw-r--r-- | src/bin.rs | 35 | ||||
-rw-r--r-- | ui/src/state.rs | 5 |
2 files changed, 31 insertions, 9 deletions
@@ -45,12 +45,24 @@ use xdg; fn notify( signals: &[c_int], + sender: crossbeam::channel::Sender<ThreadEvent>, ) -> std::result::Result<crossbeam::channel::Receiver<c_int>, std::io::Error> { let (s, r) = crossbeam::channel::bounded(100); let signals = signal_hook::iterator::Signals::new(signals)?; std::thread::spawn(move || { - for signal in signals.forever() { - s.send(signal).unwrap(); + let mut ctr = 0; + loop { + ctr %= 3; + if ctr == 0 { + sender.send(ThreadEvent::Pulse).unwrap(); + } + + for signal in signals.pending() { + s.send(signal).unwrap(); + } + + std::thread::sleep(std::time::Duration::from_millis(100)); + ctr += 1; } }); Ok(r) @@ -175,18 +187,19 @@ fn main() -> std::result::Result<(), std::io::Error> { std::env::set_var("MELI_CONFIG", config_location); } + /* Create the application State. */ + let mut state = State::new(); + + let receiver = state.receiver(); + let sender = state.sender(); + /* Catch SIGWINCH to handle terminal resizing */ let signals = &[ /* Catch SIGWINCH to handle terminal resizing */ signal_hook::SIGWINCH, ]; - let signal_recvr = notify(signals)?; - - /* Create the application State. This is the 'System' part of an ECS architecture */ - let mut state = State::new(); - - let receiver = state.receiver(); + let signal_recvr = notify(signals, sender)?; /* Register some reasonably useful interfaces */ let window = Box::new(Tabbed::new(vec![ @@ -219,7 +232,11 @@ fn main() -> std::result::Result<(), std::io::Error> { /* Poll on all channels. Currently we have the input channel for stdin, watching events and the signal watcher. */ crossbeam::select! { recv(receiver) -> r => { - match debug!(r.unwrap()) { + match r { + Ok(ThreadEvent::Pulse) => {}, + _ => {debug!(&r);} + } + match r.unwrap() { ThreadEvent::Input(Key::Ctrl('z')) => { state.switch_to_main_screen(); //_thread_handler.join().expect("Couldn't join on the associated thread"); diff --git a/ui/src/state.rs b/ui/src/state.rs index 63a82285..27bcdfe2 100644 --- a/ui/src/state.rs +++ b/ui/src/state.rs @@ -365,6 +365,11 @@ impl State { pub fn receiver(&self) -> Receiver<ThreadEvent> { self.context.receiver.clone() } + + pub fn sender(&self) -> Sender<ThreadEvent> { + self.context.sender.clone() + } + pub fn restore_input(&mut self) { self.context.restore_input(); } |