// file: crates/ksp-app-solprices-desk/src/tw_main.rs // version: 1 //! Tauri-window helpers for the SOL Prices Desk main window. use tauri::Manager; // rust-rules: trait-import /// Crate-internal `WINDOW_LABEL_MAIN` constant. pub(crate) const WINDOW_LABEL_MAIN: &str = "main"; /// Resolves the required main window or returns a typed error. pub(crate) fn require_main_window(manager: &impl Manager) -> ksp_core_lib::Result { let window = manager.get_webview_window(WINDOW_LABEL_MAIN); return match window { std::option::Option::Some(value) => std::result::Result::Ok(value), std::option::Option::None => std::result::Result::Err( ksp_core_lib::Error::new(crate::ERROR_CODE_TAURI_WINDOW_MISSING, "SOL Prices Desk main window is missing") .with_context("window_label", WINDOW_LABEL_MAIN), ), }; } /// Shows main window. pub(crate) fn show_main_window(app: &tauri::AppHandle) -> ksp_core_lib::Result<()> { let window = crate::require_main_window(app); let window = match window { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let shown = window.show(); if let std::result::Result::Err(error) = shown { return std::result::Result::Err( ksp_core_lib::Error::new(crate::ERROR_CODE_TAURI_WINDOW_OPERATION_FAILED, "Cannot show SOL Prices Desk main window") .with_context("window_label", WINDOW_LABEL_MAIN) .with_source(error), ); } let focused = window.set_focus(); if let std::result::Result::Err(error) = focused { return std::result::Result::Err( ksp_core_lib::Error::new(crate::ERROR_CODE_TAURI_WINDOW_OPERATION_FAILED, "Cannot focus SOL Prices Desk main window") .with_context("window_label", WINDOW_LABEL_MAIN) .with_source(error), ); } ksp_logging_lib::debug!( target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WINDOWS, window_label = WINDOW_LABEL_MAIN, "main window shown and focused" ); return std::result::Result::Ok(()); }