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.master
parent
d007ef7e00
commit
b07db29a19
35
src/bin.rs
35
src/bin.rs
|
@ -45,12 +45,24 @@ use xdg;
|
||||||
|
|
||||||
fn notify(
|
fn notify(
|
||||||
signals: &[c_int],
|
signals: &[c_int],
|
||||||
|
sender: crossbeam::channel::Sender<ThreadEvent>,
|
||||||
) -> std::result::Result<crossbeam::channel::Receiver<c_int>, std::io::Error> {
|
) -> std::result::Result<crossbeam::channel::Receiver<c_int>, std::io::Error> {
|
||||||
let (s, r) = crossbeam::channel::bounded(100);
|
let (s, r) = crossbeam::channel::bounded(100);
|
||||||
let signals = signal_hook::iterator::Signals::new(signals)?;
|
let signals = signal_hook::iterator::Signals::new(signals)?;
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
for signal in signals.forever() {
|
let mut ctr = 0;
|
||||||
s.send(signal).unwrap();
|
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)
|
Ok(r)
|
||||||
|
@ -175,18 +187,19 @@ fn main() -> std::result::Result<(), std::io::Error> {
|
||||||
std::env::set_var("MELI_CONFIG", config_location);
|
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 */
|
/* Catch SIGWINCH to handle terminal resizing */
|
||||||
let signals = &[
|
let signals = &[
|
||||||
/* Catch SIGWINCH to handle terminal resizing */
|
/* Catch SIGWINCH to handle terminal resizing */
|
||||||
signal_hook::SIGWINCH,
|
signal_hook::SIGWINCH,
|
||||||
];
|
];
|
||||||
|
|
||||||
let signal_recvr = notify(signals)?;
|
let signal_recvr = notify(signals, sender)?;
|
||||||
|
|
||||||
/* Create the application State. This is the 'System' part of an ECS architecture */
|
|
||||||
let mut state = State::new();
|
|
||||||
|
|
||||||
let receiver = state.receiver();
|
|
||||||
|
|
||||||
/* Register some reasonably useful interfaces */
|
/* Register some reasonably useful interfaces */
|
||||||
let window = Box::new(Tabbed::new(vec![
|
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. */
|
/* Poll on all channels. Currently we have the input channel for stdin, watching events and the signal watcher. */
|
||||||
crossbeam::select! {
|
crossbeam::select! {
|
||||||
recv(receiver) -> r => {
|
recv(receiver) -> r => {
|
||||||
match debug!(r.unwrap()) {
|
match r {
|
||||||
|
Ok(ThreadEvent::Pulse) => {},
|
||||||
|
_ => {debug!(&r);}
|
||||||
|
}
|
||||||
|
match r.unwrap() {
|
||||||
ThreadEvent::Input(Key::Ctrl('z')) => {
|
ThreadEvent::Input(Key::Ctrl('z')) => {
|
||||||
state.switch_to_main_screen();
|
state.switch_to_main_screen();
|
||||||
//_thread_handler.join().expect("Couldn't join on the associated thread");
|
//_thread_handler.join().expect("Couldn't join on the associated thread");
|
||||||
|
|
|
@ -365,6 +365,11 @@ impl State {
|
||||||
pub fn receiver(&self) -> Receiver<ThreadEvent> {
|
pub fn receiver(&self) -> Receiver<ThreadEvent> {
|
||||||
self.context.receiver.clone()
|
self.context.receiver.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn sender(&self) -> Sender<ThreadEvent> {
|
||||||
|
self.context.sender.clone()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn restore_input(&mut self) {
|
pub fn restore_input(&mut self) {
|
||||||
self.context.restore_input();
|
self.context.restore_input();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue