mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-02 18:31:50 -04:00
refactor: show retrying UI
This commit is contained in:
parent
c4fa91f6ea
commit
2136c3aa25
@ -84,9 +84,18 @@ impl AuthData {
|
||||
}
|
||||
|
||||
fn check(&self) -> bool {
|
||||
let username_valid = self.username.clone().is_some_and(|username| !username.is_empty());
|
||||
let prelogin_cookie_valid = self.prelogin_cookie.clone().is_some_and(|val| val.len() > 5);
|
||||
let portal_userauthcookie_valid = self.portal_userauthcookie.clone().is_some_and(|val| val.len() > 5);
|
||||
let username_valid = self
|
||||
.username
|
||||
.clone()
|
||||
.is_some_and(|username| !username.is_empty());
|
||||
let prelogin_cookie_valid = self
|
||||
.prelogin_cookie
|
||||
.clone()
|
||||
.is_some_and(|val| val.len() > 5);
|
||||
let portal_userauthcookie_valid = self
|
||||
.portal_userauthcookie
|
||||
.clone()
|
||||
.is_some_and(|val| val.len() > 5);
|
||||
|
||||
username_valid && (prelogin_cookie_valid || portal_userauthcookie_valid)
|
||||
}
|
||||
@ -247,7 +256,7 @@ async fn monitor_events(window: &Window, event_rx: mpsc::Receiver<AuthEvent>) ->
|
||||
}
|
||||
|
||||
async fn monitor_auth_event(window: &Window, mut event_rx: mpsc::Receiver<AuthEvent>) -> AuthData {
|
||||
info!("Monitoring auth events");
|
||||
info!("Start monitoring auth events");
|
||||
|
||||
let (cancel_timeout_tx, cancel_timeout_rx) = mpsc::channel::<()>(1);
|
||||
let cancel_timeout_rx = Arc::new(Mutex::new(cancel_timeout_rx));
|
||||
@ -272,6 +281,23 @@ async fn monitor_auth_event(window: &Window, mut event_rx: mpsc::Receiver<AuthEv
|
||||
return auth_data;
|
||||
}
|
||||
AuthEvent::Error(AuthError::TokenInvalid) => {
|
||||
let _ = window.with_webview(|wv| {
|
||||
let wv = wv.inner();
|
||||
let url = wv.uri().unwrap_or("<empty>".into());
|
||||
|
||||
info!("Injecting loading element to {}", redact_url(&url));
|
||||
wv.run_javascript(
|
||||
r#"
|
||||
var loading = document.createElement("div");
|
||||
loading.innerHTML = '<div style="position: absolute; width: 100%; text-align: center; font-size: 20px; font-weight: bold; top: 50%; left: 50%; transform: translate(-50%, -50%);">Got invalid token, retrying...</div>';
|
||||
loading.style = "position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255, 255, 255, 0.85); z-index: 99999;";
|
||||
document.body.appendChild(loading);
|
||||
"#,
|
||||
Cancellable::NONE,
|
||||
|_| info!("Injected loading element successfully"),
|
||||
);
|
||||
});
|
||||
|
||||
// Found the invalid token, means that user is authenticated, keep retrying and no need to show the window
|
||||
warn!(
|
||||
"Attempt #{} failed, found invalid token, retrying",
|
||||
|
Loading…
Reference in New Issue
Block a user