1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::system::{System, SystemTweaks};
6
7#[derive(PartialEq, Debug, Deserialize, Serialize)]
8pub struct TweakSettings {
9 pub gamemode: Option<bool>,
10 pub mangohud: Option<bool>,
11}
12
13#[derive(Debug, Deserialize, Serialize)]
14pub struct Issue {
15 pub description: String,
16 pub solution: Option<String>,
17}
18
19#[derive(Debug, Deserialize, Serialize)]
20pub struct Tweaks {
21 pub tricks: Vec<String>,
22 pub env: HashMap<String, String>,
23 pub args: Vec<String>,
24 pub settings: TweakSettings,
25 pub system: System,
26}
27
28#[derive(Debug, Deserialize, Serialize)]
29pub struct App {
30 pub id: String,
31 pub name: String,
32 pub tweaks: Tweaks,
33 pub issues: Vec<Issue>,
34}
35
36impl Clone for TweakSettings {
37 fn clone(&self) -> Self {
38 Self {
39 gamemode: self.gamemode.clone(),
40 mangohud: self.mangohud.clone(),
41 }
42 }
43}
44
45impl App {
46 pub async fn flatten(&self) -> SystemTweaks {
48 let mut env = self.tweaks.env.clone();
49 let mut tricks = self.tweaks.tricks.clone();
50 let mut args = self.tweaks.args.clone();
51 let mut settings = self.tweaks.settings.clone();
52
53 if let Some(gpu_tweaks) = self.tweaks.system.gpu_driver.get_tweaks().await {
54 env.extend(gpu_tweaks.env.clone());
56 tricks.extend(gpu_tweaks.tricks.clone());
57 args.extend(gpu_tweaks.args.clone());
58
59 if let Some(gamemode) = gpu_tweaks.settings.gamemode {
60 settings.gamemode = Some(gamemode);
61 }
62
63 if let Some(mangohud) = gpu_tweaks.settings.mangohud {
64 settings.mangohud = Some(mangohud);
65 }
66 }
67
68 SystemTweaks {
69 env,
70 args,
71 tricks,
72 settings,
73 }
74 }
75}
76
77#[cfg(test)]
78mod tests {
79 use crate::Protontweaks;
80
81 #[tokio::test]
82 async fn flatten() {
83 let api = Protontweaks::new();
84
85 let app = api.app("644930").await;
86
87 assert_eq!(app.tweaks.tricks.len(), app.flatten().await.tricks.len());
88 }
89}