diff --git a/crates/desktop/tauri-artcraft/src/threads/main_window_thread/main_window_thread.rs b/crates/desktop/tauri-artcraft/src/threads/main_window_thread/main_window_thread.rs index f68941ae28..ddffb7fe95 100644 --- a/crates/desktop/tauri-artcraft/src/threads/main_window_thread/main_window_thread.rs +++ b/crates/desktop/tauri-artcraft/src/threads/main_window_thread/main_window_thread.rs @@ -5,6 +5,7 @@ use crate::threads::main_window_thread::persist_storyteller_cookies_task::persis use crate::threads::main_window_thread::persist_window_resize_task::persist_window_resize_task; use errors::AnyhowResult; use log::{error, info}; +use memory_store::clone_slot::CloneSlot; use tauri::{AppHandle, Manager, Webview, Window}; const MAIN_WINDOW_NAME : &str = "main"; @@ -14,6 +15,8 @@ pub async fn main_window_thread( app_data_root: AppDataRoot, storyteller_creds_manager: StorytellerCredentialManager, ) -> ! { + let window_size_slot: CloneSlot = CloneSlot::empty(); + loop { for (window_name, window) in app.windows() { if window_name == MAIN_WINDOW_NAME { @@ -21,6 +24,7 @@ pub async fn main_window_thread( &window, &app_data_root, &storyteller_creds_manager, + &window_size_slot, ).await; if let Err(err) = result { error!("Error handling main window: {:?}", err); @@ -35,10 +39,11 @@ pub async fn handle_main_window( window: &Window, app_data_root: &AppDataRoot, storyteller_creds_manager: &StorytellerCredentialManager, + window_size_slot: &CloneSlot, ) -> AnyhowResult<()> { loop { log_errors(persist_storyteller_cookies_task(window, app_data_root, storyteller_creds_manager).await); - log_errors(persist_window_resize_task(window, app_data_root).await); + log_errors(persist_window_resize_task(window, app_data_root, window_size_slot).await); tokio::time::sleep(std::time::Duration::from_millis(1_000)).await; } } diff --git a/crates/desktop/tauri-artcraft/src/threads/main_window_thread/persist_storyteller_cookies_task.rs b/crates/desktop/tauri-artcraft/src/threads/main_window_thread/persist_storyteller_cookies_task.rs index 91951ba1f5..051c534cd7 100644 --- a/crates/desktop/tauri-artcraft/src/threads/main_window_thread/persist_storyteller_cookies_task.rs +++ b/crates/desktop/tauri-artcraft/src/threads/main_window_thread/persist_storyteller_cookies_task.rs @@ -33,10 +33,10 @@ async fn persist_webview_cookies( app_data_root: &AppDataRoot, storyteller_credential_manager: &StorytellerCredentialManager, ) -> AnyhowResult<()> { - let webview_credentials = get_storyteller_cookies(webview)?; + let current_webview_credentials = get_storyteller_cookies(webview)?; - if webview_credentials.is_empty() { - // TODO: handle logout + if current_webview_credentials.is_empty() { + // TODO: handle logout / cookie deletion return Ok(()); } @@ -45,13 +45,14 @@ async fn persist_webview_cookies( let maybe_old_credentials = storyteller_credential_manager.get_credentials()?; if let Some(old_credentials) = maybe_old_credentials { - if old_credentials.equals(&webview_credentials) { + if old_credentials.equals(¤t_webview_credentials) { replace_credentials = false; } } if replace_credentials { - storyteller_credential_manager.set_credentials(&webview_credentials)?; + info!("Writing ArtCraft credentials to disk..."); + storyteller_credential_manager.set_credentials(¤t_webview_credentials)?; storyteller_credential_manager.persist_all_to_disk()?; } diff --git a/crates/desktop/tauri-artcraft/src/threads/main_window_thread/persist_window_resize_task.rs b/crates/desktop/tauri-artcraft/src/threads/main_window_thread/persist_window_resize_task.rs index fcea642c70..fc6c356fea 100644 --- a/crates/desktop/tauri-artcraft/src/threads/main_window_thread/persist_window_resize_task.rs +++ b/crates/desktop/tauri-artcraft/src/threads/main_window_thread/persist_window_resize_task.rs @@ -1,26 +1,32 @@ -use log::info; -use tauri::Window; -use errors::AnyhowResult; use crate::state::data_dir::app_data_root::AppDataRoot; use crate::state::main_window_size::MainWindowSize; +use errors::AnyhowResult; +use log::info; +use memory_store::clone_slot::CloneSlot; +use tauri::Window; pub async fn persist_window_resize_task( window: &Window, app_data_root: &AppDataRoot, + window_size_slot: &CloneSlot, ) -> AnyhowResult<()> { - let mut window_size = MainWindowSize::from_window(window)?; - let new_size = window.inner_size()?; + let current_window_size = MainWindowSize::from_window(window)?; + let current_physical_size = window.inner_size()?; - // TODO: Temporary regression. This used to work, but we no longer have old state to compare against. - // if !window_size.matches_physical_size(&new_size) { - // let old_size = window_size.to_physical_size(); - // info!("Window size changed from {:?} to {:?}", old_size, new_size); - // window_size = MainWindowSize::from_window(&window)?; - // info!("Saving window size configs to disk..."); - // window_size.persist_to_filesystem(app_data_root)?; - // } + let mut save_size_to_disk = true; + + if let Ok(Some(old_size)) = window_size_slot.get_clone() { + if old_size.matches_physical_size(¤t_physical_size) { + save_size_to_disk = false; + } + } + + if save_size_to_disk { + info!("Saving window size configs to disk..."); + current_window_size.persist_to_filesystem(app_data_root)?; + window_size_slot.set_clone(¤t_window_size)?; + } Ok(()) } - diff --git a/crates/lib/caching/memory_store/src/clone_slot.rs b/crates/lib/caching/memory_store/src/clone_slot.rs index 3726acd443..3dd13c3742 100644 --- a/crates/lib/caching/memory_store/src/clone_slot.rs +++ b/crates/lib/caching/memory_store/src/clone_slot.rs @@ -13,7 +13,7 @@ pub struct CloneSlot { } impl CloneSlot { - pub fn new() -> Self { + pub fn empty() -> Self { Self { store: Arc::new(RwLock::new(None)), }