format: paket.login
This commit is contained in:
parent
6fbdc6193c
commit
0dc60250e6
1 changed files with 41 additions and 51 deletions
|
@ -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,18 +117,16 @@ 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 {
|
||||
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
|
||||
|
@ -141,9 +137,8 @@ impl AsyncComponent for Login {
|
|||
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(),
|
||||
);
|
||||
model.refresh_token =
|
||||
Some(RefreshToken::new(refresh_token.to_string()).unwrap());
|
||||
sender.input(LoginInput::NeedsRefresh);
|
||||
} else {
|
||||
sender.input(LoginInput::NeedsLogin);
|
||||
|
@ -157,14 +152,12 @@ impl AsyncComponent for Login {
|
|||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
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<URIRequest> {
|
||||
if self.state != LoginState::InFlow {
|
||||
|
|
Loading…
Reference in a new issue