From 7407651bfe0e127c9dbdcb1a496e52242085f149 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Sun, 5 Jan 2025 01:37:42 +0100 Subject: [PATCH] feat: Re-implement passing playercount etc to frontend --- src-tauri/src/lib.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 450f212b2..7789eaa9d 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -11,6 +11,8 @@ mod thunderstore; mod util; use serde::{Deserialize, Serialize}; +use tauri::Emitter; +use tokio::time::sleep; use ts_rs::TS; #[derive(Serialize, Deserialize, Debug, Clone, TS)] @@ -51,6 +53,54 @@ pub fn run() { let tauri_builder_res = tauri::Builder::default() .plugin(tauri_plugin_store::Builder::new().build()) .plugin(tauri_plugin_opener::init()) + .setup(|app| { + let app_handle = app.handle().clone(); + tauri::async_runtime::spawn(async move { + loop { + sleep(Duration::from_millis(2000)).await; + // println!("sending backend ping"); + app_handle.emit("backend-ping", "ping").unwrap(); + } + }); + let app_handle = app.handle().clone(); + tauri::async_runtime::spawn(async move { + loop { + sleep(Duration::from_millis(2000)).await; + app_handle + .emit( + "ea-app-running-ping", + util::check_ea_app_or_origin_running(), + ) + .unwrap(); + } + }); + let app_handle = app.handle().clone(); + tauri::async_runtime::spawn(async move { + loop { + sleep(Duration::from_millis(2000)).await; + app_handle + .emit("northstar-running-ping", util::check_northstar_running()) + .unwrap(); + } + }); + + // Emit updated player and server count to GUI + let app_handle = app.handle().clone(); + tauri::async_runtime::spawn(async move { + loop { + sleep(constants::REFRESH_DELAY).await; + app_handle + .emit( + "northstar-statistics", + util::get_server_player_count().await, + ) + .unwrap(); + } + }); + + Ok(()) + }) + .manage(()) .invoke_handler(tauri::generate_handler![ development::install_git_main, github::compare_tags,