v0.3.8-pre.006
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
// file: crates/ksp-app-store-desk/src/app_state.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
//! Shared backend state owned by the Store Desk Tauri scaffold.
|
||||
//! Shared backend state owned by the Store Desk Tauri application.
|
||||
|
||||
/// Shared Store Desk application state managed by Tauri.
|
||||
pub(crate) struct AppState {
|
||||
config_management: ksp_config_lib::ConfigManagement,
|
||||
logging_runtime: std::sync::Mutex<LoggingRuntimeState>,
|
||||
shutdown_started: std::sync::atomic::AtomicBool,
|
||||
splash_settings: crate::SplashSettings,
|
||||
splash_sequence_started: std::sync::atomic::AtomicBool,
|
||||
store_startup: crate::StoreStartup,
|
||||
}
|
||||
|
||||
impl crate::AppState {
|
||||
/// Initializes Config ownership, transient standard Logging and common splash settings.
|
||||
/// Initializes Config ownership, composite-managed Logging, Store readiness and common splash settings.
|
||||
pub(crate) fn initialize(arguments: &[std::ffi::OsString]) -> ksp_core_lib::Result<Self> {
|
||||
let config_management = crate::config_management(arguments);
|
||||
let config_management = match config_management {
|
||||
@@ -29,6 +31,7 @@ impl crate::AppState {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
let store_startup = tauri::async_runtime::block_on(crate::initialize_store(&config_management));
|
||||
let splash_settings = crate::SplashSettings::load();
|
||||
let splash_settings = match splash_settings {
|
||||
std::result::Result::Ok(value) => value,
|
||||
@@ -63,12 +66,14 @@ impl crate::AppState {
|
||||
fallback_active: logging_startup.fallback_active,
|
||||
startup_diagnostic: logging_startup.startup_diagnostic,
|
||||
}),
|
||||
shutdown_started: std::sync::atomic::AtomicBool::new(false),
|
||||
splash_settings,
|
||||
splash_sequence_started: std::sync::atomic::AtomicBool::new(false),
|
||||
store_startup,
|
||||
});
|
||||
}
|
||||
|
||||
/// Builds the safe runtime status exposed by the Store Desk scaffold shell.
|
||||
/// Builds the safe shell/Config/Logging status exposed by Store Desk diagnostics.
|
||||
pub(crate) fn shell_status(&self) -> ksp_core_lib::Result<crate::ShellStatusDto> {
|
||||
let document_count = self.config_management.engine().registry().descriptors().count();
|
||||
let document_count = u32::try_from(document_count);
|
||||
@@ -100,11 +105,16 @@ impl crate::AppState {
|
||||
application_version: env!("CARGO_PKG_VERSION").to_owned(),
|
||||
config_document_count: document_count,
|
||||
fallback_logging_active: runtime.fallback_active,
|
||||
shell_phase: "pre.002-scaffold".to_owned(),
|
||||
shell_phase: "pre.006-store-overview".to_owned(),
|
||||
startup_diagnostic: runtime.startup_diagnostic.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
/// Builds one fresh safe Store runtime/health projection for the Overview and Diagnostics screens.
|
||||
pub(crate) async fn store_runtime_status(&self) -> crate::StoreRuntimeStatusDto {
|
||||
return self.store_startup.status().await;
|
||||
}
|
||||
|
||||
/// Returns the resolved splash timings captured during application bootstrap.
|
||||
#[must_use]
|
||||
pub(crate) const fn splash_settings(&self) -> crate::SplashSettings {
|
||||
@@ -118,6 +128,16 @@ impl crate::AppState {
|
||||
.compare_exchange(false, true, std::sync::atomic::Ordering::AcqRel, std::sync::atomic::Ordering::Acquire)
|
||||
.is_ok();
|
||||
}
|
||||
|
||||
/// Marks graceful application shutdown as started and reports whether this caller won the one-shot transition.
|
||||
pub(crate) fn begin_shutdown(&self) -> bool {
|
||||
return self.shutdown_started.compare_exchange(false, true, std::sync::atomic::Ordering::AcqRel, std::sync::atomic::Ordering::Acquire).is_ok();
|
||||
}
|
||||
|
||||
/// Explicitly closes the retained Store runtime when application shutdown begins.
|
||||
pub(crate) async fn close_store(&self) -> ksp_core_lib::Result<()> {
|
||||
return self.store_startup.close().await;
|
||||
}
|
||||
}
|
||||
|
||||
struct LoggingRuntimeState {
|
||||
|
||||
Reference in New Issue
Block a user