You've already forked AstralRinth
forked from didirus/AstralRinth
Hydra local (#594)
* initial commit * merge fixes * added sanitizing * linter * Improve sign in UI * simple simple! * bump version --------- Co-authored-by: CodexAdrian <83074853+CodexAdrian@users.noreply.github.com> Co-authored-by: Jai A <jaiagr+gpg@pm.me>
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use crate::launcher::auth::Credentials;
|
||||
use crate::{
|
||||
hydra::{self, init::DeviceLoginSuccess},
|
||||
launcher::auth::Credentials,
|
||||
};
|
||||
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
@@ -8,7 +11,7 @@ use tokio::task::JoinHandle;
|
||||
|
||||
pub struct AuthTask(
|
||||
#[allow(clippy::type_complexity)]
|
||||
Option<JoinHandle<crate::Result<(Credentials, Option<String>)>>>,
|
||||
Option<JoinHandle<crate::Result<Credentials>>>,
|
||||
);
|
||||
|
||||
impl AuthTask {
|
||||
@@ -16,32 +19,24 @@ impl AuthTask {
|
||||
AuthTask(None)
|
||||
}
|
||||
|
||||
pub async fn begin_auth() -> crate::Result<url::Url> {
|
||||
pub async fn begin_auth() -> crate::Result<DeviceLoginSuccess> {
|
||||
let state = crate::State::get().await?;
|
||||
// Init task, get url
|
||||
let login = hydra::init::init().await?;
|
||||
|
||||
// Creates a channel to receive the URL
|
||||
let (tx, rx) = tokio::sync::oneshot::channel::<url::Url>();
|
||||
let task = tokio::spawn(crate::auth::authenticate(tx));
|
||||
|
||||
// If receiver is dropped, try to get Hydra error
|
||||
let url = rx.await;
|
||||
let url = match url {
|
||||
Ok(url) => url,
|
||||
Err(e) => {
|
||||
task.await??;
|
||||
return Err(e.into()); // truly a dropped receiver
|
||||
}
|
||||
};
|
||||
// Await completion
|
||||
let task = tokio::spawn(hydra::complete::wait_finish(
|
||||
login.device_code.clone(),
|
||||
));
|
||||
|
||||
// Flow is going, store in state and return
|
||||
let mut write = state.auth_flow.write().await;
|
||||
write.0 = Some(task);
|
||||
|
||||
Ok(url)
|
||||
Ok(login)
|
||||
}
|
||||
|
||||
pub async fn await_auth_completion(
|
||||
) -> crate::Result<(Credentials, Option<String>)> {
|
||||
pub async fn await_auth_completion() -> crate::Result<Credentials> {
|
||||
// Gets the task handle from the state, replacing with None
|
||||
let task = {
|
||||
let state = crate::State::get().await?;
|
||||
|
||||
Reference in New Issue
Block a user