move re-hide to main request handler
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
use core::time::Duration;
|
||||
use std::io;
|
||||
use std::net::{SocketAddr, SocketAddrV4};
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::sync::oneshot;
|
||||
use tokio::time::sleep;
|
||||
|
||||
use tauri::{AppHandle, Manager};
|
||||
|
||||
@ -49,7 +51,8 @@ impl Handler {
|
||||
}
|
||||
|
||||
let req = Request {id: self.request_id, clients};
|
||||
self.notify_frontend(&req).await?;
|
||||
self.app.emit_all("credentials-request", &req)?;
|
||||
let starting_visibility = self.ensure_visible()?;
|
||||
|
||||
match self.wait_for_response().await? {
|
||||
Approval::Approved => self.send_credentials().await?,
|
||||
@ -61,6 +64,17 @@ impl Handler {
|
||||
}
|
||||
}
|
||||
|
||||
// only hide the window if a) it was hidden to start with
|
||||
// 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());
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -90,15 +104,15 @@ impl Handler {
|
||||
clients.iter().any(|c| state.is_banned(c))
|
||||
}
|
||||
|
||||
async fn notify_frontend(&self, req: &Request) -> Result<(), RequestError> {
|
||||
self.app.emit_all("credentials-request", req)?;
|
||||
fn ensure_visible(&self) -> Result<bool, RequestError> {
|
||||
let window = self.app.get_window("main").ok_or(RequestError::NoMainWindow)?;
|
||||
if !window.is_visible()? {
|
||||
let starting_visibility = window.is_visible()?;
|
||||
if !starting_visibility {
|
||||
window.unminimize()?;
|
||||
window.show()?;
|
||||
}
|
||||
window.set_focus()?;
|
||||
Ok(())
|
||||
Ok(starting_visibility)
|
||||
}
|
||||
|
||||
async fn wait_for_response(&mut self) -> Result<Approval, RequestError> {
|
||||
|
Reference in New Issue
Block a user