From 14aeabeed29f0851b697f8a55e7df9a94b9b1a41 Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Thu, 17 Oct 2024 22:07:55 +0200 Subject: [PATCH] fix: listen for device flow completion without requiring enter --- CHANGELOG.md | 1 + src/cli/commands/auth/login.rs | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc37429..3bc110c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed - Use updated aliases when reusing lockfile dependencies by @daimond113 +- Listen for device flow completion without requiring pressing enter by @daimond113 ## [0.5.0-rc.6] - 2024-10-14 ### Added diff --git a/src/cli/commands/auth/login.rs b/src/cli/commands/auth/login.rs index 59cc0c6..52d3dff 100644 --- a/src/cli/commands/auth/login.rs +++ b/src/cli/commands/auth/login.rs @@ -2,6 +2,7 @@ use anyhow::Context; use clap::Args; use colored::Colorize; use serde::Deserialize; +use std::thread::spawn; use url::Url; use pesde::{ @@ -81,19 +82,21 @@ impl LoginCommand { response.verification_uri.as_str().blue() ); - { - let mut input = String::new(); - std::io::stdin() - .read_line(&mut input) - .context("failed to read input")?; - } - - match open::that(response.verification_uri.as_str()) { - Ok(_) => (), - Err(e) => { - eprintln!("failed to open browser: {e}"); + spawn(move || { + { + let mut input = String::new(); + std::io::stdin() + .read_line(&mut input) + .expect("failed to read input"); } - } + + match open::that(response.verification_uri.as_str()) { + Ok(_) => (), + Err(e) => { + eprintln!("failed to open browser: {e}"); + } + } + }); let mut time_left = response.expires_in; let mut interval = std::time::Duration::from_secs(response.interval);