From 7482f8543ce778005e811e7f52b737aacb01a5a0 Mon Sep 17 00:00:00 2001 From: FTCHD <144691102+FTCHD@users.noreply.github.com> Date: Sun, 10 May 2026 17:52:49 +0300 Subject: [PATCH] window: linux fixes --- src-tauri/common/window.rs | 57 ++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/src-tauri/common/window.rs b/src-tauri/common/window.rs index f2bec09..23eb43c 100644 --- a/src-tauri/common/window.rs +++ b/src-tauri/common/window.rs @@ -95,6 +95,7 @@ pub async fn open_full_window( Ok(()) } +#[cfg(not(target_os = "linux"))] #[tauri::command] pub async fn open_window( app_handle: AppHandle, @@ -107,7 +108,7 @@ pub async fn open_window( existing.set_focus().map_err(|e| e.to_string())?; return Ok(()); } - + let os = std::env::consts::OS; let default_height = if os == "windows" { 755.0 } else { 725.0 }; @@ -131,10 +132,9 @@ pub async fn open_window( } let window = builder.build().map_err(|e| e.to_string())?; - + std::thread::sleep(std::time::Duration::from_millis(750)); - // window.center().map_err(|e| e.to_string())?; let monitor = window .current_monitor() .map_err(|e| e.to_string())? @@ -159,18 +159,51 @@ pub async fn open_window( y: y + final_offset, })) .map_err(|e| e.to_string())?; - + window.set_zoom(1.0).map_err(|e| e.to_string())?; window.show().map_err(|e| e.to_string())?; window.set_focus().map_err(|e| e.to_string())?; - - #[cfg(target_os = "linux")] - window - .set_position(tauri::Position::Physical(tauri::PhysicalPosition { - x: x + final_offset, - y: y + final_offset, - })) - .map_err(|e| e.to_string())?; + + Ok(()) +} + +#[cfg(target_os = "linux")] +#[tauri::command] +pub async fn open_window( + app_handle: AppHandle, + name: String, + url: String, + width: Option, + height: Option, +) -> Result<(), String> { + if let Some(existing) = app_handle.get_webview_window(&name) { + existing.set_focus().map_err(|e| e.to_string())?; + return Ok(()); + } + + let width = width.unwrap_or(840.0); + let height = height.unwrap_or(725.0); + + let builder = WebviewWindowBuilder::new(&app_handle, &name, WebviewUrl::App(url.into())) + .title(&name) + .inner_size(width, height) + .min_inner_size(700.0, 700.0) + .max_inner_size(1000.0, 1000.0) + .resizable(true) + .visible(false) + .focused(false) + .decorations(true) + .zoom_hotkeys_enabled(false); + + let window = builder.build().map_err(|e| e.to_string())?; + + window.center().map_err(|e| e.to_string())?; + window.set_zoom(1.0).map_err(|e| e.to_string())?; + window.show().map_err(|e| e.to_string())?; + window.set_focus().map_err(|e| e.to_string())?; + + window.set_resizable(false).map_err(|e| e.to_string())?; + window.set_resizable(true).map_err(|e| e.to_string())?; Ok(()) }