sign in auth flow 👍

This commit is contained in:
2025-11-27 13:28:33 +08:00
parent 6fe397e868
commit bafbe271d8
9 changed files with 838 additions and 51 deletions

View File

@@ -1,17 +1,39 @@
use tauri::Manager;
use tauri_plugin_positioner::WindowExt;
use tracing::{error, info};
use crate::{
core::services::auth::get_tokens,
get_app_handle,
services::overlay::{overlay_fullscreen, SCENE_WINDOW_LABEL},
};
pub async fn start_fdoll() {
initialize_session().await;
init_session().await;
}
pub async fn initialize_session() {
let webview_window = tauri::WebviewWindowBuilder::new(
pub async fn init_session() {
match get_tokens().await {
Some(_) => {
info!("User session restored");
create_scene().await;
}
None => {
info!("No active session, user needs to authenticate");
crate::core::services::auth::init_auth_code_retrieval(|| {
info!("Authentication successful, creating scene...");
tauri::async_runtime::spawn(async {
info!("Creating scene after auth success...");
create_scene().await;
});
});
}
}
}
pub async fn create_scene() {
info!("Starting scene creation...");
let webview_window = match tauri::WebviewWindowBuilder::new(
get_app_handle(),
SCENE_WINDOW_LABEL,
tauri::WebviewUrl::App("/scene".into()),
@@ -27,19 +49,42 @@ pub async fn initialize_session() {
.always_on_top(true)
.visible_on_all_workspaces(true)
.build()
.expect("Failed to display scene screen");
{
Ok(window) => {
info!("Scene window builder succeeded");
window
}
Err(e) => {
error!("Failed to build scene window: {}", e);
return;
}
};
webview_window
.move_window(tauri_plugin_positioner::Position::Center)
.unwrap();
if let Err(e) = webview_window.move_window(tauri_plugin_positioner::Position::Center) {
error!("Failed to move scene window to center: {}", e);
return;
}
let window = get_app_handle().get_window(webview_window.label()).unwrap();
overlay_fullscreen(&window).unwrap();
window.set_ignore_cursor_events(true).unwrap();
let window = match get_app_handle().get_window(webview_window.label()) {
Some(window) => window,
None => {
error!("Failed to get scene window after creation");
return;
}
};
if let Err(e) = overlay_fullscreen(&window) {
error!("Failed to set overlay fullscreen: {}", e);
return;
}
if let Err(e) = window.set_ignore_cursor_events(true) {
error!("Failed to set ignore cursor events: {}", e);
return;
}
#[cfg(debug_assertions)]
webview_window.open_devtools();
println!("Scene window initialized.");
crate::core::services::auth::get_auth_code();
info!("Scene window initialized successfully.");
}