diff --git a/paket/src/login.rs b/paket/src/login.rs index 6bb23f2..bdc6015 100644 --- a/paket/src/login.rs +++ b/paket/src/login.rs @@ -6,13 +6,11 @@ use std::{ }; use adw::prelude::*; -use gtk::prelude::*; use libpaket::{ login::{create_nonce, CodeVerfier, DHLIdToken, RefreshToken, TokenResponse}, LibraryError, LibraryResult, OpenIdClient, }; use relm4::{ - adw, gtk, prelude::*, tokio::{sync::Mutex, time::sleep}, AsyncComponentSender, SharedState, @@ -119,52 +117,47 @@ impl AsyncComponent for Login { tracker: 0, }; - { - let result = oo7::Keyring::new().await; - match result { - Ok(keyring) => { - KEYRING.set(keyring).unwrap(); - { - let keyring = KEYRING.get().unwrap(); - if let Err(err) = keyring.unlock().await { - sender - .output(LoginOutput::KeyringError(err)) - .expect("sender not worky"); - } else { - match keyring - .search_items(&HashMap::from(KEYRING_ATTRIBUTES)) - .await - { - Ok(res) => { - if res.len() > 0 { - let item = &res[0]; - let refresh_token = item.secret().await.unwrap(); - let refresh_token = - std::str::from_utf8(refresh_token.as_slice()).unwrap(); - model.refresh_token = Some( - RefreshToken::new(refresh_token.to_string()).unwrap(), - ); - sender.input(LoginInput::NeedsRefresh); - } else { - sender.input(LoginInput::NeedsLogin); - } - } - Err(err) => { - sender - .output(LoginOutput::KeyringError(err)) - .expect("sender not worky"); - } - }; - } - } - } - Err(err) => { + let result = oo7::Keyring::new().await; + match result { + Ok(keyring) => { + KEYRING.set(keyring).unwrap(); + if let Err(err) = KEYRING.get().unwrap().unlock().await { sender .output(LoginOutput::KeyringError(err)) .expect("sender not worky"); + } else { + let keyring = KEYRING.get().unwrap(); + match keyring + .search_items(&HashMap::from(KEYRING_ATTRIBUTES)) + .await + { + Ok(res) => { + if res.len() > 0 { + let item = &res[0]; + let refresh_token = item.secret().await.unwrap(); + let refresh_token = + std::str::from_utf8(refresh_token.as_slice()).unwrap(); + model.refresh_token = + Some(RefreshToken::new(refresh_token.to_string()).unwrap()); + sender.input(LoginInput::NeedsRefresh); + } else { + sender.input(LoginInput::NeedsLogin); + } + } + Err(err) => { + sender + .output(LoginOutput::KeyringError(err)) + .expect("sender not worky"); + } + }; } - }; - } + } + Err(err) => { + sender + .output(LoginOutput::KeyringError(err)) + .expect("sender not worky"); + } + }; let webcontext = WebContext::builder().build(); { @@ -204,7 +197,10 @@ impl AsyncComponent for Login { match message { LoginInput::NeedsRefresh => { let refresh_token = self.refresh_token.as_ref().unwrap().clone(); - sender.oneshot_command(async { use_refresh_token(refresh_token).await }) + sender.oneshot_command(async { + let res = use_refresh_token(refresh_token).await; + res + }); } LoginInput::ReceivedAuthCode(auth_code) => { self.set_state(LoginState::Offline); @@ -254,12 +250,6 @@ impl AsyncComponent for Login { } } -#[derive(PartialEq)] -enum ResponseType { - Retry, - Okay, -} - impl Login { fn construct_request_uri(&self) -> Option { if self.state != LoginState::InFlow {