diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index f5a8bd4a..73198816 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -962,6 +962,7 @@ dependencies = [ name = "epherome-beta" version = "0.0.0" dependencies = [ + "once_cell", "serde", "serde_json", "tauri", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index fad0c0e4..f04c03f7 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -18,6 +18,7 @@ tauri = { version = "1.5", features = [ "api-all", serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" zip = "0.6.6" +once_cell = "1.19.0" [features] # this feature is used for production builds or when `devPath` points to the filesystem diff --git a/src-tauri/src/core/auth.rs b/src-tauri/src/core/auth.rs new file mode 100644 index 00000000..8b58b756 --- /dev/null +++ b/src-tauri/src/core/auth.rs @@ -0,0 +1,36 @@ +use tauri::Manager; + +#[tauri::command] +pub fn get_microsoft_auth_code(app_handle: tauri::AppHandle) { + tauri::WindowBuilder::new( + &app_handle, + "oauth", + tauri::WindowUrl::External( + "https://login.live.com/oauth20_authorize.srf\ + ?client_id=00000000402b5328\ + &response_type=code\ + &prompt=login\ + &scope=service%3A%3Auser.auth.xboxlive.com%3A%3AMBI_SSL\ + &redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf" + .parse() + .unwrap(), + ), + ) + .title("Log in to Microsoft...") + .on_navigation(|url| { + let prefix = "https://login.live.com/oauth20_desktop.srf?"; + let url = url.to_string(); + if url.starts_with(prefix) { + let auth_code = url.replace(prefix, ""); + if let Some(app_handle) = crate::INSTANCE.get() { + app_handle.emit_all("auth-code", auth_code).unwrap(); + if let Some(window) = app_handle.get_window("oauth") { + window.close().unwrap(); + } + } + } + true + }) + .build() + .unwrap(); +} diff --git a/src-tauri/src/core/mod.rs b/src-tauri/src/core/mod.rs index ba556561..6dc8c8aa 100644 --- a/src-tauri/src/core/mod.rs +++ b/src-tauri/src/core/mod.rs @@ -1,2 +1,3 @@ +pub mod auth; pub mod runner; pub mod zip; diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index fe7fb6ad..8fc82c68 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,13 +1,23 @@ // Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] +use once_cell::sync::OnceCell; +use tauri::AppHandle; + +pub static INSTANCE: OnceCell = OnceCell::new(); + mod core; fn main() { tauri::Builder::default() + .setup(|app| { + INSTANCE.set(app.handle()).unwrap(); + Ok(()) + }) .invoke_handler(tauri::generate_handler![ core::zip::extract_zip, - core::runner::run_minecraft + core::runner::run_minecraft, + core::auth::get_microsoft_auth_code, ]) .run(tauri::generate_context!()) .expect("error while running tauri application");