Make platforms generic

This commit is contained in:
Philip Kristoffersen
2021-09-25 08:50:03 +02:00
parent 99079dcaff
commit 9493262076
13 changed files with 136 additions and 93 deletions
+35
View File
@@ -0,0 +1,35 @@
use super::{LegendaryGame, LegendarySettings};
use crate::platform::Platform;
use serde_json::from_str;
use std::error::Error;
use std::process::Command;
pub struct LegendaryPlatform {
settings: LegendarySettings,
}
impl LegendaryPlatform {
pub fn new(settings: LegendarySettings) -> LegendaryPlatform {
Self { settings }
}
}
impl Platform<LegendaryGame, Box<dyn Error>> for LegendaryPlatform {
fn enabled(&self) -> bool {
self.settings.enabled
}
fn name(&self) -> &str {
"Legendary"
}
fn get_shortcuts(&self) -> Result<Vec<LegendaryGame>, Box<dyn Error>> {
let legendary_command = Command::new("legendary")
.arg("list-installed")
.arg("--json")
.output()?;
let json = String::from_utf8_lossy(&legendary_command.stdout);
let legendary_ouput = from_str(&json)?;
Ok(legendary_ouput)
}
}