Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

feat(lib) add way to manually call loop #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,31 @@ impl Application {
self.window.quit()
}

pub fn wait_for_message(&mut self) -> Result<(), Error> {
loop {
let msg;
match self.rx.recv() {
Ok(m) => msg = m,
Err(_) => {
self.quit();
break;
}
pub fn get_message(&mut self) -> Result<bool, Error> {
let msg;
match self.rx.recv() {
Ok(m) => msg = m,
Err(_) => {
self.quit();
return Ok(true);
}
if self.callback.contains_key(&msg.menu_index) {
if let Some(mut f) = self.callback.remove(&msg.menu_index) {
f(self)?;
self.callback.insert(msg.menu_index, f);
}
}
if self.callback.contains_key(&msg.menu_index) {
if let Some(mut f) = self.callback.remove(&msg.menu_index) {
f(self)?;
self.callback.insert(msg.menu_index, f);
}
}
Ok(false)
}

pub fn wait_for_message(&mut self) -> Result<(), Error> {
loop {
let quit = self.get_message()?;
if quit {
break;
}
}
Ok(())
}
}
Expand Down