0.1.0-1-alpha.2-fix.3
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/apps/game-reflex-poc-tauri/src/lib.rs
|
||||
// version: 2
|
||||
// version: 3
|
||||
|
||||
//! Tauri desktop application facade for the Reflex WebAssembly POC.
|
||||
|
||||
@@ -15,5 +15,7 @@ pub use self::tauri::run;
|
||||
|
||||
/// Records that the Vite/TypeScript frontend reached its ready state.
|
||||
pub(crate) use self::runtime::record_frontend_ready;
|
||||
/// Records one accepted native window close request.
|
||||
pub(crate) use self::runtime::record_window_close;
|
||||
/// Returns the runtime label exposed by the Tauri bridge.
|
||||
pub(crate) use self::runtime::runtime_label;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/apps/game-reflex-poc-tauri/src/runtime.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
/// Stable label for the current Tauri/WASM runtime combination.
|
||||
pub(crate) fn runtime_label() -> &'static str {
|
||||
@@ -16,3 +16,14 @@ pub(crate) fn record_frontend_ready() {
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
/// Records one accepted native window close request.
|
||||
pub(crate) fn record_window_close(source: &str) {
|
||||
tracing::info!(
|
||||
target: "games::tauri::reflex",
|
||||
action = "window_close",
|
||||
source = source,
|
||||
"Reflex Tauri window close accepted"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
// file: crates/apps/game-reflex-poc-tauri/src/tauri.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
//! Tauri runtime assembly and Web/Rust commands for the Reflex POC.
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct FrontendLogPayload {
|
||||
level: String,
|
||||
target_id: String,
|
||||
message: String,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_runtime_label() -> String {
|
||||
@@ -12,6 +22,47 @@ fn frontend_ready() {
|
||||
return;
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn emit_frontend_log(payload: FrontendLogPayload) -> std::result::Result<(), String> {
|
||||
let target_id = payload.target_id.trim();
|
||||
if target_id != "frontend" && target_id != "main" {
|
||||
return std::result::Result::Err("unsupported frontend log target".to_string());
|
||||
}
|
||||
let message = payload.message.as_str();
|
||||
return match payload.level.trim().to_ascii_lowercase().as_str() {
|
||||
"trace" => {
|
||||
tracing::trace!(target: "games::tauri::reflex::frontend", action = "frontend_log", target_id = target_id, "{message}");
|
||||
std::result::Result::Ok(())
|
||||
},
|
||||
"debug" => {
|
||||
tracing::debug!(target: "games::tauri::reflex::frontend", action = "frontend_log", target_id = target_id, "{message}");
|
||||
std::result::Result::Ok(())
|
||||
},
|
||||
"info" => {
|
||||
tracing::info!(target: "games::tauri::reflex::frontend", action = "frontend_log", target_id = target_id, "{message}");
|
||||
std::result::Result::Ok(())
|
||||
},
|
||||
"warn" => {
|
||||
tracing::warn!(target: "games::tauri::reflex::frontend", action = "frontend_log", target_id = target_id, "{message}");
|
||||
std::result::Result::Ok(())
|
||||
},
|
||||
"error" => {
|
||||
tracing::error!(target: "games::tauri::reflex::frontend", action = "frontend_log", target_id = target_id, "{message}");
|
||||
std::result::Result::Ok(())
|
||||
},
|
||||
_ => std::result::Result::Err("unsupported frontend log level".to_string()),
|
||||
};
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn close_main_window(window: tauri::WebviewWindow) -> std::result::Result<(), String> {
|
||||
crate::record_window_close("game_quit_decision");
|
||||
return match window.close() {
|
||||
std::result::Result::Ok(()) => std::result::Result::Ok(()),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(error.to_string()),
|
||||
};
|
||||
}
|
||||
|
||||
fn configure_plugins(builder: tauri::Builder<tauri::Wry>) -> tauri::Builder<tauri::Wry> {
|
||||
let tracing_plugin = tauri_plugin_tracing::Builder::new().build::<tauri::Wry>();
|
||||
return builder.plugin(tracing_plugin);
|
||||
@@ -19,11 +70,16 @@ fn configure_plugins(builder: tauri::Builder<tauri::Wry>) -> tauri::Builder<taur
|
||||
|
||||
#[allow(clippy::question_mark_used)] // Tauri generates the question-mark operator internally for command dispatch.
|
||||
fn configure_commands(builder: tauri::Builder<tauri::Wry>) -> tauri::Builder<tauri::Wry> {
|
||||
return builder.invoke_handler(tauri::generate_handler![get_runtime_label, frontend_ready]);
|
||||
return builder.invoke_handler(tauri::generate_handler![get_runtime_label, frontend_ready, emit_frontend_log, close_main_window]);
|
||||
}
|
||||
|
||||
/// Runs the Reflex Tauri desktop application.
|
||||
pub fn run() -> std::result::Result<(), String> {
|
||||
let logging_guard = game_logging_lib::init_console_tracing();
|
||||
let _logging_guard = match logging_guard {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()),
|
||||
};
|
||||
tracing::info!(
|
||||
target: "games::tauri::reflex",
|
||||
action = "runtime_start",
|
||||
@@ -33,7 +89,22 @@ pub fn run() -> std::result::Result<(), String> {
|
||||
let builder = configure_plugins(builder);
|
||||
let builder = configure_commands(builder);
|
||||
return match builder.run(tauri::generate_context!()) {
|
||||
std::result::Result::Ok(()) => std::result::Result::Ok(()),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(error.to_string()),
|
||||
std::result::Result::Ok(()) => {
|
||||
tracing::info!(
|
||||
target: "games::tauri::reflex",
|
||||
action = "runtime_stop",
|
||||
"Reflex Tauri runtime stopped"
|
||||
);
|
||||
std::result::Result::Ok(())
|
||||
},
|
||||
std::result::Result::Err(error) => {
|
||||
tracing::error!(
|
||||
target: "games::tauri::reflex",
|
||||
action = "runtime_error",
|
||||
error = error.to_string(),
|
||||
"Reflex Tauri runtime failed"
|
||||
);
|
||||
std::result::Result::Err(error.to_string())
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user