Add player stats and server leaderboards to Desktop app and polish UI
This commit is contained in:
1 parent
ebd9de1bee
commit
3043f3ab42
12 files changed
+826
-66
No files matched your search
@@ -478,3 +478,45 @@ pub fn show_window(app: AppHandle) {
|
||||
w.set_focus().ok();
|
||||
}
|
||||
}
|
||||
|
||||
// ---- stats & leaderboards ----
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_player_stats(state: State<'_, AppState>) -> Res<serde_json::Value> {
|
||||
let req = account_api(&state, reqwest::Method::GET, "/account/stats").await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to load player stats".into());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_leaderboard(
|
||||
state: State<'_, AppState>,
|
||||
server_id: Option<i64>,
|
||||
sort: Option<String>,
|
||||
) -> Res<serde_json::Value> {
|
||||
let panel = state.panel_url().ok_or("no panel configured")?;
|
||||
let sort_query = sort.map(|s| format!("?sort={s}")).unwrap_or_default();
|
||||
let url = if let Some(id) = server_id {
|
||||
format!("{panel}/api/v1/servers/{id}/leaderboard{sort_query}")
|
||||
} else {
|
||||
format!("{panel}/api/v1/leaderboard{sort_query}")
|
||||
};
|
||||
let resp = state.http.get(&url).send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to load leaderboard".into());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_public_servers(state: State<'_, AppState>) -> Res<serde_json::Value> {
|
||||
let panel = state.panel_url().ok_or("no panel configured")?;
|
||||
let resp = state.http.get(format!("{panel}/api/v1/servers/public")).send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to load servers".into());
|
||||
}
|
||||
resp.json().await.map_err(err)
|
||||
}
|
||||
@@ -81,6 +81,9 @@ pub fn run() {
|
||||
commands::check_update,
|
||||
commands::install_update,
|
||||
commands::show_window,
|
||||
commands::get_player_stats,
|
||||
commands::get_leaderboard,
|
||||
commands::get_public_servers,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running the launcher");
|
||||
|
||||
Reference in new issue
Block a user