diff --git a/crates/desktop/artcraft/src/state/main_window_size.rs b/crates/desktop/artcraft/src/state/main_window_size.rs index f1f32f6966..3fff6b32d9 100644 --- a/crates/desktop/artcraft/src/state/main_window_size.rs +++ b/crates/desktop/artcraft/src/state/main_window_size.rs @@ -4,6 +4,7 @@ use serde_derive::{Deserialize, Serialize}; use std::fs::OpenOptions; use std::io::Write; use tauri::{AppHandle, Manager, PhysicalSize, Window}; +use crate::utils::best_window_size_heuristic::best_window_size_heuristic; const MAIN_WINDOW_NAME: &str = "main"; @@ -26,7 +27,7 @@ impl MainWindowSize { } pub fn from_window(window: &Window) -> AnyhowResult { - let size = window.inner_size()?; + let size = best_window_size_heuristic(window)?; Ok(Self { width: size.width, height: size.height, diff --git a/crates/desktop/artcraft/src/threads/main_window_thread/persist_window_resize_task.rs b/crates/desktop/artcraft/src/threads/main_window_thread/persist_window_resize_task.rs index fc6c356fea..3c842478f6 100644 --- a/crates/desktop/artcraft/src/threads/main_window_thread/persist_window_resize_task.rs +++ b/crates/desktop/artcraft/src/threads/main_window_thread/persist_window_resize_task.rs @@ -1,5 +1,6 @@ use crate::state::data_dir::app_data_root::AppDataRoot; use crate::state::main_window_size::MainWindowSize; +use crate::utils::best_window_size_heuristic::best_window_size_heuristic; use errors::AnyhowResult; use log::info; use memory_store::clone_slot::CloneSlot; @@ -12,7 +13,7 @@ pub async fn persist_window_resize_task( ) -> AnyhowResult<()> { let current_window_size = MainWindowSize::from_window(window)?; - let current_physical_size = window.inner_size()?; + let current_physical_size = best_window_size_heuristic(window)?; let mut save_size_to_disk = true; diff --git a/crates/desktop/artcraft/src/utils/best_window_size_heuristic.rs b/crates/desktop/artcraft/src/utils/best_window_size_heuristic.rs new file mode 100644 index 0000000000..995dbbd207 --- /dev/null +++ b/crates/desktop/artcraft/src/utils/best_window_size_heuristic.rs @@ -0,0 +1,25 @@ +use tauri::{PhysicalSize, Window}; +use errors::AnyhowResult; + +// A typical height difference when dev tools are open: +// Window inner size = PhysicalSize { width: 3704, height: 732 } +// Window outer size = PhysicalSize { width: 3704, height: 1476 } +const HEIGHT_DIFFERENCE_THRESHOLD: u32 = 300; + +/// Get the best window size +pub fn best_window_size_heuristic(window: &Window) -> AnyhowResult> { + // NB: Ordinarily we'd use inner size, as the outer size includes the window decorations. + // However, dev tools contract the inner size, and in the event they're open, we should + // prefer the outer size. + let inner = window.inner_size()?; + let outer = window.outer_size()?; + + let height_delta = outer.height.saturating_sub(inner.height); + if height_delta > HEIGHT_DIFFERENCE_THRESHOLD { + // Dev tools are open, use the outer size + Ok(outer) + } else { + // Dev tools are not open, use the inner size + Ok(inner) + } +} diff --git a/crates/desktop/artcraft/src/utils/mod.rs b/crates/desktop/artcraft/src/utils/mod.rs index c98cf6ab71..d3784750af 100644 --- a/crates/desktop/artcraft/src/utils/mod.rs +++ b/crates/desktop/artcraft/src/utils/mod.rs @@ -1,3 +1,4 @@ +pub mod best_window_size_heuristic; pub mod clear_all_webview_cookies; pub mod get_url_file_extension; pub mod image;