mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Add support for lutris flatpak version (#114)
This commit is contained in:
@@ -32,6 +32,9 @@ create_symlinks = true
|
||||
|
||||
[lutris]
|
||||
enabled = false
|
||||
executable = "lutris"
|
||||
flatpak_image = "net.lutris.Lutris//beta"
|
||||
flatpak = false
|
||||
|
||||
[heroic]
|
||||
enabled = true
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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<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(),
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
+14
-13
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user