Move waiting for QR to task

This commit is contained in:
Artemis Tosini 2024-09-04 21:29:49 +00:00
parent 4207832545
commit 277967fae9
Signed by: artemist
GPG key ID: ADFFE553DCBB831E

View file

@ -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<CAuthentication_PollAuthSessionStatus_Response> = 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<CAuthentication_PollAuthSessionStatus_Response> =
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::<qrcode::render::unicode::Dense1x2>().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::<qrcode::render::unicode::Dense1x2>().build()
)
};
};
let (refresh_token, account_name) = poll_handle.await?;
log::debug!(
"Got account name {}, access token {}",