mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
fix: get games list as json from lutris (#191)
This commit is contained in:
@@ -1,32 +1,15 @@
|
|||||||
use super::lutris_game::LutrisGame;
|
use super::lutris_game::LutrisGame;
|
||||||
|
|
||||||
pub fn parse_lutris_games(input: &str) -> Vec<LutrisGame> {
|
pub fn parse_lutris_games(input: &str) -> Vec<LutrisGame> {
|
||||||
input
|
let games = serde_json::from_str::<Vec<LutrisGame>>(&input);
|
||||||
.split('\n')
|
match games {
|
||||||
.into_iter()
|
Ok(games) => {
|
||||||
.filter(|s| !s.is_empty())
|
return games
|
||||||
.filter_map(parse_line)
|
}
|
||||||
.collect()
|
Err(_err) => {
|
||||||
}
|
return Vec::new()
|
||||||
|
}
|
||||||
fn parse_line(input: &str) -> Option<LutrisGame> {
|
|
||||||
let mut sections = input.split('|');
|
|
||||||
if sections.clone().count() < 4 {
|
|
||||||
return None;
|
|
||||||
}
|
}
|
||||||
let index = sections.next().unwrap().trim();
|
|
||||||
let name = sections.next().unwrap().trim();
|
|
||||||
let id = sections.next().unwrap().trim();
|
|
||||||
let platform = sections.next().unwrap().trim();
|
|
||||||
|
|
||||||
Some(LutrisGame {
|
|
||||||
id: id.to_string(),
|
|
||||||
index: index.to_string(),
|
|
||||||
name: name.to_string(),
|
|
||||||
platform: platform.to_string(),
|
|
||||||
//theese will be added by the platform class
|
|
||||||
settings: None,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -39,7 +22,7 @@ mod tests {
|
|||||||
|
|
||||||
let games = parse_lutris_games(content);
|
let games = parse_lutris_games(content);
|
||||||
|
|
||||||
assert_eq!(19, games.len());
|
assert_eq!(6, games.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -48,7 +31,7 @@ mod tests {
|
|||||||
|
|
||||||
let games = parse_lutris_games(content);
|
let games = parse_lutris_games(content);
|
||||||
|
|
||||||
assert_eq!(games[0].index, "7");
|
assert_eq!(games[0].id, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -57,7 +40,7 @@ mod tests {
|
|||||||
|
|
||||||
let games = parse_lutris_games(content);
|
let games = parse_lutris_games(content);
|
||||||
|
|
||||||
assert_eq!(games[1].name, "Cave Story+");
|
assert_eq!(games[5].name, "The Witcher 3: Wild Hunt - Game of the Year Edition");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -66,7 +49,7 @@ mod tests {
|
|||||||
|
|
||||||
let games = parse_lutris_games(content);
|
let games = parse_lutris_games(content);
|
||||||
|
|
||||||
assert_eq!(games[3].id, "dicey-dungeons");
|
assert_eq!(games[5].slug, "the-witcher-3-wild-hunt-game-of-the-year-edition");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -75,6 +58,6 @@ mod tests {
|
|||||||
|
|
||||||
let games = parse_lutris_games(content);
|
let games = parse_lutris_games(content);
|
||||||
|
|
||||||
assert_eq!(games[18].platform, "steam");
|
assert_eq!(games[1].runner, "steam");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
use crate::lutris::settings::LutrisSettings;
|
use crate::lutris::settings::LutrisSettings;
|
||||||
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
|
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
|
||||||
|
|
||||||
#[derive(Clone)]
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize, Clone)]
|
||||||
pub struct LutrisGame {
|
pub struct LutrisGame {
|
||||||
pub index: String,
|
pub id: i64,
|
||||||
|
pub slug: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub id: String,
|
pub runner: String,
|
||||||
pub platform: String,
|
pub platform: String,
|
||||||
pub settings: Option<LutrisSettings>,
|
pub settings: Option<LutrisSettings>,
|
||||||
}
|
}
|
||||||
@@ -36,15 +39,15 @@ impl LutrisGame {
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
if is_flatpak {
|
if is_flatpak {
|
||||||
format!(
|
format!(
|
||||||
"run {} lutris:rungameid/{}",
|
"run {} lutris:rungame/{}",
|
||||||
self.settings
|
self.settings
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|s| s.flatpak_image.clone())
|
.map(|s| s.flatpak_image.clone())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
self.index
|
self.slug
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
format!("lutris:rungame/{}", self.id)
|
format!("lutris:rungame/{}", self.slug)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ impl Platform<LutrisGame, Box<dyn Error>> for LutrisPlatform {
|
|||||||
let games = parse_lutris_games(output.as_str());
|
let games = parse_lutris_games(output.as_str());
|
||||||
let mut res = vec![];
|
let mut res = vec![];
|
||||||
for mut game in games {
|
for mut game in games {
|
||||||
if game.platform != "steam" {
|
if game.runner != "steam" {
|
||||||
game.settings = Some(self.settings.clone());
|
game.settings = Some(self.settings.clone());
|
||||||
res.push(game);
|
res.push(game);
|
||||||
}
|
}
|
||||||
@@ -55,10 +55,10 @@ fn get_lutris_command_output(settings: &LutrisSettings) -> Result<String, Box<dy
|
|||||||
let output = if settings.flatpak {
|
let output = if settings.flatpak {
|
||||||
let flatpak_image = &settings.flatpak_image;
|
let flatpak_image = &settings.flatpak_image;
|
||||||
let mut command = Command::new("flatpak");
|
let mut command = Command::new("flatpak");
|
||||||
command.arg("run").arg(flatpak_image).arg("-lo").output()?
|
command.arg("run").arg(flatpak_image).arg("-lo").arg("--json").output()?
|
||||||
} else {
|
} else {
|
||||||
let mut command = Command::new(&settings.executable);
|
let mut command = Command::new(&settings.executable);
|
||||||
command.arg("-lo").output()?
|
command.arg("-lo").arg("--json").output()?
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(String::from_utf8_lossy(&output.stdout).to_string())
|
Ok(String::from_utf8_lossy(&output.stdout).to_string())
|
||||||
|
|||||||
+74
-19
@@ -1,19 +1,74 @@
|
|||||||
7 | 7 Billion Humans | 7-billion-humans | steam | -
|
[
|
||||||
1 | Cave Story+ | cave-story | steam | -
|
{
|
||||||
15 | Dead Cells | dead-cells | steam | -
|
"id": 1,
|
||||||
6 | Dicey Dungeons | dicey-dungeons | steam | -
|
"slug": "aperture-desk-job",
|
||||||
12 | Finding Paradise | finding-paradise | steam | -
|
"name": "Aperture Desk Job",
|
||||||
17 | Griftlands | griftlands | steam | -
|
"runner": "steam",
|
||||||
4 | Gunpoint | gunpoint | steam | -
|
"platform": "Linux",
|
||||||
5 | Impostor Factory | impostor-factory | steam | -
|
"year": null,
|
||||||
3 | Kentucky Route Zero | kentucky-route-zero | steam | -
|
"directory": null,
|
||||||
13 | Monster Train | monster-train | steam | -
|
"hidden": false,
|
||||||
19 | My Test Game | my-test-game | linux | -
|
"playtime": null,
|
||||||
8 | Owlboy | owlboy | steam | -
|
"lastplayed": null
|
||||||
16 | Papers, Please | papers-please | steam | -
|
},
|
||||||
11 | Reventure | reventure | steam | -
|
{
|
||||||
2 | Slay the Spire | slay-the-spire | steam | -
|
"id": 2,
|
||||||
9 | Space Pirates and Zombies | space-pirates-and-zombies | steam | -
|
"slug": "dark-souls-iii",
|
||||||
10 | The Detail | the-detail | steam | -
|
"name": "DARK SOULS\u2122 III",
|
||||||
14 | The Henry Stickmin Collection | the-henry-stickmin-collection | steam | -
|
"runner": "steam",
|
||||||
18 | Vampire Survivors | vampire-survivors | steam | -
|
"platform": "Linux",
|
||||||
|
"year": null,
|
||||||
|
"directory": null,
|
||||||
|
"hidden": false,
|
||||||
|
"playtime": null,
|
||||||
|
"lastplayed": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 4,
|
||||||
|
"slug": "disco-elysium",
|
||||||
|
"name": "Disco Elysium",
|
||||||
|
"runner": "wine",
|
||||||
|
"platform": "Windows",
|
||||||
|
"year": 2019,
|
||||||
|
"directory": "/home/deck/Games/gog/disco-elysium",
|
||||||
|
"hidden": false,
|
||||||
|
"playtime": "0:01:16",
|
||||||
|
"lastplayed": "2022-07-25 23:21:56"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"slug": "hollow-knight",
|
||||||
|
"name": "Hollow Knight",
|
||||||
|
"runner": "steam",
|
||||||
|
"platform": "Linux",
|
||||||
|
"year": null,
|
||||||
|
"directory": null,
|
||||||
|
"hidden": false,
|
||||||
|
"playtime": null,
|
||||||
|
"lastplayed": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 7,
|
||||||
|
"slug": "lumino-city",
|
||||||
|
"name": "Lumino City",
|
||||||
|
"runner": "wine",
|
||||||
|
"platform": "Windows",
|
||||||
|
"year": null,
|
||||||
|
"directory": "/home/deck/Games/gog/lumino-city",
|
||||||
|
"hidden": false,
|
||||||
|
"playtime": null,
|
||||||
|
"lastplayed": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"slug": "the-witcher-3-wild-hunt-game-of-the-year-edition",
|
||||||
|
"name": "The Witcher 3: Wild Hunt - Game of the Year Edition",
|
||||||
|
"runner": "wine",
|
||||||
|
"platform": "Windows",
|
||||||
|
"year": 2015,
|
||||||
|
"directory": "/home/deck/Games/gog/the-witcher-3-wild-hunt-game-of-the-year-edition",
|
||||||
|
"hidden": false,
|
||||||
|
"playtime": "0:00:54",
|
||||||
|
"lastplayed": "2022-07-25 23:20:40"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user