Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
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