Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 6 additions & 76 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 7 additions & 64 deletions apps/voxit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ enum AuthEvent {
SignedIn(AuthRecord),
StatusChecked(AuthStatus),
DeviceCodeInfo { user_code: String, verification_uri: String },
Status(String),
Failed(String),
}

Expand Down Expand Up @@ -384,10 +383,6 @@ impl VoxitApp {
self.status =
"Device code shown in panel. Open the URL and enter the code.".to_string();
},
AuthEvent::Status(message) => {
self.auth_busy = true;
self.status = message;
},
AuthEvent::Failed(err) => {
self.device_code_user_code = None;
self.device_code_verification_uri = None;
Expand Down Expand Up @@ -505,69 +500,26 @@ impl VoxitApp {
self.auth_busy = true;
self.device_code_user_code = None;
self.device_code_verification_uri = None;
self.status = "Starting browser login...".to_string();
self.status = "Starting ChatGPT device code login...".to_string();

let tx = self.auth_event_tx.clone();
#[cfg(target_os = "macos")]
let _ = voxit_macos::activate_current_application();

thread::spawn(move || {
let event = match auth::sign_in_with_chatgpt() {
let event = match auth::sign_in_with_chatgpt(|user_code, verification_uri| {
let _ = tx.send(AuthEvent::DeviceCodeInfo {
user_code: user_code.to_string(),
verification_uri: verification_uri.to_string(),
});
}) {
Ok(record) => AuthEvent::SignedIn(record),
Err(err) if is_browser_login_timeout_error(&err) => {
let _ = tx.send(AuthEvent::Status(
"Browser login timed out. Switching to device-code login.".to_string(),
));

match auth::sign_in_with_device_code_with_progress(
|user_code, verification_uri| {
let _ = tx.send(AuthEvent::DeviceCodeInfo {
user_code: user_code.to_string(),
verification_uri: verification_uri.to_string(),
});
},
) {
Ok(record) => AuthEvent::SignedIn(record),
Err(device_code_err) => AuthEvent::Failed(format!(
"browser timeout: {err}; device code login failed: {device_code_err}"
)),
}
},
Err(err) => AuthEvent::Failed(err),
};
let _ = tx.send(event);
});
}

fn start_sign_in_with_device_code(&mut self) {
if self.auth_busy {
return;
}

self.auth_busy = true;
self.device_code_user_code = None;
self.device_code_verification_uri = None;
self.status = "Starting device code login...".to_string();

let tx = self.auth_event_tx.clone();
#[cfg(target_os = "macos")]
let _ = voxit_macos::activate_current_application();

thread::spawn(move || {
let event =
match auth::sign_in_with_device_code_with_progress(|user_code, verification_uri| {
let _ = tx.send(AuthEvent::DeviceCodeInfo {
user_code: user_code.to_string(),
verification_uri: verification_uri.to_string(),
});
}) {
Ok(record) => AuthEvent::SignedIn(record),
Err(err) => AuthEvent::Failed(err),
};
let _ = tx.send(event);
});
}

fn sign_out(&mut self) {
self.device_code_user_code = None;
self.device_code_verification_uri = None;
Expand Down Expand Up @@ -1009,9 +961,6 @@ impl VoxitApp {
if ui.add_enabled(can_auth, Button::new("Sign in with ChatGPT")).clicked() {
self.start_sign_in_with_chatgpt();
}
if ui.add_enabled(can_auth, Button::new("Device code login")).clicked() {
self.start_sign_in_with_device_code();
}
}
});
}
Expand Down Expand Up @@ -1297,12 +1246,6 @@ impl App for VoxitApp {
}
}

fn is_browser_login_timeout_error(message: &str) -> bool {
let message = message.to_lowercase();

message.contains("browser login timeout") || message.contains("callback timeout")
}

fn ensure_app_data_dir(app_root: &Path) -> Result<()> {
fs::create_dir_all(app_root).map_err(|err| {
crate::prelude::eyre!("Failed to create app data directory {}: {err}", app_root.display())
Expand Down
2 changes: 0 additions & 2 deletions packages/voxit-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ futures-util = { version = "0.3", optional = true }
hound = { version = "3.5" }
http = { version = "1.3", optional = true }
keyring = { version = "3.6", features = ["apple-native"] }
rand = { version = "0.10" }
reqwest = { version = "0.13", default-features = false, features = ["blocking", "json", "multipart", "rustls"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
sha2 = { version = "0.10" }
tiny_http = { version = "0.12" }
tokio = { version = "1.47", features = ["rt-multi-thread", "time"], optional = true }
tokio-tungstenite = { version = "0.28", default-features = false, features = ["connect", "rustls-tls-native-roots"], optional = true }
tracing = { version = "0.1" }
Expand Down
Loading
Loading