Send NewJob event on all job startups
parent
65357625ea
commit
f05dd379ae
|
@ -225,9 +225,6 @@ impl MailView {
|
||||||
};
|
};
|
||||||
self.active_jobs.insert(job_id);
|
self.active_jobs.insert(job_id);
|
||||||
account.insert_job(job_id, JobRequest::AsBytes(handle));
|
account.insert_job(job_id, JobRequest::AsBytes(handle));
|
||||||
context
|
|
||||||
.replies
|
|
||||||
.push_back(UIEvent::StatusEvent(StatusEvent::NewJob(job_id)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
|
@ -414,6 +414,11 @@ impl Account {
|
||||||
};
|
};
|
||||||
active_jobs.insert(job_id, JobRequest::Mailboxes(handle, rcvr));
|
active_jobs.insert(job_id, JobRequest::Mailboxes(handle, rcvr));
|
||||||
active_job_instants.insert(std::time::Instant::now(), job_id);
|
active_job_instants.insert(std::time::Instant::now(), job_id);
|
||||||
|
sender
|
||||||
|
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
||||||
|
StatusEvent::NewJob(job_id),
|
||||||
|
)))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Account {
|
Ok(Account {
|
||||||
|
@ -929,21 +934,14 @@ impl Account {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if let Ok(refresh_job) = self.backend.write().unwrap().refresh(mailbox_hash) {
|
let refresh_job = self.backend.write().unwrap().refresh(mailbox_hash);
|
||||||
|
if let Ok(refresh_job) = refresh_job {
|
||||||
let (rcvr, handle, job_id) = if self.backend_capabilities.is_async {
|
let (rcvr, handle, job_id) = if self.backend_capabilities.is_async {
|
||||||
self.job_executor.spawn_specialized(refresh_job)
|
self.job_executor.spawn_specialized(refresh_job)
|
||||||
} else {
|
} else {
|
||||||
self.job_executor.spawn_blocking(refresh_job)
|
self.job_executor.spawn_blocking(refresh_job)
|
||||||
};
|
};
|
||||||
self.sender
|
self.insert_job(job_id, JobRequest::Refresh(mailbox_hash, handle, rcvr));
|
||||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
|
||||||
StatusEvent::NewJob(job_id),
|
|
||||||
)))
|
|
||||||
.unwrap();
|
|
||||||
self.active_jobs
|
|
||||||
.insert(job_id, JobRequest::Refresh(mailbox_hash, handle, rcvr));
|
|
||||||
self.active_job_instants
|
|
||||||
.insert(std::time::Instant::now(), job_id);
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1033,13 +1031,7 @@ impl Account {
|
||||||
} else {
|
} else {
|
||||||
self.job_executor.spawn_blocking(mailbox_job)
|
self.job_executor.spawn_blocking(mailbox_job)
|
||||||
};
|
};
|
||||||
self.sender
|
self.insert_job(job_id, JobRequest::Fetch(mailbox_hash, handle, rcvr));
|
||||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
|
||||||
StatusEvent::NewJob(job_id),
|
|
||||||
)))
|
|
||||||
.unwrap();
|
|
||||||
self.active_jobs
|
|
||||||
.insert(job_id, JobRequest::Fetch(mailbox_hash, handle, rcvr));
|
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.mailbox_entries
|
self.mailbox_entries
|
||||||
|
@ -1130,12 +1122,7 @@ impl Account {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.save(bytes.to_vec(), mailbox_hash, flags)?;
|
.save(bytes.to_vec(), mailbox_hash, flags)?;
|
||||||
let (channel, handle, job_id) = self.job_executor.spawn_specialized(job);
|
let (channel, handle, job_id) = self.job_executor.spawn_specialized(job);
|
||||||
self.sender
|
self.insert_job(
|
||||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
|
||||||
StatusEvent::NewJob(job_id),
|
|
||||||
)))
|
|
||||||
.unwrap();
|
|
||||||
self.active_jobs.insert(
|
|
||||||
job_id,
|
job_id,
|
||||||
JobRequest::SaveMessage {
|
JobRequest::SaveMessage {
|
||||||
bytes: bytes.to_vec(),
|
bytes: bytes.to_vec(),
|
||||||
|
@ -1144,8 +1131,6 @@ impl Account {
|
||||||
channel,
|
channel,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
self.active_job_instants
|
|
||||||
.insert(std::time::Instant::now(), job_id);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1207,16 +1192,8 @@ impl Account {
|
||||||
melib::smtp::SmtpConnection::new_connection(conf).await?;
|
melib::smtp::SmtpConnection::new_connection(conf).await?;
|
||||||
smtp_connection.mail_transaction(&message, None).await
|
smtp_connection.mail_transaction(&message, None).await
|
||||||
});
|
});
|
||||||
self.sender
|
|
||||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
|
||||||
StatusEvent::NewJob(job_id),
|
|
||||||
)))
|
|
||||||
.unwrap();
|
|
||||||
if complete_in_background {
|
if complete_in_background {
|
||||||
self.active_jobs
|
self.insert_job(job_id, JobRequest::SendMessageBackground(handle, chan));
|
||||||
.insert(job_id, JobRequest::SendMessageBackground(handle, chan));
|
|
||||||
self.active_job_instants
|
|
||||||
.insert(std::time::Instant::now(), job_id);
|
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
} else {
|
} else {
|
||||||
self.insert_job(job_id, JobRequest::SendMessage);
|
self.insert_job(job_id, JobRequest::SendMessage);
|
||||||
|
@ -1463,6 +1440,12 @@ impl Account {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_event(&mut self, job_id: &JobId) -> bool {
|
pub fn process_event(&mut self, job_id: &JobId) -> bool {
|
||||||
|
self.sender
|
||||||
|
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
||||||
|
StatusEvent::JobFinished(*job_id),
|
||||||
|
)))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
if self.active_jobs.contains_key(job_id) {
|
if self.active_jobs.contains_key(job_id) {
|
||||||
match self.active_jobs.remove(job_id).unwrap() {
|
match self.active_jobs.remove(job_id).unwrap() {
|
||||||
JobRequest::Mailboxes(_, ref mut chan) => {
|
JobRequest::Mailboxes(_, ref mut chan) => {
|
||||||
|
@ -1484,24 +1467,16 @@ impl Account {
|
||||||
self.is_online = Err(err);
|
self.is_online = Err(err);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if let Ok(mailboxes_job) = self.backend.read().unwrap().mailboxes() {
|
let mailboxes_job = self.backend.read().unwrap().mailboxes();
|
||||||
|
if let Ok(mailboxes_job) = mailboxes_job {
|
||||||
let (rcvr, handle, job_id) =
|
let (rcvr, handle, job_id) =
|
||||||
self.job_executor.spawn_specialized(mailboxes_job);
|
self.job_executor.spawn_specialized(mailboxes_job);
|
||||||
self.active_jobs
|
self.insert_job(job_id, JobRequest::Mailboxes(handle, rcvr));
|
||||||
.insert(job_id, JobRequest::Mailboxes(handle, rcvr));
|
};
|
||||||
self.active_job_instants
|
|
||||||
.insert(std::time::Instant::now(), job_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JobRequest::Fetch(mailbox_hash, _, ref mut chan) => {
|
JobRequest::Fetch(mailbox_hash, _, ref mut chan) => {
|
||||||
self.sender
|
|
||||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
|
||||||
StatusEvent::JobFinished(*job_id),
|
|
||||||
)))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (payload, rest): (Option<Result<Vec<Envelope>>>, _) =
|
let (payload, rest): (Option<Result<Vec<Envelope>>>, _) =
|
||||||
chan.try_recv().unwrap().unwrap();
|
chan.try_recv().unwrap().unwrap();
|
||||||
debug!("got payload in status for {}", mailbox_hash);
|
debug!("got payload in status for {}", mailbox_hash);
|
||||||
|
@ -1522,15 +1497,7 @@ impl Account {
|
||||||
}
|
}
|
||||||
let (rcvr, handle, job_id) =
|
let (rcvr, handle, job_id) =
|
||||||
self.job_executor.spawn_specialized(rest.into_future());
|
self.job_executor.spawn_specialized(rest.into_future());
|
||||||
self.sender
|
self.insert_job(job_id, JobRequest::Fetch(mailbox_hash, handle, rcvr));
|
||||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
|
||||||
StatusEvent::NewJob(job_id),
|
|
||||||
)))
|
|
||||||
.unwrap();
|
|
||||||
self.active_jobs
|
|
||||||
.insert(job_id, JobRequest::Fetch(mailbox_hash, handle, rcvr));
|
|
||||||
self.active_job_instants
|
|
||||||
.insert(std::time::Instant::now(), job_id);
|
|
||||||
let payload = payload.unwrap();
|
let payload = payload.unwrap();
|
||||||
if let Err(err) = payload {
|
if let Err(err) = payload {
|
||||||
self.sender
|
self.sender
|
||||||
|
@ -1600,14 +1567,12 @@ impl Account {
|
||||||
}
|
}
|
||||||
self.is_online = is_online;
|
self.is_online = is_online;
|
||||||
}
|
}
|
||||||
if let Ok(online_job) = self.backend.read().unwrap().is_online() {
|
let online_job = self.backend.read().unwrap().is_online();
|
||||||
|
if let Ok(online_job) = online_job {
|
||||||
let (rcvr, handle, job_id) =
|
let (rcvr, handle, job_id) =
|
||||||
self.job_executor.spawn_specialized(online_job);
|
self.job_executor.spawn_specialized(online_job);
|
||||||
self.active_jobs
|
self.insert_job(job_id, JobRequest::IsOnline(handle, rcvr));
|
||||||
.insert(job_id, JobRequest::IsOnline(handle, rcvr));
|
};
|
||||||
self.active_job_instants
|
|
||||||
.insert(std::time::Instant::now(), job_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
JobRequest::Refresh(_mailbox_hash, _, ref mut chan) => {
|
JobRequest::Refresh(_mailbox_hash, _, ref mut chan) => {
|
||||||
let r = chan.try_recv().unwrap();
|
let r = chan.try_recv().unwrap();
|
||||||
|
@ -1641,11 +1606,6 @@ impl Account {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.sender
|
|
||||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
|
||||||
StatusEvent::JobFinished(*job_id),
|
|
||||||
)))
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
JobRequest::SetFlags(_, _, ref mut chan) => {
|
JobRequest::SetFlags(_, _, ref mut chan) => {
|
||||||
let r = chan.try_recv().unwrap();
|
let r = chan.try_recv().unwrap();
|
||||||
|
@ -1688,13 +1648,7 @@ impl Account {
|
||||||
.expect("Could not send event on main channel");
|
.expect("Could not send event on main channel");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JobRequest::SendMessage => {
|
JobRequest::SendMessage => {}
|
||||||
self.sender
|
|
||||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
|
||||||
StatusEvent::JobFinished(*job_id),
|
|
||||||
)))
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
JobRequest::SendMessageBackground(_, ref mut chan) => {
|
JobRequest::SendMessageBackground(_, ref mut chan) => {
|
||||||
let r = chan.try_recv().unwrap();
|
let r = chan.try_recv().unwrap();
|
||||||
if let Some(Err(err)) = r {
|
if let Some(Err(err)) = r {
|
||||||
|
@ -1706,11 +1660,6 @@ impl Account {
|
||||||
)))
|
)))
|
||||||
.expect("Could not send event on main channel");
|
.expect("Could not send event on main channel");
|
||||||
}
|
}
|
||||||
self.sender
|
|
||||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
|
||||||
StatusEvent::JobFinished(*job_id),
|
|
||||||
)))
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
JobRequest::CopyTo(mailbox_hash, _, ref mut chan) => {
|
JobRequest::CopyTo(mailbox_hash, _, ref mut chan) => {
|
||||||
if let Err(err) = chan
|
if let Err(err) = chan
|
||||||
|
@ -1899,13 +1848,7 @@ impl Account {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//JobRequest::RenameMailbox,
|
//JobRequest::RenameMailbox,
|
||||||
JobRequest::Search(_) | JobRequest::AsBytes(_) => {
|
JobRequest::Search(_) | JobRequest::AsBytes(_) => {}
|
||||||
self.sender
|
|
||||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
|
||||||
StatusEvent::JobFinished(*job_id),
|
|
||||||
)))
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
JobRequest::SetMailboxPermissions(_, _, ref mut chan) => {
|
JobRequest::SetMailboxPermissions(_, _, ref mut chan) => {
|
||||||
let r = chan.try_recv().unwrap();
|
let r = chan.try_recv().unwrap();
|
||||||
match r {
|
match r {
|
||||||
|
@ -2026,11 +1969,6 @@ impl Account {
|
||||||
)))
|
)))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
self.sender
|
|
||||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
|
||||||
StatusEvent::JobFinished(*job_id),
|
|
||||||
)))
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
@ -2043,6 +1981,11 @@ impl Account {
|
||||||
self.active_jobs.insert(job_id, job);
|
self.active_jobs.insert(job_id, job);
|
||||||
self.active_job_instants
|
self.active_job_instants
|
||||||
.insert(std::time::Instant::now(), job_id);
|
.insert(std::time::Instant::now(), job_id);
|
||||||
|
self.sender
|
||||||
|
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
||||||
|
StatusEvent::NewJob(job_id),
|
||||||
|
)))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue