Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.
Rust downloadmanagerguihacktoberfesthomebrewlightweightlinuxlinux-distributionlocal-firstmacosmacos-packagemedia-toolboxopen-sourcerustsveltetauritrendingtrending-repositorieswindowswindows-desktopytdlp
fix: improve authentication flow by adding polling delay and logging for cookie retrieval
Tonho19a672d5db11
diff --git a/src-tauri/src/platforms/hotmart/auth.rs b/src-tauri/src/platforms/hotmart/auth.rsindex 687feb8c..5dd38dfb 100644--- a/src-tauri/src/platforms/hotmart/auth.rs+++ b/src-tauri/src/platforms/hotmart/auth.rs@@ -326,10 +326,12 @@ pub async fn authenticate(tokio::time::sleep(Duration::from_millis(500)).await;}+ let login_url = "https://sso.hotmart.com/login?redirect=https%3A%2F%2Fconsumer.hotmart.com";+let login_window = tauri::WebviewWindowBuilder::new(app,"hotmart-login",- tauri::WebviewUrl::External("https://sso.hotmart.com/login".parse().unwrap()),+ tauri::WebviewUrl::External(login_url.parse().unwrap()),).title("Hotmart Login").inner_size(500.0, 700.0)@@ -338,9 +340,12 @@ pub async fn authenticate(let host = url.host_str().unwrap_or("");let url_str = url.as_str();+ tracing::info!("[auth] navigation → {} (host={})", url_str, host);+if host == "consumer.hotmart.com"|| host.ends_with(".club.hotmart.com")|| url_str.contains("dashboard")+ || (host.ends_with(".hotmart.com") && host != "sso.hotmart.com"){post_login_flag.store(true, std::sync::atomic::Ordering::Relaxed);}@@ -369,6 +374,8 @@ pub async fn authenticate(let start = std::time::Instant::now();let timeout = Duration::from_secs(120);+ let poll_start_delay = Duration::from_secs(5);+ let mut last_log_secs: u64 = 0;loop {if start.elapsed() > timeout {@@ -380,77 +387,66 @@ pub async fn authenticate(let _ = app.emit("hotmart-auth-captcha", ());}- if post_login_detected.load(std::sync::atomic::Ordering::Relaxed) {- let poll_start = std::time::Instant::now();- let poll_timeout = Duration::from_secs(15);- let poll_interval = Duration::from_millis(500);-- let cookies = loop {- #[cfg(windows)]- let cookies = extract_webview_cookies(&login_window).await?;- #[cfg(not(windows))]- let cookies = extract_webview_cookies_js(&login_window, &cookie_data).await?;-- let has_token = cookies.iter().any(|(name, _)| name == "hmVlcIntegration");- if has_token {- let elapsed = poll_start.elapsed();- tracing::info!(- "hmVlcIntegration cookie found after {:.1}s",- elapsed.as_secs_f64()- );- break cookies;- }+ let nav_detected = post_login_detected.load(std::sync::atomic::Ordering::Relaxed);+ let should_poll = nav_detected || start.elapsed() > poll_start_delay;- if poll_start.elapsed() > poll_timeout {- let cookie_names: Vec<&str> =- cookies.iter().map(|(n, _)| n.as_str()).collect();- tracing::warn!(- "hmVlcIntegration not found after {}s. Available cookies: {:?}",- poll_timeout.as_secs(),- cookie_names- );- break cookies;- }+ if should_poll {+ #[cfg(windows)]+ let cookies = extract_webview_cookies(&login_window).await?;+ #[cfg(not(windows))]+ let cookies = extract_webview_cookies_js(&login_window, &cookie_data).await?;- tokio::time::sleep(poll_interval).await;- };+ let has_token = cookies.iter().any(|(name, _)| name == "hmVlcIntegration");- let _ = login_window.close();+ if has_token {+ tracing::info!(+ "[auth] hmVlcIntegration found after {:.1}s (nav_detected={})",+ start.elapsed().as_secs_f64(),+ nav_detected+ );+ let _ = login_window.close();++ let token = cookies+ .iter()+ .find(|(name, _)| name == "hmVlcIntegration")+ .map(|(_, value)| value.clone())+ .unwrap();++ let saved = SavedSession {+ token: token.clone(),+ email: email.to_string(),+ cookies: cookies.clone(),+ saved_at: std::time::SystemTime::now()+ .duration_since(std::time::UNIX_EPOCH)+ .unwrap_or_default()+ .as_secs(),+ };++ let client = build_client_from_saved(&saved)?;++ return Ok(HotmartSession {+ token,+ email: email.to_string(),+ client,+ cookies,+ });+ }- let token = cookies- .iter()- .find(|(name, _)| name == "hmVlcIntegration")- .map(|(_, value)| value.clone())- .ok_or_else(|| {- let cookie_names: Vec<&str> =- cookies.iter().map(|(n, _)| n.as_str()).collect();- tracing::warn!(- "hmVlcIntegration not found. Available cookies: {:?}",- cookie_names- );- anyhow!("Cookie hmVlcIntegration não encontrado.")- })?;-- let saved = SavedSession {- token: token.clone(),- email: email.to_string(),- cookies: cookies.clone(),- saved_at: std::time::SystemTime::now()- .duration_since(std::time::UNIX_EPOCH)- .unwrap_or_default()- .as_secs(),- };-- let client = build_client_from_saved(&saved)?;-- return Ok(HotmartSession {- token,- email: email.to_string(),- client,- cookies,- });+ let elapsed_secs = start.elapsed().as_secs();+ if elapsed_secs >= last_log_secs + 5 {+ last_log_secs = elapsed_secs;+ let cookie_names: Vec<&str> =+ cookies.iter().map(|(n, _)| n.as_str()).collect();+ tracing::info!(+ "[auth] polling at {}s, {} cookies: {:?}",+ elapsed_secs,+ cookies.len(),+ cookie_names+ );+ }}- tokio::time::sleep(Duration::from_millis(500)).await;+ let sleep_ms = if nav_detected { 500 } else { 2000 };+ tokio::time::sleep(Duration::from_millis(sleep_ms)).await;}}