[feat] use eti game.db, commit not working, something is wrong with game.id in the client/frontend

This commit is contained in:
2024-11-12 22:12:49 +01:00
parent ba2177abf0
commit 1388bc2115
17 changed files with 790 additions and 310 deletions

View File

@ -1,4 +1,4 @@
use std::{net::SocketAddr, process::Command};
use std::net::SocketAddr;
use lanspread_client::{ClientCommand, ClientEvent};
use lanspread_mdns::{discover_service, LANSPREAD_INSTANCE_NAME, LANSPREAD_SERVICE_TYPE};
@ -22,24 +22,26 @@ fn request_games(state: tauri::State<LanSpreadState>) {
}
#[tauri::command]
fn run_game_backend(id: u64, state: tauri::State<LanSpreadState>) -> String {
fn run_game_backend(id: String, state: tauri::State<LanSpreadState>) -> String {
log::error!("Running game with id {id}");
let result = Command::new(r#"C:\Users\ddidderr\scoop\apps\mpv\0.39.0\mpv.exe"#).spawn();
// let result = Command::new(r#"C:\Users\ddidderr\scoop\apps\mpv\0.39.0\mpv.exe"#).spawn();
if let Err(e) = state.inner().client_ctrl.send(ClientCommand::GetGame(id)) {
log::error!("Failed to send message to client: {e:?}");
}
if result.is_ok() {
"Ok".to_string()
} else {
"Failed to run game".to_string()
}
"TODO".to_string()
// if result.is_ok() {
// "Ok".to_string()
// } else {
// "Failed to run game".to_string()
// }
}
async fn find_server(app: AppHandle) {
log::error!("Looking for server...");
log::info!("Looking for server...");
loop {
match discover_service(LANSPREAD_SERVICE_TYPE, Some(LANSPREAD_INSTANCE_NAME)) {
@ -73,7 +75,7 @@ pub fn run() {
tauri_plugin_log::TargetKind::Stdout,
))
.level(log::LevelFilter::Info)
.level_for("lanspread_client", log::LevelFilter::Debug)
.level_for("lanspread_client", log::LevelFilter::Trace)
.level_for("lanspread_tauri_leptos_lib", log::LevelFilter::Debug)
.level_for("mdns_sd::service_daemon", log::LevelFilter::Off);
@ -106,7 +108,7 @@ pub fn run() {
let app_handle = app.handle().clone();
tauri::async_runtime::spawn(async move {
while let Some(event) = rx_client_event.recv().await {
log::debug!("Received client event: {event:?}");
log::debug!("Received client event");
match event {
ClientEvent::ListGames(games) => {

View File

@ -16,7 +16,7 @@ extern "C" {
#[derive(Serialize, Deserialize)]
struct RunGameArgs {
id: u64,
id: String,
}
#[derive(Serialize, Deserialize)]
@ -59,14 +59,14 @@ pub fn App() -> impl IntoView {
});
// Call list_games on component mount
create_effect(move |_| {
spawn_local(async move {
let args = serde_wasm_bindgen::to_value(&()).unwrap();
invoke("request_games", args).await;
});
});
// create_effect(move |_| {
// spawn_local(async move {
// let args = serde_wasm_bindgen::to_value(&()).unwrap();
// invoke("request_games", args).await;
// });
// });
let run_game = move |id: u64| {
let run_game = move |id: String| {
log_1(&JsValue::from_str(format!("id={id}").as_str()));
spawn_local(async move {
let args = serde_wasm_bindgen::to_value(&RunGameArgs { id }).unwrap();
@ -87,7 +87,7 @@ pub fn App() -> impl IntoView {
{move || game_items.get().into_iter()
.map(|item|
view! {
<div class="item" on:click=move |_| run_game(item.id)>
<div class="item" on:click=move |_| run_game(item.id.clone())>
<img src="https://via.placeholder.com/200x150" alt="Item Image" />
<div class="item-name">{ &item.name }</div>
<div class="description">