v0.1.0-pre.047
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: kb-app-demo-desktop/src/tauri.rs
|
||||
// version: 3
|
||||
// version: 4
|
||||
|
||||
//! Tauri runtime assembly and private command wrappers.
|
||||
|
||||
@@ -7,16 +7,22 @@ use tauri::Manager; // rust-rules: trait-import
|
||||
|
||||
/// Runs the desktop demo application.
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
#[allow(clippy::question_mark_used)]
|
||||
pub fn run() -> kb_core::Result<()> {
|
||||
let rustls_result = install_default_rustls_provider();
|
||||
if let std::result::Result::Err(error) = rustls_result {
|
||||
return std::result::Result::Err(error);
|
||||
}
|
||||
let app_state = match crate::AppState::initialize() {
|
||||
std::result::Result::Ok(state) => state,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
let app_state_result = crate::AppState::initialize();
|
||||
let app_state;
|
||||
if let std::result::Result::Ok(state) = app_state_result {
|
||||
app_state = state;
|
||||
} else if let std::result::Result::Err(error) = app_state_result {
|
||||
return std::result::Result::Err(error);
|
||||
} else {
|
||||
return std::result::Result::Err(kb_core::Error::invalid_state(
|
||||
"application state initialization produced no result",
|
||||
));
|
||||
}
|
||||
tracing::info!(
|
||||
target: crate::TRACING_TARGET,
|
||||
config_path = app_state.config_path(),
|
||||
@@ -27,8 +33,14 @@ pub fn run() -> kb_core::Result<()> {
|
||||
let tracing_builder = tauri_plugin_tracing::Builder::new();
|
||||
let mut builder = tauri::Builder::default();
|
||||
builder = builder.manage(app_state);
|
||||
builder =
|
||||
builder.invoke_handler(tauri::generate_handler![emit_frontend_log, load_project_readme,]);
|
||||
builder = builder.invoke_handler(tauri::generate_handler![
|
||||
emit_frontend_log,
|
||||
load_project_readme,
|
||||
open_demo_backfill_window,
|
||||
demo_backfill_options,
|
||||
demo_backfill_execute,
|
||||
demo_backfill_cancel,
|
||||
]);
|
||||
builder = builder.plugin(tracing_builder.build::<tauri::Wry>());
|
||||
builder = builder.setup(|app| {
|
||||
let splash_window = match app.get_webview_window("splash") {
|
||||
@@ -124,3 +136,126 @@ fn emit_frontend_log(payload: crate::FrontendLogPayload) {
|
||||
fn load_project_readme() -> std::result::Result<std::string::String, std::string::String> {
|
||||
return into_ipc_result(crate::load_project_readme());
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn demo_backfill_cancel(state: tauri::State<'_, crate::AppState>) -> bool {
|
||||
let running = state.demo_backfill_running().load(std::sync::atomic::Ordering::Acquire);
|
||||
state
|
||||
.demo_backfill_cancel_requested()
|
||||
.store(true, std::sync::atomic::Ordering::Release);
|
||||
return running;
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn open_demo_backfill_window(
|
||||
app_handle: tauri::AppHandle,
|
||||
) -> std::result::Result<(), std::string::String> {
|
||||
let existing_window = app_handle.get_webview_window("demo_backfill");
|
||||
if let std::option::Option::Some(window) = existing_window {
|
||||
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 build_result = tauri::WebviewWindowBuilder::new(
|
||||
&app_handle,
|
||||
"demo_backfill",
|
||||
tauri::WebviewUrl::App("demo_backfill.html".into()),
|
||||
)
|
||||
.title("Khadhroony Bot3 - Backfill HTTP")
|
||||
.inner_size(1280.0, 860.0)
|
||||
.min_inner_size(960.0, 620.0)
|
||||
.resizable(true)
|
||||
.visible(true)
|
||||
.build();
|
||||
return match build_result {
|
||||
std::result::Result::Ok(window) => match window.set_focus() {
|
||||
std::result::Result::Ok(()) => std::result::Result::Ok(()),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(error.to_string()),
|
||||
},
|
||||
std::result::Result::Err(error) => std::result::Result::Err(error.to_string()),
|
||||
};
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn demo_backfill_options(
|
||||
state: tauri::State<'_, crate::AppState>,
|
||||
) -> crate::DemoBackfillOptionsPayload {
|
||||
let roles = crate::build_role_options(state.http_pool().snapshot());
|
||||
let default_role = if roles.iter().any(|item| return item.role == "history_backfill") {
|
||||
std::option::Option::Some("history_backfill".to_string())
|
||||
} else {
|
||||
roles.first().map(|item| return item.role.clone())
|
||||
};
|
||||
return crate::DemoBackfillOptionsPayload {
|
||||
roles,
|
||||
default_role,
|
||||
default_commitment: "confirmed".to_string(),
|
||||
default_page_size: 100,
|
||||
default_max_pages: 20,
|
||||
default_max_concurrent_requests: 4,
|
||||
default_max_retries: 2,
|
||||
running: state.demo_backfill_running().load(std::sync::atomic::Ordering::Acquire),
|
||||
};
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn demo_backfill_execute(
|
||||
app_handle: tauri::AppHandle,
|
||||
state: tauri::State<'_, crate::AppState>,
|
||||
request: crate::DemoBackfillRequest,
|
||||
) -> std::result::Result<crate::DemoBackfillSummaryPayload, std::string::String> {
|
||||
let acquire_result = state.demo_backfill_running().compare_exchange(
|
||||
false,
|
||||
true,
|
||||
std::sync::atomic::Ordering::AcqRel,
|
||||
std::sync::atomic::Ordering::Acquire,
|
||||
);
|
||||
if acquire_result.is_err() {
|
||||
return std::result::Result::Err("a backfill campaign is already running".to_string());
|
||||
}
|
||||
let _run_guard = crate::DemoBackfillRunGuard { running: state.demo_backfill_running() };
|
||||
state
|
||||
.demo_backfill_cancel_requested()
|
||||
.store(false, std::sync::atomic::Ordering::Release);
|
||||
let pipeline_request = match crate::build_demo_backfill_pipeline_request(request) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
let profile = state.active_profile();
|
||||
let store_options = match kb_store::PostgresStoreOptions::new(
|
||||
profile.database.postgres.url.clone(),
|
||||
profile.database.postgres.max_connections,
|
||||
profile.database.postgres.connect_timeout_ms,
|
||||
false,
|
||||
) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()),
|
||||
};
|
||||
let store = match kb_store::PostgresStore::connect(store_options).await {
|
||||
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) = store.initialize_store_schema().await {
|
||||
return std::result::Result::Err(error.to_string());
|
||||
}
|
||||
let observer = crate::DemoBackfillObserver {
|
||||
app_handle,
|
||||
cancel_requested: state.demo_backfill_cancel_requested(),
|
||||
};
|
||||
let summary = match kb_pipeline::execute_http_backfill(
|
||||
state.http_pool(),
|
||||
&store,
|
||||
&pipeline_request,
|
||||
&observer,
|
||||
)
|
||||
.await
|
||||
{
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()),
|
||||
};
|
||||
return std::result::Result::Ok(crate::demo_backfill_summary_payload(summary));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user