Skip to content

Commit a5fa774

Browse files
authored
Add features to add flatpak apps on linux (#161)
* Add features to add flatpak apps on linux * Fix build on windows
1 parent b426201 commit a5fa774

File tree

10 files changed

+124
-3
lines changed

10 files changed

+124
-3
lines changed

Readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ There is also an [AUR package](https://aur.archlinux.org/packages/steam-boilr-gu
4242

4343
- [x] Show games from other platforms in your steam library
4444
- [x] Automatically download art from [SteamGridDB](https://www.steamgriddb.com/)
45+
- [x] Customize your Steam games art
46+
- [x] Backup your shortcuts
4547
- [x] Cross Platform (Windows, Linux, Mac, Steam Deck)
4648
- [x] Standalone / No install needed
4749
- [x] Small (~3mb on disk)
@@ -60,6 +62,7 @@ There is also an [AUR package](https://aur.archlinux.org/packages/steam-boilr-gu
6062
- [x] [Rare](https://github.com/Dummerle/Rare/releases)
6163
- [x] [Heroic Launcher](https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher) (Linux Only)
6264
- [x] [Amazon Games](https://gaming.amazon.com) (Windows Only)
65+
- [x] [Flatpak](https://flathub.org/) (Linux Only)
6366
- [ ] XBox/Microsoft Store integration
6467

6568

src/defaultconfig.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ default_launch_through_heroic = true
4343
[amazon]
4444
enabled = true
4545

46+
47+
[flatpak]
48+
enabled = true
49+
4650
[steam]
4751
create_collections = false
4852
optimize_for_big_picture = false

src/flatpak/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mod platform;
2+
mod settings;
3+
4+
pub use platform::*;
5+
pub use settings::*;

src/flatpak/platform.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
use crate::platform::{Platform, SettingsValidity};
4+
use std::error::Error;
5+
6+
use super::FlatpakSettings;
7+
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
8+
9+
#[derive(Debug, Deserialize, Serialize, Clone)]
10+
pub struct FlatpakPlatform {
11+
pub settings: FlatpakSettings,
12+
}
13+
14+
#[derive(Debug, Clone)]
15+
pub struct FlatpakApp {
16+
pub name: String,
17+
pub id: String,
18+
}
19+
20+
impl From<FlatpakApp> for ShortcutOwned {
21+
fn from(app: FlatpakApp) -> Self {
22+
let launch_parameter = format!("run {}", app.id);
23+
Shortcut::new("0", &app.name, "flatpak", "", "", "", &launch_parameter).to_owned()
24+
}
25+
}
26+
27+
impl Platform<FlatpakApp, Box<dyn Error>> for FlatpakPlatform {
28+
fn enabled(&self) -> bool {
29+
self.settings.enabled
30+
}
31+
32+
fn name(&self) -> &str {
33+
"Flatpak"
34+
}
35+
36+
fn get_shortcuts(&self) -> Result<Vec<FlatpakApp>, Box<dyn Error>> {
37+
use std::process::Command;
38+
let mut command = Command::new("flatpak");
39+
let output = command
40+
.arg("list")
41+
.arg("--app")
42+
.arg("--columns=name,application")
43+
.output()?;
44+
let output_string = String::from_utf8_lossy(&output.stdout).to_string();
45+
let mut result = vec![];
46+
for line in output_string.lines() {
47+
let mut split = line.split("\t");
48+
if let Some(name) = split.next() {
49+
if let Some(id) = split.next() {
50+
result.push(FlatpakApp {
51+
name: name.to_string(),
52+
id: id.to_string(),
53+
})
54+
}
55+
}
56+
}
57+
Ok(result)
58+
}
59+
60+
fn settings_valid(&self) -> crate::platform::SettingsValidity {
61+
let shortcuts_res = self.get_shortcuts();
62+
match shortcuts_res {
63+
Ok(_) => SettingsValidity::Valid,
64+
Err(err) => SettingsValidity::Invalid {
65+
reason: format!("{}", err),
66+
},
67+
}
68+
}
69+
70+
#[cfg(target_family = "unix")]
71+
fn create_symlinks(&self) -> bool {
72+
false
73+
}
74+
75+
fn needs_proton(&self, _input: &FlatpakApp) -> bool {
76+
false
77+
}
78+
}

src/flatpak/settings.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
#[derive(Debug, Deserialize, Serialize, Clone)]
4+
pub struct FlatpakSettings {
5+
pub enabled: bool,
6+
}

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ mod steamgriddb;
1515
mod sync;
1616
mod ui;
1717
mod uplay;
18+
mod flatpak;
1819
use std::error::Error;
1920

2021
fn main() -> Result<(), Box<dyn Error>> {

src/settings.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{
22
amazon::AmazonSettings, config::get_config_file, egs::EpicGamesLauncherSettings,
3-
gog::GogSettings, heroic::HeroicSettings, itch::ItchSettings, legendary::LegendarySettings,
4-
lutris::settings::LutrisSettings, origin::OriginSettings, steam::SteamSettings,
5-
steamgriddb::SteamGridDbSettings, uplay::UplaySettings,
3+
flatpak::FlatpakSettings, gog::GogSettings, heroic::HeroicSettings, itch::ItchSettings,
4+
legendary::LegendarySettings, lutris::settings::LutrisSettings, origin::OriginSettings,
5+
steam::SteamSettings, steamgriddb::SteamGridDbSettings, uplay::UplaySettings,
66
};
77

88
use config::{Config, ConfigError, Environment, File};
@@ -25,6 +25,7 @@ pub struct Settings {
2525
pub lutris: LutrisSettings,
2626
pub heroic: HeroicSettings,
2727
pub amazon: AmazonSettings,
28+
pub flatpak: FlatpakSettings,
2829
}
2930

3031
impl Settings {

src/sync/synchronization.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use tokio::sync::watch::Sender;
33

44
use crate::{
55
egs::EpicPlatform,
6+
flatpak::FlatpakPlatform,
67
legendary::LegendaryPlatform,
78
lutris::lutris_platform::LutrisPlatform,
89
platform::Platform,
@@ -217,6 +218,10 @@ pub fn get_platform_shortcuts(settings: &Settings) -> Vec<(String, Vec<ShortcutO
217218
platform_results.push(update_platform_shortcuts(&HeroicPlatform {
218219
settings: settings.heroic.clone(),
219220
}));
221+
222+
platform_results.push(update_platform_shortcuts(&FlatpakPlatform {
223+
settings: settings.flatpak.clone(),
224+
}));
220225
}
221226

222227
#[cfg(windows)]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Heroic Games Launcher com.heroicgameslauncher.hgl
2+
BoilR io.github.philipk.boilr
3+
Lutris net.lutris.Lutris

src/ui/ui_settings.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,27 @@ impl MyEguiApp {
4949
{
5050
self.render_amazon_settings(ui);
5151
}
52+
53+
54+
#[cfg(target_family = "unix")]
55+
{
56+
self.render_flatpak_settings(ui);
57+
}
58+
5259

5360
ui.add_space(SECTION_SPACING);
5461
ui.label(format!("Version: {}", VERSION));
5562
});
5663
}
5764

65+
fn render_flatpak_settings(&mut self, ui: &mut egui::Ui) {
66+
ui.heading("Flatpak");
67+
ui.checkbox(&mut self.settings.flatpak.enabled, "Import from Flatpak");
68+
69+
ui.add_space(SECTION_SPACING);
70+
}
71+
72+
5873
fn render_heroic_settings(&mut self, ui: &mut egui::Ui) {
5974
ui.heading("Heroic");
6075
ui.checkbox(&mut self.settings.heroic.enabled, "Import from Heroic");

0 commit comments

Comments
 (0)