51 lines
2.0 KiB
Rust
51 lines
2.0 KiB
Rust
// file: crates/ksp-app-config-desk/src/tw_main.rs
|
|
// version: 1
|
|
|
|
//! Tauri-window helpers for the Config Desk main window.
|
|
|
|
use tauri::Manager; // rust-rules: trait-import
|
|
|
|
pub(crate) const WINDOW_LABEL_MAIN: &str = "main";
|
|
|
|
pub(crate) fn require_window(manager: &impl Manager<tauri::Wry>) -> ksp_core_lib::Result<tauri::WebviewWindow> {
|
|
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, "Config Desk main window is missing")
|
|
.with_context("window_label", WINDOW_LABEL_MAIN),
|
|
),
|
|
};
|
|
}
|
|
|
|
pub(crate) fn show_and_focus(app: &tauri::AppHandle) -> ksp_core_lib::Result<()> {
|
|
let window = require_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 Config 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 Config 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(());
|
|
}
|