From 52655d97026fa2318a2c4a308ee2e293a0c2fc81 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Wed, 20 Aug 2025 18:05:31 +0800 Subject: [PATCH] feat: add configuration options to IpcManager for improved client setup --- src-tauri/src/ipc/general.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/ipc/general.rs b/src-tauri/src/ipc/general.rs index 5818cb2c..87176476 100644 --- a/src-tauri/src/ipc/general.rs +++ b/src-tauri/src/ipc/general.rs @@ -1,6 +1,9 @@ +use std::time::Duration; + use kode_bridge::{ errors::{AnyError, AnyResult}, - IpcHttpClient, LegacyResponse, + pool::PoolConfig, + ClientConfig, IpcHttpClient, LegacyResponse, }; use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS}; @@ -22,6 +25,7 @@ fn create_error(msg: impl Into) -> AnyError { pub struct IpcManager { ipc_path: String, + config: ClientConfig, } impl IpcManager { @@ -39,6 +43,23 @@ impl IpcManager { let ipc_path = ipc_path_buf.to_str().unwrap_or_default(); Self { ipc_path: ipc_path.to_string(), + config: ClientConfig { + default_timeout: Duration::from_secs(5), + enable_pooling: true, + max_retries: 3, + max_concurrent_requests: 32, + max_requests_per_second: Some(5.0), + pool_config: PoolConfig { + max_size: 32, + min_idle: 2, + max_idle_time_ms: 10_000, + max_retries: 3, + max_concurrent_requests: 32, + max_requests_per_second: Some(5.0), + ..Default::default() + }, + ..Default::default() + }, } } } @@ -53,7 +74,8 @@ impl IpcManager { path: &str, body: Option<&serde_json::Value>, ) -> AnyResult { - let client = IpcHttpClient::new(&self.ipc_path)?; + // let client = IpcHttpClient::new(&self.ipc_path)?; + let client = IpcHttpClient::with_config(&self.ipc_path, self.config.clone())?; client.request(method, path, body).await } }