peer count in UI

This commit is contained in:
2025-11-14 00:03:32 +01:00
parent 32e909448f
commit b9e3e760d9
4 changed files with 97 additions and 1 deletions
@@ -208,6 +208,23 @@ async fn update_game(id: String, state: tauri::State<'_, LanSpreadState>) -> tau
}
}
#[tauri::command]
async fn get_peer_count(state: tauri::State<'_, LanSpreadState>) -> tauri::Result<usize> {
let peer_ctrl_arc = state.inner().peer_ctrl.clone();
let peer_ctrl = peer_ctrl_arc.read().await.clone();
if let Some(peer_ctrl) = peer_ctrl {
// Send a request to get peer count
if let Err(e) = peer_ctrl.send(PeerCommand::GetPeerCount) {
log::error!("Failed to send GetPeerCount message to peer: {e:?}");
}
}
// For now, we'll return 0 and rely on the event-based updates
// The UI will get the actual count through peer-count-updated events
Ok(0)
}
#[cfg(target_os = "windows")]
fn run_as_admin(file: &str, params: &str, dir: &str) -> bool {
use std::{ffi::OsStr, os::windows::ffi::OsStrExt};
@@ -602,7 +619,8 @@ pub fn run() {
install_game,
run_game,
update_game_directory,
update_game
update_game,
get_peer_count
])
.manage(lanspread_state)
.setup({
@@ -847,6 +865,12 @@ pub fn run() {
log::error!("Failed to emit peer-lost event: {e}");
}
}
PeerEvent::PeerCountUpdated(count) => {
log::info!("Peer count updated: {count}");
if let Err(e) = app_handle.emit("peer-count-updated", Some(count)) {
log::error!("Failed to emit peer-count-updated event: {e}");
}
}
}
}
});