wasm: add support for reload events

Manos Pitsidianakis 2020-07-25 00:54:46 +03:00
parent a49190cd5d
commit 04d74a3e85
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
8 changed files with 62 additions and 8 deletions

View File

@ -232,9 +232,9 @@ pub enum RefreshEventKind {
#[derive(Debug, Clone)]
pub struct RefreshEvent {
mailbox_hash: MailboxHash,
account_hash: AccountHash,
kind: RefreshEventKind,
pub mailbox_hash: MailboxHash,
pub account_hash: AccountHash,
pub kind: RefreshEventKind,
}
impl RefreshEvent {

View File

@ -618,7 +618,7 @@ async function init(input) {
imports.wbg.__wbindgen_rethrow = function(arg0) {
throw takeObject(arg0);
};
imports.wbg.__wbindgen_closure_wrapper3066 = function(arg0, arg1, arg2) {
imports.wbg.__wbindgen_closure_wrapper3072 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 689, __wbg_adapter_26);
return addHeapObject(ret);
};

Binary file not shown.

View File

@ -146,6 +146,7 @@ pub trait MailListingTrait: ListingTrait {
) {
let account_pos = self.coordinates().0;
let account = &mut context.accounts[account_pos];
let account_hash = account.hash;
let mut envs_to_set: SmallVec<[EnvelopeHash; 8]> = SmallVec::new();
let mailbox_hash = self.coordinates().1;
for (_, h) in account
@ -184,6 +185,16 @@ pub trait MailListingTrait: ListingTrait {
account
.active_jobs
.insert(job_id, JobRequest::SetFlags(env_hash, handle, rcvr));
context
.replies
.push_back(UIEvent::RefreshEvent(Box::new(RefreshEvent {
kind: melib::backends::RefreshEventKind::Update(
env_hash,
Box::new(envelope.clone()),
),
mailbox_hash,
account_hash,
})));
}
},
ListingAction::SetUnseen => match envelope.set_unseen(op) {
@ -197,6 +208,16 @@ pub trait MailListingTrait: ListingTrait {
account
.active_jobs
.insert(job_id, JobRequest::SetFlags(env_hash, handle, rcvr));
context
.replies
.push_back(UIEvent::RefreshEvent(Box::new(RefreshEvent {
kind: melib::backends::RefreshEventKind::Update(
env_hash,
Box::new(envelope.clone()),
),
mailbox_hash,
account_hash,
})));
}
},
ListingAction::Delete => {
@ -216,6 +237,13 @@ pub trait MailListingTrait: ListingTrait {
account
.active_jobs
.insert(job_id, JobRequest::DeleteMessage(env_hash, handle, rcvr));
context.replies.push_back(UIEvent::RefreshEvent(Box::new(
RefreshEvent {
kind: melib::backends::RefreshEventKind::Remove(env_hash),
mailbox_hash,
account_hash,
},
)));
}
}
continue;

View File

@ -221,11 +221,28 @@ impl MailView {
.and_then(|mut op| op.set_flag(Flag::SEEN, true))
{
Ok(fut) => {
let mailbox_hash = self.coordinates.1;
let env_hash = self.coordinates.2;
let account_hash = account.hash;
let mut env = account.collection.get_env_mut(self.coordinates.2);
let mut flags = env.flags();
flags.set(Flag::SEEN, true);
env.set_flags(flags);
let (rcvr, handle, job_id) = account.job_executor.spawn_specialized(fut);
account.active_jobs.insert(
job_id,
JobRequest::SetFlags(self.coordinates.2, handle, rcvr),
);
context
.replies
.push_back(UIEvent::RefreshEvent(Box::new(RefreshEvent {
kind: melib::backends::RefreshEventKind::Update(
env_hash,
Box::new(env.clone()),
),
mailbox_hash,
account_hash,
})));
}
Err(e) => {
context.replies.push_back(UIEvent::StatusEvent(

View File

@ -1102,6 +1102,9 @@ impl Component for StatusBar {
self.dirty = true;
}
UIEvent::ExInput(Key::Ctrl('p')) => {
if self.cmd_history.is_empty() {
return true;
}
let pos = self.ex_buffer_cmd_history_pos.map(|p| p + 1).unwrap_or(0);
let pos = Some(std::cmp::min(pos, self.cmd_history.len().saturating_sub(1)));
if pos != self.ex_buffer_cmd_history_pos {
@ -1121,6 +1124,9 @@ impl Component for StatusBar {
return true;
}
UIEvent::ExInput(Key::Ctrl('n')) => {
if self.cmd_history.is_empty() {
return true;
}
if Some(0) == self.ex_buffer_cmd_history_pos {
self.ex_buffer_cmd_history_pos = None;
self.ex_buffer.clear();

View File

@ -139,7 +139,7 @@ impl MailboxEntry {
pub struct Account {
pub index: usize,
name: String,
hash: AccountHash,
pub hash: AccountHash,
pub is_online: Result<()>,
pub(crate) mailbox_entries: HashMap<MailboxHash, MailboxEntry>,
pub(crate) mailboxes_order: Vec<MailboxHash>,
@ -596,6 +596,7 @@ impl Account {
Some(mailbox)
}
pub fn reload(&mut self, event: RefreshEvent, mailbox_hash: MailboxHash) -> Option<UIEvent> {
melib::log(format!("got reload event {:?}", &event), melib::ERROR);
if !self.mailbox_entries[&mailbox_hash].status.is_available() {
self.event_queue.push_back((mailbox_hash, event));
return None;

View File

@ -368,7 +368,6 @@ impl State {
* and startup a thread to remind us to poll it every now and then till it's finished.
*/
pub fn refresh_event(&mut self, event: RefreshEvent) {
/*
let account_hash = event.account_hash();
let mailbox_hash = event.mailbox_hash();
if let Some(&idxa) = self.context.account_hashes.get(&account_hash) {
@ -392,11 +391,10 @@ impl State {
}
} else {
if let melib::backends::RefreshEventKind::Failure(err) = event.kind() {
debug!(err);
js_console(&err.to_string());
}
}
}
*/
}
/// Switch back to the terminal's main screen (The command line the user sees before opening
@ -1400,6 +1398,10 @@ impl State {
self.overlay.push(dialog);
return;
}
UIEvent::RefreshEvent(ev) => {
self.refresh_event(*ev);
return;
}
_ => {}
}
let Self {