diff --git a/daemon/src/main.rs b/daemon/src/main.rs index ff30c0c..7cac8cb 100644 --- a/daemon/src/main.rs +++ b/daemon/src/main.rs @@ -95,35 +95,43 @@ pub async fn main() -> eyre::Result<()> { response.body.interval(), )); - let (refresh_token, account_name) = loop { - interval.tick().await; - let request = CAuthentication_PollAuthSessionStatus_Request { - client_id: response.body.client_id, - request_id: response.body.request_id.clone(), - ..Default::default() - }; - let response: CMProtoBufMessage = session - .call_service_method( - "Authentication.PollAuthSessionStatus#1".to_string(), - request, - ) - .await?; + let session_cloned = session.clone(); + let poll_handle = tokio::spawn(async move { + let mut session = session_cloned; + loop { + interval.tick().await; + let request = CAuthentication_PollAuthSessionStatus_Request { + client_id: response.body.client_id, + request_id: response.body.request_id.clone(), + ..Default::default() + }; + let response: CMProtoBufMessage = + session + .call_service_method( + "Authentication.PollAuthSessionStatus#1".to_string(), + request, + ) + .await + .expect("Failed to call PollAuthSessionStatus"); - log::debug!("Got auth poll status {:#?}", response.body); + log::debug!("Got auth poll status {:#?}", response.body); - if let Some(access_token) = response.body.refresh_token { - let account_name = response.body.account_name.unwrap_or_default(); - break (access_token, account_name); + if let Some(refresh_token) = response.body.refresh_token { + let account_name = response.body.account_name.unwrap_or_default(); + break (refresh_token, account_name); + } + + if let Some(new_url) = response.body.new_challenge_url { + let code = qrcode::QrCode::new(new_url).expect("Failed to create QR Code"); + log::info!( + "Got new QR code:\n{}", + code.render::().build() + ) + }; } + }); - if let Some(new_url) = response.body.new_challenge_url { - let code = qrcode::QrCode::new(new_url)?; - log::info!( - "Got new QR code:\n{}", - code.render::().build() - ) - }; - }; + let (refresh_token, account_name) = poll_handle.await?; log::debug!( "Got account name {}, access token {}",