imap: launch async watch when connection comes online
Closes #38 Make async watch/refresh work in imapasync
parent
b5748c247a
commit
89dedbedb7
|
@ -1419,7 +1419,7 @@ impl Account {
|
|||
self.active_jobs.insert(job_id, JobRequest::IsOnline(rcvr));
|
||||
}
|
||||
}
|
||||
return self.backend.read().unwrap().is_online();
|
||||
return Err(MeliError::new("Attempting connection."));
|
||||
} else {
|
||||
let ret = self.backend.read().unwrap().is_online();
|
||||
if ret.is_ok() != self.is_online && ret.is_ok() {
|
||||
|
@ -1586,6 +1586,9 @@ impl Account {
|
|||
if is_online.is_some() {
|
||||
let is_online = is_online.unwrap();
|
||||
if is_online.is_ok() {
|
||||
if !self.is_online {
|
||||
self.watch();
|
||||
}
|
||||
self.is_online = true;
|
||||
self.sender
|
||||
.send(ThreadEvent::UIEvent(UIEvent::AccountStatusChange(
|
||||
|
@ -1603,6 +1606,9 @@ impl Account {
|
|||
JobRequest::Refresh(_mailbox_hash, mut chan) => {
|
||||
let r = chan.try_recv().unwrap();
|
||||
if r.is_some() && r.unwrap().is_ok() {
|
||||
if !self.is_online {
|
||||
self.watch();
|
||||
}
|
||||
self.is_online = true;
|
||||
}
|
||||
self.sender
|
||||
|
|
|
@ -126,6 +126,7 @@ impl Context {
|
|||
let ret = accounts[account_pos].is_online();
|
||||
if ret.is_ok() {
|
||||
if !was_online {
|
||||
debug!("inserting mailbox hashes:");
|
||||
for mailbox_node in accounts[account_pos].list_mailboxes() {
|
||||
debug!(
|
||||
"hash & mailbox: {:?} {}",
|
||||
|
@ -133,13 +134,6 @@ impl Context {
|
|||
accounts[account_pos][&mailbox_node.hash].name()
|
||||
);
|
||||
}
|
||||
/* Account::watch() needs
|
||||
* - work_controller to pass `work_context` to the watcher threads and then add them
|
||||
* to the controller's static thread list,
|
||||
* - sender to pass a RefreshEventConsumer closure to watcher threads for them to
|
||||
* inform the main binary that refresh events arrived
|
||||
* - replies to report any failures to the user
|
||||
*/
|
||||
accounts[account_pos].watch();
|
||||
|
||||
replies.push_back(UIEvent::AccountStatusChange(account_pos));
|
||||
|
@ -356,7 +350,6 @@ impl State {
|
|||
}
|
||||
|
||||
s.switch_to_alternate_screen();
|
||||
debug!("inserting mailbox hashes:");
|
||||
for i in 0..s.context.accounts.len() {
|
||||
if !s.context.accounts[i].is_remote {
|
||||
s.context.accounts[i].watch();
|
||||
|
|
Loading…
Reference in New Issue