v0.1.0-pre.051
This commit is contained in:
51
kb-app-demo-desktop/src/demo_config.rs
Normal file
51
kb-app-demo-desktop/src/demo_config.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
// file: kb-app-demo-desktop/src/demo_config.rs
|
||||
// version: 1
|
||||
|
||||
//! Configuration demo payload and state projection.
|
||||
|
||||
use ts_rs::TS; // rust-rules: derive-import
|
||||
|
||||
/// Serializable payload shown by the configuration demo page.
|
||||
#[derive(Clone, Debug, serde::Serialize, TS)]
|
||||
#[ts(
|
||||
export,
|
||||
export_to = "../frontend/ts/bindings/kb_app_demo_desktop/demo_config/DemoConfigPayload.ts"
|
||||
)]
|
||||
pub(crate) struct DemoConfigPayload {
|
||||
/// Path used to load the configuration file.
|
||||
pub(crate) config_path: std::string::String,
|
||||
/// Active profile name.
|
||||
pub(crate) active_profile_name: std::string::String,
|
||||
/// Active profile environment.
|
||||
pub(crate) environment: std::string::String,
|
||||
/// Entire parsed configuration.
|
||||
pub(crate) app_config: kb_config::AppConfig,
|
||||
/// Active profile configuration.
|
||||
pub(crate) active_profile: kb_config::ProfileConfig,
|
||||
/// Embedded JSON Schema text used during loading.
|
||||
pub(crate) schema_json: std::string::String,
|
||||
}
|
||||
|
||||
/// Builds the configuration payload from shared application state.
|
||||
pub(crate) fn demo_config_payload(state: &crate::AppState) -> crate::DemoConfigPayload {
|
||||
return crate::DemoConfigPayload {
|
||||
config_path: state.config_path().to_owned(),
|
||||
active_profile_name: state.active_profile().name.clone(),
|
||||
environment: state.active_profile().app.environment.clone(),
|
||||
app_config: state.app_config().clone(),
|
||||
active_profile: state.active_profile().clone(),
|
||||
schema_json: kb_config::config_json_schema_text().to_owned(),
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ts_rs::TS; // rust-rules: trait-import
|
||||
|
||||
#[test]
|
||||
fn payload_binding_uses_desktop_path() {
|
||||
let config = ts_rs::Config::default();
|
||||
let declaration = <crate::DemoConfigPayload as TS>::decl(&config);
|
||||
assert!(declaration.contains("DemoConfigPayload"));
|
||||
}
|
||||
}
|
||||
@@ -161,7 +161,7 @@ pub(crate) fn table_snapshots_from_pg(
|
||||
) -> std::vec::Vec<crate::DemoSqlTableSnapshot> {
|
||||
let mut output = std::vec::Vec::new();
|
||||
for value in values {
|
||||
output.push(table_snapshot_from_pg(value));
|
||||
output.push(crate::table_snapshot_from_pg(value));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: kb-app-demo-desktop/src/lib.rs
|
||||
// version: 5
|
||||
// version: 6
|
||||
|
||||
//! Tauri desktop demo application for `khadhroony-bot3`.
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
mod app_state;
|
||||
mod constants;
|
||||
mod demo_backfill;
|
||||
mod demo_config;
|
||||
mod demo_http;
|
||||
mod demo_ws;
|
||||
mod demo_sql_common;
|
||||
@@ -47,6 +48,10 @@ pub(crate) use self::demo_backfill::build_demo_backfill_pipeline_request;
|
||||
pub(crate) use self::demo_backfill::build_role_options;
|
||||
/// Converts a pipeline summary to the UI-safe summary.
|
||||
pub(crate) use self::demo_backfill::demo_backfill_summary_payload;
|
||||
/// Configuration payload shown by the configuration window.
|
||||
pub(crate) use self::demo_config::DemoConfigPayload;
|
||||
/// Builds the configuration payload from shared application state.
|
||||
pub(crate) use self::demo_config::demo_config_payload;
|
||||
/// HTTP demo response payload.
|
||||
pub(crate) use self::demo_http::DemoHttpExecutionPayload;
|
||||
/// One selectable HTTP JSON-RPC method.
|
||||
@@ -93,8 +98,6 @@ pub(crate) use self::demo_ws::demo_ws_disconnect_inner;
|
||||
pub(crate) use self::demo_ws::demo_ws_status_inner;
|
||||
/// Unsubscribes one active WebSocket subscription.
|
||||
pub(crate) use self::demo_ws::demo_ws_unsubscribe_inner;
|
||||
/// Disconnects the application WebSocket session during shutdown.
|
||||
pub(crate) use self::demo_ws::disconnect_demo_ws_app_state;
|
||||
/// UI-safe SQL table diagnostic snapshot.
|
||||
pub(crate) use self::demo_sql_common::DemoSqlTableSnapshot;
|
||||
/// Connects to the configured PostgreSQL store.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: kb-app-demo-desktop/src/tauri.rs
|
||||
// version: 7
|
||||
// version: 8
|
||||
|
||||
//! Tauri runtime assembly and private command wrappers.
|
||||
|
||||
@@ -64,21 +64,10 @@ pub fn run() -> kb_core::Result<()> {
|
||||
load_demo_sql_replay_programs,
|
||||
load_demo_sql_replay_entities,
|
||||
export_demo_sql_replay_csv,
|
||||
open_demo_config_window,
|
||||
load_demo_config,
|
||||
]);
|
||||
builder = builder.plugin(tracing_builder.build::<tauri::Wry>());
|
||||
builder = builder.on_window_event(|window, event| {
|
||||
if window.label() != "demo_ws" {
|
||||
return;
|
||||
}
|
||||
if !matches!(event, tauri::WindowEvent::Destroyed) {
|
||||
return;
|
||||
}
|
||||
let app_handle = window.app_handle().clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let state = app_handle.state::<crate::AppState>();
|
||||
crate::disconnect_demo_ws_app_state(&state, false).await;
|
||||
});
|
||||
});
|
||||
builder = builder.setup(|app| {
|
||||
let splash_window = match app.get_webview_window("splash") {
|
||||
std::option::Option::Some(window) => window,
|
||||
@@ -194,6 +183,46 @@ fn install_default_rustls_provider() -> kb_core::Result<()> {
|
||||
};
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn open_demo_config_window(
|
||||
app_handle: tauri::AppHandle,
|
||||
) -> std::result::Result<(), std::string::String> {
|
||||
if let std::option::Option::Some(window) = app_handle.get_webview_window("demo_config") {
|
||||
if let std::result::Result::Err(error) = window.show() {
|
||||
return std::result::Result::Err(error.to_string());
|
||||
}
|
||||
if let std::result::Result::Err(error) = window.set_focus() {
|
||||
return std::result::Result::Err(error.to_string());
|
||||
}
|
||||
return std::result::Result::Ok(());
|
||||
}
|
||||
let builder = tauri::WebviewWindowBuilder::new(
|
||||
&app_handle,
|
||||
"demo_config",
|
||||
tauri::WebviewUrl::App("demo_config.html".into()),
|
||||
)
|
||||
.title("Khadhroony Bot3 - Configuration")
|
||||
.inner_size(1280.0, 820.0)
|
||||
.min_inner_size(960.0, 640.0);
|
||||
let window = match builder.build() {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => {
|
||||
return std::result::Result::Err(error.to_string());
|
||||
},
|
||||
};
|
||||
if let std::result::Result::Err(error) = window.set_focus() {
|
||||
return std::result::Result::Err(error.to_string());
|
||||
}
|
||||
return std::result::Result::Ok(());
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn load_demo_config(
|
||||
state: tauri::State<'_, crate::AppState>,
|
||||
) -> crate::DemoConfigPayload {
|
||||
return crate::demo_config_payload(state.inner());
|
||||
}
|
||||
|
||||
fn into_ipc_result<T>(
|
||||
result: kb_core::Result<T>,
|
||||
) -> std::result::Result<T, std::string::String> {
|
||||
|
||||
Reference in New Issue
Block a user