Add clearing of the buffer after closing a repository

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 31eadd2e43
commit 9fe670a648

@ -77,7 +77,7 @@ impl ApiClient {
) -> ApiResult<Self> { ) -> ApiResult<Self> {
let ctx = IPCBuilder::<L>::new() let ctx = IPCBuilder::<L>::new()
.address(address) .address(address)
.timeout(Duration::from_secs(10)) .timeout(Duration::from_secs(30))
.build_pooled_client(8) .build_pooled_client(8)
.await?; .await?;
let client = Self::new(ctx); let client = Self::new(ctx);

@ -1,6 +1,6 @@
use crate::client_api::protocol::ApiProtocolListener; use crate::client_api::protocol::ApiProtocolListener;
use crate::client_api::ApiClient; 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::error::{PluginError, PluginResult};
use crate::tauri_plugin::settings::{save_settings, Repository}; use crate::tauri_plugin::settings::{save_settings, Repository};
use crate::types::repo::FrontendState; use crate::types::repo::FrontendState;
@ -121,10 +121,12 @@ pub async fn check_local_repository_exists(path: String) -> PluginResult<bool> {
pub async fn disconnect_repository( pub async fn disconnect_repository(
app_state: AppAccess<'_>, app_state: AppAccess<'_>,
api_state: ApiAccess<'_>, api_state: ApiAccess<'_>,
buffer_state: BufferAccess<'_>,
) -> PluginResult<()> { ) -> PluginResult<()> {
api_state.disconnect().await; api_state.disconnect().await;
let mut active_repo = app_state.active_repo.write().await; let mut active_repo = app_state.active_repo.write().await;
mem::take(&mut *active_repo); mem::take(&mut *active_repo);
buffer_state.clear();
Ok(()) Ok(())
} }
@ -133,12 +135,16 @@ pub async fn disconnect_repository(
pub async fn close_local_repository( pub async fn close_local_repository(
app_state: AppAccess<'_>, app_state: AppAccess<'_>,
api_state: ApiAccess<'_>, api_state: ApiAccess<'_>,
buffer_state: BufferAccess<'_>,
) -> PluginResult<()> { ) -> PluginResult<()> {
let mut active_repo = app_state.active_repo.write().await; let mut active_repo = app_state.active_repo.write().await;
if let Some(path) = mem::take(&mut *active_repo).and_then(|r| r.path) { if let Some(path) = mem::take(&mut *active_repo).and_then(|r| r.path) {
app_state.stop_running_daemon(&path).await?; app_state.stop_running_daemon(&path).await?;
} }
api_state.disconnect().await; api_state.disconnect().await;
mem::take(&mut *active_repo);
buffer_state.clear();
Ok(()) Ok(())
} }

@ -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 /// Trims the buffer to the given target size
pub fn trim_to_size(&self, target_size: usize) { pub fn trim_to_size(&self, target_size: usize) {
let mut size = self.get_size(); let mut size = self.get_size();

Loading…
Cancel
Save