|
| 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 | +} |
0 commit comments