fix: move window creation into rust side for easier control

This commit is contained in:
hazre committed 2026-03-14 20:48:20 +01:00
1 parent e8670348ff
commit 4795fb387e
4 files changed
+20 -42

No files matched your search

+14 -24
View File
@@ -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<crate::BrowserEngine>, event: &TrayI
}
}
pub fn configure_main_window(_window: &WebviewWindow<crate::BrowserEngine>) {
#[cfg(target_os = "windows")]
{
let _ = _window.set_decorations(false);
}
}
pub fn handle_run_event(app: &AppHandle<crate::BrowserEngine>, event: RunEvent) {
if let RunEvent::ExitRequested { code, api, .. } = event {
handle_exit_request(app, code, &api);
}
}
pub fn show_or_create_main_window(app: &AppHandle<crate::BrowserEngine>) -> tauri::Result<()> {
pub fn show_or_create_main_window<R: tauri::Runtime>(app: &AppHandle<R>) -> 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<crate::BrowserEngine>) -> 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(())
}
+1 -6
View File
@@ -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())?;
}
+2 -11
View File
@@ -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 @@
]
}
}
}
}
+3 -1
View File
@@ -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';