diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-03-30 13:41:32 +0200 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-10 19:40:41 +0300 |
commit | 551db51b00872a6cf4261ff8a9dedacc62914454 (patch) | |
tree | 4d6320170cd4889cb25c494019f617037a234ace | |
parent | d19bda89776346b72c8e5dd36880a94f58299cec (diff) |
ui: avoid full renders when worker threads return StartupChecks
Now listings only re-render when their folder gets a StartupCheck event,
account menu always re-renders to update new mail counts
closes #76
-rw-r--r-- | melib/src/mailbox/backends.rs | 12 | ||||
-rw-r--r-- | src/bin.rs | 18 | ||||
-rw-r--r-- | ui/src/components/mail.rs | 5 | ||||
-rw-r--r-- | ui/src/components/mail/listing/compact.rs | 12 | ||||
-rw-r--r-- | ui/src/components/mail/listing/plain.rs | 12 | ||||
-rw-r--r-- | ui/src/components/mail/listing/thread.rs | 15 | ||||
-rw-r--r-- | ui/src/conf/accounts.rs | 3 | ||||
-rw-r--r-- | ui/src/state.rs | 8 | ||||
-rw-r--r-- | ui/src/types.rs | 3 |
9 files changed, 38 insertions, 50 deletions
diff --git a/melib/src/mailbox/backends.rs b/melib/src/mailbox/backends.rs index a650eda4..4ba2d010 100644 --- a/melib/src/mailbox/backends.rs +++ b/melib/src/mailbox/backends.rs @@ -121,7 +121,7 @@ impl RefreshEventConsumer { } } -pub struct NotifyFn(Box<Fn() -> ()>); +pub struct NotifyFn(Box<Fn(FolderHash) -> ()>); unsafe impl Send for NotifyFn {} unsafe impl Sync for NotifyFn {} @@ -131,18 +131,18 @@ impl fmt::Debug for NotifyFn { } } -impl From<Box<Fn() -> ()>> for NotifyFn { - fn from(kind: Box<Fn() -> ()>) -> Self { +impl From<Box<Fn(FolderHash) -> ()>> for NotifyFn { + fn from(kind: Box<Fn(FolderHash) -> ()>) -> Self { NotifyFn(kind) } } impl NotifyFn { - pub fn new(b: Box<Fn() -> ()>) -> Self { + pub fn new(b: Box<Fn(FolderHash) -> ()>) -> Self { NotifyFn(b) } - pub fn notify(&self) { - self.0(); + pub fn notify(&self, f: FolderHash) { + self.0(f); } } pub trait MailBackend: ::std::fmt::Debug { @@ -171,24 +171,6 @@ fn main() { break 'inner; // `goto` 'reap loop, and wait on child. } } - ThreadEvent::UIEvent(UIEventType::StartupCheck) => { - let mut render_flag = false; - for idx_a in 0..state.context.accounts.len() { - let len = state.context.accounts[idx_a].len(); - for idx_m in 0..len { - - match state.context.account_status(idx_a, idx_m) { - Ok(_) => { - render_flag = true; - }, - Err(_) => {} - } - } - } - if render_flag { - state.render(); - } - } ThreadEvent::UIEvent(e) => { state.rcv_event(UIEvent { id: 0, event_type: e}); state.render(); diff --git a/ui/src/components/mail.rs b/ui/src/components/mail.rs index 4a760fd7..a58d2aa1 100644 --- a/ui/src/components/mail.rs +++ b/ui/src/components/mail.rs @@ -247,9 +247,7 @@ impl Component for AccountMenu { } clear_area(grid, area); let upper_left = upper_left!(area); - let x = get_x(upper_left); let bottom_right = bottom_right!(area); - let x_max = get_x(bottom_right); self.dirty = false; let mut y = get_y(upper_left); for a in &self.accounts { @@ -275,6 +273,9 @@ impl Component for AccountMenu { self.visible = !self.visible; self.dirty = true; } + UIEventType::StartupCheck(_) => { + self.dirty = true; + } _ => {} } false diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index 61e64487..bf34350f 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -479,11 +479,13 @@ impl Component for CompactListing { self.view = None; self.dirty = true; } - UIEventType::MailboxUpdate((ref idxa, ref idxf)) => { - if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 { - self.refresh_mailbox(context); - self.set_dirty(); - } + UIEventType::MailboxUpdate((ref idxa, ref idxf)) if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 => { + self.refresh_mailbox(context); + self.set_dirty(); + } + UIEventType::StartupCheck(ref f) if context.mailbox_hashes[f] == (self.new_cursor_pos.0, self.new_cursor_pos.1) => { + self.refresh_mailbox(context); + self.set_dirty(); } UIEventType::ChangeMode(UIMode::Normal) => { self.dirty = true; diff --git a/ui/src/components/mail/listing/plain.rs b/ui/src/components/mail/listing/plain.rs index a7843b09..d354aee3 100644 --- a/ui/src/components/mail/listing/plain.rs +++ b/ui/src/components/mail/listing/plain.rs @@ -512,11 +512,13 @@ impl Component for PlainListing { self.dirty = true; self.view = None; } - UIEventType::MailboxUpdate((ref idxa, ref idxf)) => { - if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 { - self.dirty = true; - self.refresh_mailbox(context); - } + UIEventType::MailboxUpdate((ref idxa, ref idxf)) if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 => { + self.refresh_mailbox(context); + self.set_dirty(); + } + UIEventType::StartupCheck(ref f) if context.mailbox_hashes[f] == (self.new_cursor_pos.0, self.new_cursor_pos.1) => { + self.refresh_mailbox(context); + self.set_dirty(); } UIEventType::ChangeMode(UIMode::Normal) => { self.dirty = true; diff --git a/ui/src/components/mail/listing/thread.rs b/ui/src/components/mail/listing/thread.rs index 6f55678a..edfbd7dc 100644 --- a/ui/src/components/mail/listing/thread.rs +++ b/ui/src/components/mail/listing/thread.rs @@ -651,14 +651,13 @@ impl Component for ThreadListing { self.dirty = true; self.view = None; } - UIEventType::MailboxUpdate((ref idxa, ref idxf)) => { - if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 { - self.dirty = true; - self.refresh_mailbox(context); - if cfg!(feature = "debug_log") { - eprintln!("mailboxupdate"); - } - } + UIEventType::MailboxUpdate((ref idxa, ref idxf)) if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 => { + self.refresh_mailbox(context); + self.set_dirty(); + } + UIEventType::StartupCheck(ref f) if context.mailbox_hashes[f] == (self.new_cursor_pos.0, self.new_cursor_pos.1) => { + self.refresh_mailbox(context); + self.set_dirty(); } UIEventType::ChangeMode(UIMode::Normal) => { self.dirty = true; diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index e32d2492..9ac956cd 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -140,9 +140,10 @@ impl Account { work.compute(); handle.join(); let envelopes = handle.extract(); + let hash = folder.hash(); let ret = Mailbox::new(folder, envelopes); tx.send(AsyncStatus::Payload(ret)); - notify_fn.notify(); + notify_fn.notify(hash); }))) } pub fn reload(&mut self, event: RefreshEvent, idx: usize) -> Option<UIEventType> { diff --git a/ui/src/state.rs b/ui/src/state.rs index ced7beaa..320d3e2d 100644 --- a/ui/src/state.rs +++ b/ui/src/state.rs @@ -75,7 +75,7 @@ impl InputHandler { /// A context container for loaded settings, accounts, UI changes, etc. pub struct Context { pub accounts: Vec<Account>, - mailbox_hashes: FnvHashMap<FolderHash, (usize, usize)>, + pub mailbox_hashes: FnvHashMap<FolderHash, (usize, usize)>, pub settings: Settings, pub runtime_settings: Settings, @@ -185,8 +185,8 @@ impl State { n.to_string(), a_s.clone(), &backends, - NotifyFn::new(Box::new(move || { - sender.send(ThreadEvent::UIEvent(UIEventType::StartupCheck)) + NotifyFn::new(Box::new(move |f: FolderHash| { + sender.send(ThreadEvent::UIEvent(UIEventType::StartupCheck(f))) })), ) }) @@ -279,7 +279,7 @@ impl State { if let Some(notification) = self.context.accounts[idxa].reload(event, idxm) { self.context .sender - .send(ThreadEvent::UIEvent(UIEventType::StartupCheck)); + .send(ThreadEvent::UIEvent(UIEventType::StartupCheck(hash))); self.context.replies.push_back(UIEvent { id: 0, event_type: notification, diff --git a/ui/src/types.rs b/ui/src/types.rs index 9e820bbd..bbbbf547 100644 --- a/ui/src/types.rs +++ b/ui/src/types.rs @@ -27,6 +27,7 @@ use super::execute::Action; use super::terminal::*; use melib::RefreshEvent; +use melib::backends::FolderHash; use std; use std::fmt; use std::thread; @@ -83,7 +84,7 @@ pub enum UIEventType { StatusEvent(StatusEvent), MailboxUpdate((usize, usize)), // (account_idx, mailbox_idx) EntityKill(Uuid), - StartupCheck, + StartupCheck(FolderHash), RefreshEvent(Box<RefreshEvent>), } |