diff options
-rw-r--r-- | src-tauri/src/constants.rs | 5 | ||||
-rw-r--r-- | src-tauri/src/main.rs | 13 | ||||
-rw-r--r-- | src-vue/src/plugins/store.ts | 5 |
3 files changed, 21 insertions, 2 deletions
diff --git a/src-tauri/src/constants.rs b/src-tauri/src/constants.rs index 57a10e02..7b13206a 100644 --- a/src-tauri/src/constants.rs +++ b/src-tauri/src/constants.rs @@ -1,6 +1,6 @@ // This file stores various global constants values - use const_format::concatcp; +use std::time::Duration; // FlightCore user agent for web requests pub const APP_USER_AGENT: &str = concatcp!("FlightCore/", env!("CARGO_PKG_VERSION")); @@ -34,3 +34,6 @@ pub const PULLS_API_ENDPOINT_LAUNCHER: &str = "https://api.github.com/repos/R2Northstar/NorthstarLauncher/pulls"; pub const PULLS_API_ENDPOINT_MODS: &str = "https://api.github.com/repos/R2Northstar/NorthstarMods/pulls"; + +// Statistics (players and servers counts) refresh delay +pub const REFRESH_DELAY: Duration = Duration::from_secs(5 * 60); diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index d2f7951d..d5fef9cb 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -10,7 +10,7 @@ use std::{ }; use app::{ - constants::{APP_USER_AGENT, MASTER_SERVER_URL, SERVER_BROWSER_ENDPOINT}, + constants::{APP_USER_AGENT, MASTER_SERVER_URL, REFRESH_DELAY, SERVER_BROWSER_ENDPOINT}, *, }; @@ -96,6 +96,17 @@ fn main() { } }); + // Emit updated player and server count to GUI + let app_handle = app.app_handle(); + tauri::async_runtime::spawn(async move { + loop { + sleep(REFRESH_DELAY).await; + app_handle + .emit_all("northstar-statistics", get_server_player_count().await) + .unwrap(); + } + }); + Ok(()) }) .manage(Counter(Default::default())) diff --git a/src-vue/src/plugins/store.ts b/src-vue/src/plugins/store.ts index 8671d12b..d5b7c5d8 100644 --- a/src-vue/src/plugins/store.ts +++ b/src-vue/src/plugins/store.ts @@ -455,6 +455,11 @@ function _initializeListeners(state: any) { listen("northstar-running-ping", function (evt: TauriEvent<any>) { state.northstar_is_running = evt.payload as boolean; }); + + listen("northstar-statistics", function (evt: TauriEvent<{Ok: [number, number]}>) { + state.player_count = evt.payload.Ok[0]; + state.server_count = evt.payload.Ok[1]; + }); } /** |