game_manager_lib/services/integration/
protondb.rs1use crate::constants::{HTTP_CONNECT_TIMEOUT_SECS, USER_AGENT_BROWSER};
8use crate::utils::http_client::HTTP_CLIENT;
9use serde::{Deserialize, Serialize};
10use std::time::Duration;
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
13#[serde(rename_all = "camelCase")]
14pub struct ProtonDbSummary {
15 pub tier: String, pub trending_tier: String,
17 pub best_reported_tier: String,
18 pub confidence: String, pub score: f32,
20 pub total: u32, }
22
23pub async fn get_compatibility_summary(app_id: &str) -> Result<Option<ProtonDbSummary>, String> {
28 let url = format!(
29 "https://www.protondb.com/api/v1/reports/summaries/{}.json",
30 app_id
31 );
32
33 let res = HTTP_CLIENT
34 .get(&url)
35 .header("User-Agent", USER_AGENT_BROWSER)
36 .timeout(Duration::from_secs(HTTP_CONNECT_TIMEOUT_SECS))
37 .send()
38 .await
39 .map_err(|e| format!("Erro requisição ProtonDB: {}", e))?;
40
41 if res.status().as_u16() == 404 {
42 return Ok(None); }
44
45 if !res.status().is_success() {
46 return Err(format!("ProtonDB API Error: {}", res.status()));
47 }
48
49 let data: ProtonDbSummary = res
50 .json()
51 .await
52 .map_err(|e| format!("Erro ao parsear resposta ProtonDB: {}", e))?;
53
54 Ok(Some(data))
55}
56
57pub fn is_running_on_linux() -> bool {
58 cfg!(target_os = "linux")
59}