diff --git a/src/defaultconfig.toml b/src/defaultconfig.toml index 187a260a..8120d189 100644 --- a/src/defaultconfig.toml +++ b/src/defaultconfig.toml @@ -32,6 +32,9 @@ create_symlinks = true [lutris] enabled = false +executable = "lutris" +flatpak_image = "net.lutris.Lutris//beta" +flatpak = false [heroic] enabled = true diff --git a/src/lutris/game_list_parser.rs b/src/lutris/game_list_parser.rs index f49a7fd0..f4b2d9fb 100644 --- a/src/lutris/game_list_parser.rs +++ b/src/lutris/game_list_parser.rs @@ -24,6 +24,8 @@ fn parse_line(input: &str) -> Option { index: index.to_string(), name: name.to_string(), platform: platform.to_string(), + //theese will be added by the platform class + settings: None, }) } diff --git a/src/lutris/lutris_game.rs b/src/lutris/lutris_game.rs index b7f2ccc4..a4967bf8 100644 --- a/src/lutris/lutris_game.rs +++ b/src/lutris/lutris_game.rs @@ -1,3 +1,4 @@ +use crate::lutris::settings::LutrisSettings; use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut}; #[derive(Clone)] @@ -6,15 +7,17 @@ pub struct LutrisGame { pub name: String, pub id: String, pub platform: String, + pub settings: Option, } impl From for ShortcutOwned { fn from(game: LutrisGame) -> Self { - let options = format!("lutris:rungame/{}", game.id); + let options = game.get_options(); + let exectuable = game.get_executable(); Shortcut::new( "0", game.name.as_str(), - "lutris", + exectuable.as_str(), "", "", "", @@ -23,3 +26,41 @@ impl From for ShortcutOwned { .to_owned() } } + +impl LutrisGame { + pub fn get_options(&self) -> String { + let is_flatpak = self + .settings + .as_ref() + .map(|s| s.flatpak) + .unwrap_or_default(); + if is_flatpak { + format!( + "run {} lutris:rungame/{}", + self.settings + .as_ref() + .map(|s| s.flatpak_image.clone()) + .unwrap_or_default(), + self.id + ) + } else { + format!("lutris:rungame/{}", self.id) + } + } + + pub fn get_executable(&self) -> String { + let is_flatpak = self + .settings + .as_ref() + .map(|s| s.flatpak) + .unwrap_or_default(); + if is_flatpak { + "flatpak".to_string() + } else { + self.settings + .as_ref() + .map(|s| s.executable.clone()) + .unwrap_or_default() + } + } +} diff --git a/src/lutris/lutris_platform.rs b/src/lutris/lutris_platform.rs index ef4d50ab..0d2ef054 100644 --- a/src/lutris/lutris_platform.rs +++ b/src/lutris/lutris_platform.rs @@ -19,18 +19,12 @@ impl Platform> for LutrisPlatform { } fn get_shortcuts(&self) -> Result, Box> { - let default_lutris_exe = "lutris".to_string(); - let lutris_executable = self - .settings - .executable - .as_ref() - .unwrap_or(&default_lutris_exe); - let lutris_command = Command::new(lutris_executable).arg("-lo").output()?; - let output = String::from_utf8_lossy(&lutris_command.stdout).to_string(); + let output = get_lutris_command_output(&self.settings)?; let games = parse_lutris_games(output.as_str()); let mut res = vec![]; - for game in games { + for mut game in games { if game.platform != "steam" { + game.settings = Some(self.settings.clone()); res.push(game); } } @@ -56,3 +50,16 @@ impl Platform> for LutrisPlatform { false } } + +fn get_lutris_command_output(settings: &LutrisSettings) -> Result> { + let output = if settings.flatpak { + let flatpak_image = &settings.flatpak_image; + let mut command = Command::new("flatpak"); + command.arg("run").arg(flatpak_image).arg("-lo").output()? + } else { + let mut command = Command::new(&settings.executable); + command.arg("-lo").output()? + }; + + Ok(String::from_utf8_lossy(&output.stdout).to_string()) +} diff --git a/src/lutris/settings.rs b/src/lutris/settings.rs index d8f8dc2d..ea58b693 100644 --- a/src/lutris/settings.rs +++ b/src/lutris/settings.rs @@ -3,5 +3,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Deserialize, Serialize, Clone)] pub struct LutrisSettings { pub enabled: bool, - pub executable: Option, + pub executable: String, + pub flatpak: bool, + pub flatpak_image: String, } diff --git a/src/ui/ui_settings.rs b/src/ui/ui_settings.rs index d2a1a65c..c7cb9af6 100644 --- a/src/ui/ui_settings.rs +++ b/src/ui/ui_settings.rs @@ -58,19 +58,20 @@ impl MyEguiApp { ui.heading("Lutris"); ui.checkbox(&mut self.settings.lutris.enabled, "Import form Lutris"); if self.settings.lutris.enabled { - ui.horizontal(|ui| { - let mut empty_string = "".to_string(); - let lutris_location = self - .settings - .lutris - .executable - .as_mut() - .unwrap_or(&mut empty_string); - ui.label("Lutris Location: "); - if ui.text_edit_singleline(lutris_location).changed() { - self.settings.lutris.executable = Some(lutris_location.to_string()); - } - }); + ui.checkbox(&mut self.settings.lutris.flatpak, "Flatpak version"); + if !self.settings.lutris.flatpak { + ui.horizontal(|ui| { + let lutris_location = &mut self.settings.lutris.executable; + ui.label("Lutris Location: "); + ui.text_edit_singleline(lutris_location); + }); + } else { + ui.horizontal(|ui| { + let flatpak_image = &mut self.settings.lutris.flatpak_image; + ui.label("Flatpak image"); + ui.text_edit_singleline(flatpak_image); + }); + } } ui.add_space(SECTION_SPACING); }