diff --git a/mediarepo-api/src/client_api/mod.rs b/mediarepo-api/src/client_api/mod.rs index a8c499c..d6969a4 100644 --- a/mediarepo-api/src/client_api/mod.rs +++ b/mediarepo-api/src/client_api/mod.rs @@ -77,7 +77,7 @@ impl ApiClient { ) -> ApiResult { let ctx = IPCBuilder::::new() .address(address) - .timeout(Duration::from_secs(10)) + .timeout(Duration::from_secs(30)) .build_pooled_client(8) .await?; let client = Self::new(ctx); diff --git a/mediarepo-api/src/tauri_plugin/commands/repo.rs b/mediarepo-api/src/tauri_plugin/commands/repo.rs index 32d3b3f..1912de4 100644 --- a/mediarepo-api/src/tauri_plugin/commands/repo.rs +++ b/mediarepo-api/src/tauri_plugin/commands/repo.rs @@ -1,6 +1,6 @@ use crate::client_api::protocol::ApiProtocolListener; use crate::client_api::ApiClient; -use crate::tauri_plugin::commands::{ApiAccess, AppAccess}; +use crate::tauri_plugin::commands::{ApiAccess, AppAccess, BufferAccess}; use crate::tauri_plugin::error::{PluginError, PluginResult}; use crate::tauri_plugin::settings::{save_settings, Repository}; use crate::types::repo::FrontendState; @@ -121,10 +121,12 @@ pub async fn check_local_repository_exists(path: String) -> PluginResult { pub async fn disconnect_repository( app_state: AppAccess<'_>, api_state: ApiAccess<'_>, + buffer_state: BufferAccess<'_>, ) -> PluginResult<()> { api_state.disconnect().await; let mut active_repo = app_state.active_repo.write().await; mem::take(&mut *active_repo); + buffer_state.clear(); Ok(()) } @@ -133,12 +135,16 @@ pub async fn disconnect_repository( pub async fn close_local_repository( app_state: AppAccess<'_>, api_state: ApiAccess<'_>, + buffer_state: BufferAccess<'_>, ) -> PluginResult<()> { let mut active_repo = app_state.active_repo.write().await; + if let Some(path) = mem::take(&mut *active_repo).and_then(|r| r.path) { app_state.stop_running_daemon(&path).await?; } api_state.disconnect().await; + mem::take(&mut *active_repo); + buffer_state.clear(); Ok(()) } diff --git a/mediarepo-api/src/tauri_plugin/state.rs b/mediarepo-api/src/tauri_plugin/state.rs index c38caaf..e053325 100644 --- a/mediarepo-api/src/tauri_plugin/state.rs +++ b/mediarepo-api/src/tauri_plugin/state.rs @@ -122,6 +122,12 @@ impl BufferState { } } + /// Clears the buffer completely + pub fn clear(&self) { + let mut buffer = self.buffer.write(); + buffer.clear(); + } + /// Trims the buffer to the given target size pub fn trim_to_size(&self, target_size: usize) { let mut size = self.get_size();