mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-03 00:47:53 +00:00
correct persistence behavior for window / storyteller cookies ?
This commit is contained in:
1 parent
f1b9299e46
commit
ff1a83898b
4 files changed
+33
-21
No files matched your search
@@ -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<MainWindowSize> = 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<MainWindowSize>,
|
||||
) -> 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;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-5
@@ -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()?;
|
||||
}
|
||||
|
||||
|
||||
+20
-14
@@ -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<MainWindowSize>,
|
||||
) -> 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(())
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ pub struct CloneSlot<T: Clone> {
|
||||
}
|
||||
|
||||
impl <T: Clone> CloneSlot<T> {
|
||||
pub fn new() -> Self {
|
||||
pub fn empty() -> Self {
|
||||
Self {
|
||||
store: Arc::new(RwLock::new(None)),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user