v0.1.0-pre.050

This commit is contained in:
2026-07-25 21:04:56 +02:00
parent 8286dc0919
commit 50fd7467f8
23 changed files with 3129 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
// file: kb-app-demo-desktop/src/app_state.rs
// version: 3
// version: 4
//! Shared Tauri application state and startup initialization.
@@ -10,7 +10,7 @@ pub(crate) struct AppState {
active_profile: kb_config::ProfileConfig,
logging_guard: std::sync::Mutex<kb_logging::LoggingGuard>,
http_pool: kb_onchain_transport::HttpEndpointPool,
ws_pool: kb_onchain_transport::WsEndpointPool,
ws_pool: std::sync::Mutex<std::option::Option<std::sync::Arc<kb_onchain_transport::WsEndpointPool>>>,
demo_ws_session: tokio::sync::Mutex<std::option::Option<std::sync::Arc<kb_onchain_transport::WsSession>>>,
demo_backfill_running: std::sync::atomic::AtomicBool,
demo_backfill_cancel_requested: std::sync::atomic::AtomicBool,
@@ -37,17 +37,13 @@ impl crate::AppState {
std::result::Result::Ok(pool) => pool,
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
let ws_pool = match kb_onchain_transport::WsEndpointPool::from_profile(&active_profile) {
std::result::Result::Ok(pool) => pool,
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
return std::result::Result::Ok(crate::AppState {
config_path: config_path.display().to_string(),
app_config,
active_profile,
logging_guard: std::sync::Mutex::new(logging_guard),
http_pool,
ws_pool,
ws_pool: std::sync::Mutex::new(std::option::Option::None),
demo_ws_session: tokio::sync::Mutex::new(std::option::Option::None),
demo_backfill_running: std::sync::atomic::AtomicBool::new(false),
demo_backfill_cancel_requested: std::sync::atomic::AtomicBool::new(false),
@@ -74,9 +70,28 @@ impl crate::AppState {
return &self.http_pool;
}
/// Returns the configured WebSocket endpoint pool.
pub(crate) fn ws_pool(&self) -> &kb_onchain_transport::WsEndpointPool {
return &self.ws_pool;
/// Returns the lazily initialized WebSocket endpoint pool.
pub(crate) fn demo_ws_pool(
&self,
) -> kb_core::Result<std::sync::Arc<kb_onchain_transport::WsEndpointPool>> {
let lock_result = self.ws_pool.lock();
let mut guard = match lock_result {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => {
return std::result::Result::Err(kb_core::Error::invalid_state(
"demo WebSocket pool lock is poisoned",
));
},
};
if let std::option::Option::Some(pool) = guard.as_ref() {
return std::result::Result::Ok(std::sync::Arc::clone(pool));
}
let pool = match kb_onchain_transport::WsEndpointPool::from_profile(&self.active_profile) {
std::result::Result::Ok(value) => std::sync::Arc::new(value),
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
*guard = std::option::Option::Some(std::sync::Arc::clone(&pool));
return std::result::Result::Ok(pool);
}
/// Returns the persistent WebSocket demo session slot.