diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2018-08-06 13:33:10 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-10 19:40:26 +0300 |
commit | 3f35b69ff11b22c9ffc5a73e75d312e8c5b2b680 (patch) | |
tree | 81e6e7c516c104de771410926a185ac5c1e1d994 /ui | |
parent | f2a646158dd1284f048c426caa344af340a61624 (diff) |
Poll all parse workers on startup
Diffstat (limited to 'ui')
-rw-r--r-- | ui/src/components/mail/listing.rs | 20 | ||||
-rw-r--r-- | ui/src/lib.rs | 39 |
2 files changed, 46 insertions, 13 deletions
diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index 5ed00b69..80f47e4c 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -64,14 +64,13 @@ impl MailListing { // Get mailbox as a reference. // loop { - eprintln!("loop round"); - match context.accounts[self.cursor_pos.0].status(self.cursor_pos.1) { - Ok(()) => { break; }, - Err(a) => { - eprintln!("status returned {:?}", a); + match context.accounts[self.cursor_pos.0].status(self.cursor_pos.1) { + Ok(()) => { break; }, + Err(_) => { + // TODO: Show progress visually + } } } - } let mailbox = &mut context.accounts[self.cursor_pos.0][self.cursor_pos.1] .as_ref() .unwrap(); @@ -455,8 +454,7 @@ impl Component for MailListing { &mut mailbox.collection[idx] }; if !envelope.is_seen() { - eprintln!("setting seen"); - envelope.set_seen(); + envelope.set_seen().unwrap(); true } else { false @@ -464,7 +462,6 @@ impl Component for MailListing { } }; if must_highlight { - eprintln!("must highlight"); self.highlight_line_self(idx, context); } let mid = get_y(upper_left) + total_rows - bottom_entity_rows; @@ -659,13 +656,12 @@ impl Component for MailListing { return; }, Action::ViewMailbox(idx) => { - eprintln!("listing got viewmailbox({})", idx); self.new_cursor_pos.1 = *idx; self.dirty = true; self.refresh_mailbox(context); return; - } - _ => {}, + }, + //_ => {}, }, _ => {} } diff --git a/ui/src/lib.rs b/ui/src/lib.rs index 17f66724..1aa5f127 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -55,6 +55,8 @@ use melib::*; use std::collections::VecDeque; use std::fmt; use std::io::Write; +use std::thread; +use std::time; extern crate termion; use termion::event::Key as TermionKey; use termion::input::TermRead; @@ -77,7 +79,7 @@ pub enum ThreadEvent { RefreshMailbox { hash: u64, }, - UIEventType(UIEventType), + UIEvent(UIEventType), //Decode { _ }, // For gpg2 signature check } @@ -110,6 +112,8 @@ pub enum UIEventType { Action(Action), StatusNotification(String), MailboxUpdate((usize, usize)), + + StartupCheck, } /// An event passed from `State` to its Entities. @@ -186,6 +190,8 @@ pub struct State<W: Write> { sender: Sender<ThreadEvent>, entities: Vec<Entity>, pub context: Context, + + startup_thread: Option<(chan::Sender<bool>, thread::JoinHandle<()>)>, } impl<W: Write> Drop for State<W> { @@ -222,6 +228,25 @@ impl State<std::io::Stdout> { .map(|(n, a_s)| Account::new(n.to_string(), a_s.clone(), &backends)) .collect(); accounts.sort_by(|a, b| a.name().cmp(&b.name())); + let (startup_tx, startup_rx) = chan::async(); + let startup_thread = { + let sender = sender.clone(); + thread::Builder::new() + .name("startup-thread".to_string()) + .spawn(move || { + let dur = time::Duration::from_millis(100); + loop { + chan_select! { + default => {}, + startup_rx.recv() -> _ => { + return; + } + } + sender.send(ThreadEvent::UIEvent(UIEventType::StartupCheck)); + thread::sleep(dur); + } + }).unwrap() + }; let mut s = State { cols: cols, rows: rows, @@ -242,6 +267,7 @@ impl State<std::io::Stdout> { input_thread: input_thread, }, + startup_thread: Some((startup_tx, startup_thread)), }; write!( s.stdout(), @@ -259,6 +285,17 @@ impl State<std::io::Stdout> { } s } + pub fn finish_startup(&mut self) { + // TODO: Encode startup process with the type system if possible + if self.startup_thread.is_none() { + return; + } + { + let (tx, handle) = self.startup_thread.take().unwrap(); + tx.send(true); + handle.join().unwrap(); + } + } pub fn to_main_screen(&mut self) { write!( self.stdout(), |