From 2a95f9eda3f4e3f11ec33fc45cbac6b8293db12f Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 16 Jul 2025 18:26:35 -0400 Subject: [PATCH] refactor --- .../initially_size_and_position_windows.rs | 3 ++- .../core/state/window/main_window_position.rs | 8 -------- .../artcraft/src/core/utils/window/mod.rs | 1 + .../core/utils/window/position_main_window.rs | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 crates/desktop/artcraft/src/core/utils/window/position_main_window.rs diff --git a/crates/desktop/artcraft/src/core/lifecycle/startup/tasks/initially_size_and_position_windows.rs b/crates/desktop/artcraft/src/core/lifecycle/startup/tasks/initially_size_and_position_windows.rs index bb82b83532..c2c04e51d3 100644 --- a/crates/desktop/artcraft/src/core/lifecycle/startup/tasks/initially_size_and_position_windows.rs +++ b/crates/desktop/artcraft/src/core/lifecycle/startup/tasks/initially_size_and_position_windows.rs @@ -1,6 +1,7 @@ use crate::core::state::data_dir::app_data_root::AppDataRoot; use crate::core::state::window::main_window_position::MainWindowPosition; use crate::core::state::window::main_window_size::MainWindowSize; +use crate::core::utils::window::position_main_window::position_main_window; use crate::core::utils::window::resize_main_window::resize_main_window; use tauri::AppHandle; @@ -29,7 +30,7 @@ pub fn initially_size_and_position_windows( Ok(None) => {} Ok(Some(pos)) => { println!("Moving window to: {:?}", pos); - let result = pos.apply_to_main_window(&app); + let result = position_main_window(app, &pos); if let Err(err) = result { eprintln!("Could not set window position: {:?}", err); } diff --git a/crates/desktop/artcraft/src/core/state/window/main_window_position.rs b/crates/desktop/artcraft/src/core/state/window/main_window_position.rs index ec88b83c17..e11b6d8ffb 100644 --- a/crates/desktop/artcraft/src/core/state/window/main_window_position.rs +++ b/crates/desktop/artcraft/src/core/state/window/main_window_position.rs @@ -42,14 +42,6 @@ impl MainWindowPosition { Ok(Some(pos)) } - pub fn apply_to_main_window(&self, app: &AppHandle) -> AnyhowResult<()> { - let windows = app.windows(); - let window = windows.get(MAIN_WINDOW_NAME) - .ok_or_else(|| anyhow::anyhow!("Main window not found"))?; - window.set_position(PhysicalPosition::new(self.x, self.y))?; - Ok(()) - } - pub fn persist_to_filesystem(&self, app_data_root: &AppDataRoot) -> AnyhowResult<()> { let filename = app_data_root.get_window_position_config_file(); let json = serde_json::to_string(self)?; diff --git a/crates/desktop/artcraft/src/core/utils/window/mod.rs b/crates/desktop/artcraft/src/core/utils/window/mod.rs index 5a0caba386..a6de92d14f 100644 --- a/crates/desktop/artcraft/src/core/utils/window/mod.rs +++ b/crates/desktop/artcraft/src/core/utils/window/mod.rs @@ -1,2 +1,3 @@ pub mod get_window_size_heuristic; +pub mod position_main_window; pub mod resize_main_window; diff --git a/crates/desktop/artcraft/src/core/utils/window/position_main_window.rs b/crates/desktop/artcraft/src/core/utils/window/position_main_window.rs new file mode 100644 index 0000000000..a391ae1310 --- /dev/null +++ b/crates/desktop/artcraft/src/core/utils/window/position_main_window.rs @@ -0,0 +1,18 @@ +use crate::core::state::window::main_window_position::MainWindowPosition; +use crate::core::windows::main_window::constants::MAIN_WINDOW_NAME; +use errors::AnyhowResult; +use tauri::{AppHandle, Manager, PhysicalPosition}; + +pub fn position_main_window( + app: &AppHandle, + position: &MainWindowPosition, +) -> AnyhowResult<()> { + + let windows = app.windows(); + let window = windows.get(MAIN_WINDOW_NAME) + .ok_or_else(|| anyhow::anyhow!("Main window not found"))?; + + window.set_position(PhysicalPosition::new(position.x, position.y))?; + + Ok(()) +} \ No newline at end of file