Skip to content

Commit

Permalink
Add support for lutris flatpak version (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipK authored May 1, 2022
1 parent 3f075f8 commit 81ddcb6
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 25 deletions.
3 changes: 3 additions & 0 deletions src/defaultconfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ create_symlinks = true

[lutris]
enabled = false
executable = "lutris"
flatpak_image = "net.lutris.Lutris//beta"
flatpak = false

[heroic]
enabled = true
Expand Down
2 changes: 2 additions & 0 deletions src/lutris/game_list_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ fn parse_line(input: &str) -> Option<LutrisGame> {
index: index.to_string(),
name: name.to_string(),
platform: platform.to_string(),
//theese will be added by the platform class
settings: None,
})
}

Expand Down
45 changes: 43 additions & 2 deletions src/lutris/lutris_game.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::lutris::settings::LutrisSettings;
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};

#[derive(Clone)]
Expand All @@ -6,15 +7,17 @@ pub struct LutrisGame {
pub name: String,
pub id: String,
pub platform: String,
pub settings: Option<LutrisSettings>,
}

impl From<LutrisGame> 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(),
"",
"",
"",
Expand All @@ -23,3 +26,41 @@ impl From<LutrisGame> 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()
}
}
}
25 changes: 16 additions & 9 deletions src/lutris/lutris_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,12 @@ impl Platform<LutrisGame, Box<dyn Error>> for LutrisPlatform {
}

fn get_shortcuts(&self) -> Result<Vec<LutrisGame>, Box<dyn Error>> {
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);
}
}
Expand All @@ -56,3 +50,16 @@ impl Platform<LutrisGame, Box<dyn Error>> for LutrisPlatform {
false
}
}

fn get_lutris_command_output(settings: &LutrisSettings) -> Result<String, Box<dyn Error>> {
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())
}
4 changes: 3 additions & 1 deletion src/lutris/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct LutrisSettings {
pub enabled: bool,
pub executable: Option<String>,
pub executable: String,
pub flatpak: bool,
pub flatpak_image: String,
}
27 changes: 14 additions & 13 deletions src/ui/ui_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 81ddcb6

Please sign in to comment.