ui/listing: add mailbox reload rate limit
parent
0ac10aa4d0
commit
20f86f2741
|
@ -238,6 +238,7 @@ pub struct Listing {
|
||||||
dirty: bool,
|
dirty: bool,
|
||||||
visible: bool,
|
visible: bool,
|
||||||
cursor_pos: (usize, usize),
|
cursor_pos: (usize, usize),
|
||||||
|
startup_checks_rate: RateLimit,
|
||||||
id: ComponentId,
|
id: ComponentId,
|
||||||
|
|
||||||
show_divider: bool,
|
show_divider: bool,
|
||||||
|
@ -358,6 +359,34 @@ impl Component for Listing {
|
||||||
self.dirty = false;
|
self.dirty = false;
|
||||||
}
|
}
|
||||||
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
|
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
|
||||||
|
match event {
|
||||||
|
UIEvent::StartupCheck(ref f) => {
|
||||||
|
if context.accounts[self.component.coordinates().0]
|
||||||
|
.folders_order
|
||||||
|
.get(self.component.coordinates().1)
|
||||||
|
.map(|&folder_hash| *f == folder_hash)
|
||||||
|
.unwrap_or(false)
|
||||||
|
{
|
||||||
|
if !self.startup_checks_rate.tick() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UIEvent::Timer(n) if *n == self.startup_checks_rate.id() => {
|
||||||
|
if self.startup_checks_rate.active {
|
||||||
|
self.startup_checks_rate.reset();
|
||||||
|
if let Some(folder_hash) = context.accounts[self.component.coordinates().0]
|
||||||
|
.folders_order
|
||||||
|
.get(self.component.coordinates().1)
|
||||||
|
{
|
||||||
|
return self
|
||||||
|
.process_event(&mut UIEvent::StartupCheck(*folder_hash), context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
if self.component.process_event(event, context) {
|
if self.component.process_event(event, context) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -811,6 +840,7 @@ impl Listing {
|
||||||
visible: true,
|
visible: true,
|
||||||
dirty: true,
|
dirty: true,
|
||||||
cursor_pos: (0, 0),
|
cursor_pos: (0, 0),
|
||||||
|
startup_checks_rate: RateLimit::new(2, 1000),
|
||||||
id: ComponentId::new_v4(),
|
id: ComponentId::new_v4(),
|
||||||
show_divider: false,
|
show_divider: false,
|
||||||
menu_visibility: true,
|
menu_visibility: true,
|
||||||
|
|
|
@ -847,6 +847,12 @@ impl Account {
|
||||||
};
|
};
|
||||||
*f = MailboxEntry::Available(m);
|
*f = MailboxEntry::Available(m);
|
||||||
});
|
});
|
||||||
|
self.sender
|
||||||
|
.send(ThreadEvent::UIEvent(UIEvent::MailboxUpdate((
|
||||||
|
self.index,
|
||||||
|
folder_hash,
|
||||||
|
))))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
self.workers.insert(folder_hash, None);
|
self.workers.insert(folder_hash, None);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue