aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src-tauri/src/main.rs')
-rw-r--r--src-tauri/src/main.rs22
1 files changed, 15 insertions, 7 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index b6c923e3..95914898 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -427,20 +427,28 @@ async fn clean_up_download_folder_caller(
}
}
-/// Gets server and playercount from master server API
-#[tauri::command]
-async fn get_server_player_count() -> Result<(i32, usize), String> {
+/// Fetches `/client/servers` endpoint from master server
+async fn fetch_server_list() -> Result<String, anyhow::Error> {
let url = format!("{MASTER_SERVER_URL}{SERVER_BROWSER_ENDPOINT}");
let client = reqwest::Client::new();
let res = client
.get(url)
.header(reqwest::header::USER_AGENT, APP_USER_AGENT)
.send()
- .await
- .unwrap()
+ .await?
.text()
- .await
- .unwrap();
+ .await?;
+
+ Ok(res)
+}
+
+/// Gets server and playercount from master server API
+#[tauri::command]
+async fn get_server_player_count() -> Result<(i32, usize), String> {
+ let res = match fetch_server_list().await {
+ Ok(res) => res,
+ Err(err) => return Err(err.to_string()),
+ };
let ns_servers: Vec<NorthstarServer> =
serde_json::from_str(&res).expect("JSON was not well-formatted");