diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2018-08-11 19:19:30 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-10 19:40:28 +0300 |
commit | 1b44aae5ce97a123657f64769ed32f31aed96b94 (patch) | |
tree | 484239ee608e322ee2ba76c6aa45abe0495533e3 /ui | |
parent | 9abfc855fa30067cb5612897e805baee723504a9 (diff) |
Add reload when receiving refresh event!!
Diffstat (limited to 'ui')
-rw-r--r-- | ui/src/components/mail/compose.rs | 2 | ||||
-rw-r--r-- | ui/src/components/mail/listing/mod.rs | 5 | ||||
-rw-r--r-- | ui/src/state.rs | 39 |
3 files changed, 39 insertions, 7 deletions
diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs index 0a01eea8..6e55a437 100644 --- a/ui/src/components/mail/compose.rs +++ b/ui/src/components/mail/compose.rs @@ -36,7 +36,7 @@ impl Component for Composer { context.dirty_areas.push_back(area); } - fn process_event(&mut self, event: &UIEvent, context: &mut Context) {} + fn process_event(&mut self, _event: &UIEvent, _context: &mut Context) {} fn is_dirty(&self) -> bool { true diff --git a/ui/src/components/mail/listing/mod.rs b/ui/src/components/mail/listing/mod.rs index d16228af..55aebc54 100644 --- a/ui/src/components/mail/listing/mod.rs +++ b/ui/src/components/mail/listing/mod.rs @@ -692,9 +692,10 @@ impl Component for MailListing { self.view = None; } UIEventType::MailboxUpdate((ref idxa, ref idxf)) => { - if *idxa == self.new_cursor_pos.1 && *idxf == self.new_cursor_pos.0 { - self.refresh_mailbox(context); + if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 { self.dirty = true; + self.refresh_mailbox(context); + return; } } UIEventType::ChangeMode(UIMode::Normal) => { diff --git a/ui/src/state.rs b/ui/src/state.rs index 8119b596..bd4aebbc 100644 --- a/ui/src/state.rs +++ b/ui/src/state.rs @@ -50,7 +50,6 @@ pub struct Context { /// Events queue that components send back to the state pub replies: VecDeque<UIEvent>, - backends: Backends, input_thread: chan::Sender<bool>, pub temp_files: Vec<File>, @@ -155,7 +154,6 @@ impl State<std::io::Stdout> { accounts, mailbox_hashes: FnvHashMap::with_capacity_and_hasher(1, Default::default()), - backends, settings: settings.clone(), runtime_settings: settings, dirty_areas: VecDeque::with_capacity(5), @@ -188,8 +186,41 @@ impl State<std::io::Stdout> { } s } - pub fn hash_to_folder(&self, hash: u64) { - eprintln!("got refresh {:?}", self.context.mailbox_hashes[&hash]); + /* + * When we receive a folder hash from a watcher thread, + * we match the hash to the index of the mailbox, request a reload + * and startup a thread to remind us to poll it every now and then till it's finished. + */ + pub fn hash_to_folder(&mut self, hash: u64) { + let (idxa, idxm) = self.context.mailbox_hashes[&hash]; + self.context.accounts[idxa].reload(idxm); + let (startup_tx, startup_rx) = chan::async(); + let startup_thread = { + let sender = self.sender.clone(); + let startup_rx = startup_rx.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() -> _ => { + sender.send(ThreadEvent::UIEvent(UIEventType::MailboxUpdate((idxa,idxm)))); + sender.send(ThreadEvent::ThreadJoin(thread::current().id())); + return; + } + } + sender.send(ThreadEvent::UIEvent(UIEventType::StartupCheck)); + thread::sleep(dur); + } + }) + .unwrap() + }; + self.startup_thread = Some(startup_tx); + self.threads + .insert(startup_thread.thread().id(), startup_thread); } /// If an owned thread returns a `ThreadEvent::ThreadJoin` event to `State` then it must remove |