summary refs log tree commit diff
diff options
context:
space:
mode:
authorAshelyn Rose <git@ashen.earth>2025-02-19 16:05:39 -0700
committerAshelyn Rose <git@ashen.earth>2025-02-19 16:05:39 -0700
commit665a4904f89bb842a7ba211abdda62349eac8a03 (patch)
tree849235c7e531946c1c80c321c23be298c30ffec3
parente8314458ccdf4d3c68969b206cd29f2490fb6308 (diff)
Simplify calling async from non-async inside oauth controller
-rw-r--r--app/src/lib.rs9
-rw-r--r--app/src/oauth.rs9
2 files changed, 8 insertions, 10 deletions
diff --git a/app/src/lib.rs b/app/src/lib.rs
index 8ad149f..9823cdd 100644
--- a/app/src/lib.rs
+++ b/app/src/lib.rs
@@ -24,7 +24,7 @@ pub fn run() {
         .plugin(tauri_plugin_opener::init())
         .setup(|app| {
             app.manage(AppState {
-                oauth_controller: OAuthController::new()
+                oauth_controller: OAuthController::new(tauri::async_runtime::handle())
             });
 
             #[cfg(any(target_os = "linux", all(debug_assertions, windows)))]
@@ -52,12 +52,9 @@ pub fn run() {
                         if let Ok(state) = Uuid::try_parse(&state) {
                             let state = state.clone();
                             let auth_code = auth_code.to_string().clone();
-                            let app_handle = app_handle.clone();
-                            let oauth_controller = app_handle.state::<AppState>().oauth_controller.clone();
+                            let oauth_controller = &app_handle.state::<AppState>().oauth_controller;
 
-                            tauri::async_runtime::spawn(async move {
-                                oauth_controller.resolve_code(state, auth_code);
-                            });
+                            oauth_controller.resolve_code(state, auth_code);
                         } else {
                             println!("Invalid UUID format: {state}");
                             return
diff --git a/app/src/oauth.rs b/app/src/oauth.rs
index 795d5dc..9334eac 100644
--- a/app/src/oauth.rs
+++ b/app/src/oauth.rs
@@ -1,12 +1,13 @@
 use std::{collections::HashMap, sync::Arc};
 use serde::Deserialize;
+use tauri::async_runtime::RuntimeHandle;
 use tokio::sync::Mutex;
 use tokio::sync::oneshot::{channel, Sender, Receiver};
 use uuid::Uuid;
 
 use crate::OAUTH_CLIENT_NAME;
 #[derive(Clone)]
-pub struct OAuthController (Arc<Mutex<OAuthInternal>>);
+pub struct OAuthController (Arc<Mutex<OAuthInternal>>, RuntimeHandle);
 
 type ServerDomain = String;
 type AccountIdentifier = String;
@@ -50,11 +51,11 @@ pub struct AddServerResult {
 }
 
 impl OAuthController {
-    pub fn new() -> Self {
+    pub fn new(runtime_handle: RuntimeHandle) -> Self {
         Self(Arc::new(Mutex::new(OAuthInternal {
             servers: HashMap::new(),
             open_callbacks: HashMap::new(),
-        })))
+        })), runtime_handle)
     }
 
     pub async fn add_server(&self, instance_domain: &str) -> Result<AddServerResult, String> {
@@ -110,7 +111,7 @@ impl OAuthController {
     }
 
     pub fn resolve_code(&self, state: StateCode, auth_code: String) {
-        let runtime = tokio::runtime::Handle::current();
+        let runtime = self.1.clone();
         let inner_self = self.0.clone();
         let state = state.clone();