store config in database, macro for state access

This commit is contained in:
Joseph Montanaro
2022-12-22 16:36:32 -08:00
parent 398916fe10
commit 61d674199f
10 changed files with 144 additions and 38 deletions

View File

@ -52,7 +52,7 @@ impl Handler {
let req = Request {id: self.request_id, clients};
self.app.emit_all("credentials-request", &req)?;
let starting_visibility = self.ensure_visible()?;
let starting_visibility = self.show_window()?;
match self.wait_for_response().await? {
Approval::Approved => self.send_credentials().await?,
@ -68,11 +68,13 @@ impl Handler {
// and b) there are no other pending requests
let state = self.app.state::<AppState>();
if !starting_visibility && state.req_count() == 0 {
let handle = self.app.app_handle();
tauri::async_runtime::spawn(async move {
sleep(Duration::from_secs(3)).await;
let _ = handle.get_window("main").map(|w| w.hide());
});
let delay = {
let config = state.config.read().unwrap();
Duration::from_millis(config.rehide_ms)
};
sleep(delay).await;
let window = self.app.get_window("main").ok_or(RequestError::NoMainWindow)?;
window.hide()?;
}
Ok(())
@ -104,7 +106,7 @@ impl Handler {
clients.iter().any(|c| state.is_banned(c))
}
fn ensure_visible(&self) -> Result<bool, RequestError> {
fn show_window(&self) -> Result<bool, RequestError> {
let window = self.app.get_window("main").ok_or(RequestError::NoMainWindow)?;
let starting_visibility = window.is_visible()?;
if !starting_visibility {