From 4795fb387ef63a58fd82343e84ea941a574c6883 Mon Sep 17 00:00:00 2001 From: hazre Date: Sat, 14 Mar 2026 19:18:23 +0100 Subject: [PATCH] fix: move window creation into rust side for easier control --- src-tauri/src/desktop_tray.rs | 38 +++++++++++++--------------------- src-tauri/src/lib.rs | 7 +------ src-tauri/tauri.conf.json | 13 ++---------- src/app/pages/auth/SSOTauri.ts | 4 +++- 4 files changed, 20 insertions(+), 42 deletions(-) diff --git a/src-tauri/src/desktop_tray.rs b/src-tauri/src/desktop_tray.rs index 9b60ecb64..8dac6ad70 100644 --- a/src-tauri/src/desktop_tray.rs +++ b/src-tauri/src/desktop_tray.rs @@ -3,7 +3,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use tauri::{ menu::{Menu, MenuEvent, MenuItem}, tray::{MouseButton, TrayIcon, TrayIconBuilder, TrayIconEvent}, - AppHandle, Manager, RunEvent, WebviewUrl, WebviewWindow, WebviewWindowBuilder, + AppHandle, Manager, RunEvent, WebviewUrl, WebviewWindowBuilder, }; pub const MAIN_WINDOW_LABEL: &str = "main"; @@ -113,20 +113,13 @@ fn handle_tray_double_click(app: &AppHandle, event: &TrayI } } -pub fn configure_main_window(_window: &WebviewWindow) { - #[cfg(target_os = "windows")] - { - let _ = _window.set_decorations(false); - } -} - pub fn handle_run_event(app: &AppHandle, event: RunEvent) { if let RunEvent::ExitRequested { code, api, .. } = event { handle_exit_request(app, code, &api); } } -pub fn show_or_create_main_window(app: &AppHandle) -> tauri::Result<()> { +pub fn show_or_create_main_window(app: &AppHandle) -> tauri::Result<()> { if let Some(window) = app.get_webview_window(MAIN_WINDOW_LABEL) { let _ = window.unminimize(); let _ = window.show(); @@ -134,22 +127,19 @@ pub fn show_or_create_main_window(app: &AppHandle) -> taur return Ok(()); } - if let Some(window_config) = app - .config() - .app - .windows - .iter() - .find(|window| window.label == MAIN_WINDOW_LABEL) - .or_else(|| app.config().app.windows.first()) - { - let window = WebviewWindowBuilder::from_config(app, window_config)?.build()?; - configure_main_window(&window); - return Ok(()); - } + log::info!("Main window not found, creating a new one."); - let window = - WebviewWindowBuilder::new(app, MAIN_WINDOW_LABEL, WebviewUrl::default()).build()?; - configure_main_window(&window); + let builder = WebviewWindowBuilder::new(app, MAIN_WINDOW_LABEL, WebviewUrl::default()) + .title(app.package_info().name.clone()) + .resizable(true) + .fullscreen(false) + .inner_size(1280.0, 720.0) + .visible(false); + + #[cfg(target_os = "windows")] + let builder = builder.decorations(false); + + builder.build()?; Ok(()) } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 5f96efba6..a3a9a7050 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -3,9 +3,6 @@ mod windows; #[cfg(desktop)] mod desktop_tray; -#[cfg(desktop)] -use tauri::Manager; - #[cfg(desktop)] use tauri_plugin_window_state::StateFlags; @@ -56,9 +53,7 @@ pub fn run() { #[cfg(desktop)] { - if let Some(window) = app.get_webview_window(desktop_tray::MAIN_WINDOW_LABEL) { - desktop_tray::configure_main_window(&window); - } + desktop_tray::show_or_create_main_window(app.handle())?; desktop_tray::create_system_tray(app.handle())?; } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 5ad69b320..fbeb283d6 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -10,16 +10,7 @@ "beforeBuildCommand": "pnpm build" }, "app": { - "windows": [ - { - "title": "sable", - "width": 1280, - "height": 720, - "visible": false, - "resizable": true, - "fullscreen": false - } - ], + "windows": [], "security": { "csp": "default-src 'self' blob: data: filesystem: ws: wss: http: https: tauri:; script-src 'self' 'unsafe-eval' 'unsafe-inline' blob: data: filesystem: ws: wss: http: https: tauri:; img-src 'self' data: blob: filesystem: http: https:; connect-src 'self' ipc: ws: wss: http: https: http://ipc.localhost" } @@ -54,4 +45,4 @@ ] } } -} +} \ No newline at end of file diff --git a/src/app/pages/auth/SSOTauri.ts b/src/app/pages/auth/SSOTauri.ts index e045ccb53..a82c78e0d 100644 --- a/src/app/pages/auth/SSOTauri.ts +++ b/src/app/pages/auth/SSOTauri.ts @@ -11,7 +11,9 @@ const getAppBaseUrl = (): string => { } if (import.meta.env.DEV) { - return window.location.origin; + // TODO: disabled for now since it causes issues with the SSO flow. We should find a better solution for this in the future. + // return window.location.origin; + return `${TAURI_SSO_PROTOCOL}//${TAURI_SSO_HOST}`; } return 'https://app.sable.moe';