* Add bottles platform

* Add bottles UI

* Only inc create_symlinks on unix
This commit is contained in:
Philip Kristoffersen
2022-09-12 18:32:55 +02:00
committed by GitHub
parent 6e69ff61db
commit e4be4da9e3
8 changed files with 173 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
mod platform;
mod settings;
pub use platform::*;
pub use settings::*;
+136
View File
@@ -0,0 +1,136 @@
use std::{error::Error, process::Command};
use eframe::epaint::ahash::HashMap;
use serde::{Deserialize, Serialize};
use crate::platform::Platform;
use super::BottlesSettings;
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct BottlesPlatform {
pub settings: BottlesSettings,
}
#[derive(Debug, Clone)]
pub struct BottlesApp {
pub name: String,
pub bottle: String,
}
impl From<BottlesApp> for ShortcutOwned {
fn from(app: BottlesApp) -> Self {
//
let launch_parameter = format!(
"run --command=bottles-cli com.usebottles.bottles run -b \"{}\" -p \"{}\"",
app.bottle, app.name
);
Shortcut::new("0", &app.name, "flatpak", "", "", "", &launch_parameter).to_owned()
}
}
impl Platform<BottlesApp, Box<dyn Error>> for BottlesPlatform {
fn enabled(&self) -> bool {
self.settings.enabled
}
fn name(&self) -> &str {
"Bottles"
}
fn get_shortcuts(&self) -> Result<Vec<BottlesApp>, Box<dyn Error>> {
let mut res = vec![];
let bottles = get_bottles();
dbg!(&bottles);
for bottle in bottles {
for (_id,program) in bottle.external_programs {
res.push(BottlesApp{
name:program.name,
bottle: bottle.name.clone()
})
}
}
Ok(res)
}
fn settings_valid(&self) -> crate::platform::SettingsValidity {
if let Ok(s) =self.get_shortcuts(){
if !s.is_empty() {
return crate::platform::SettingsValidity::Valid;
}
}
crate::platform::SettingsValidity::Invalid { reason: String::from("Nothing found")}
}
#[cfg(target_family = "unix")]
fn create_symlinks(&self) -> bool {
false
}
fn needs_proton(&self, _input: &BottlesApp) -> bool {
false
}
}
fn get_bottles() -> Vec<Bottle> {
let output_result = get_bottles_output();
match output_result {
Ok(json) => {
let map : HashMap<String,Bottle>= serde_json::from_str(json.as_str()).unwrap_or_default();
let mut res = vec![];
for (_,value) in map{
res.push(value);
}
res
},
Err(_err) => vec![],
}
}
fn get_bottles_output() -> Result<String, Box<dyn Error>> {
let output = {
#[cfg(not(feature = "flatpak"))]
{
let mut command = Command::new("flatpak");
command
.arg("run")
.arg("--command=bottles-cli")
.arg("com.usebottles.bottles")
.arg("-j")
.arg("list")
.arg("bottles")
.output()?
}
#[cfg(feature = "flatpak")]
{
let mut command = Command::new("flatpak-spawn");
command
.arg("--host")
.arg("flatpak")
.arg("run")
.arg("--command=bottles-cli")
.arg("com.usebottles.bottles")
.arg("-j")
.arg("list")
.arg("bottles")
.output()?
}
};
Ok(String::from_utf8_lossy(&output.stdout).to_string())
}
#[derive(Deserialize,Debug)]
struct Bottle {
#[serde(alias = "Name")]
pub(crate) name: String,
#[serde(alias = "External_Programs")]
pub(crate) external_programs : HashMap<String,Program>,
}
#[derive(Deserialize,Debug)]
struct Program {
#[serde(alias = "Name")]
pub(crate) name: String,
}
+6
View File
@@ -0,0 +1,6 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct BottlesSettings {
pub enabled: bool,
}
+3 -1
View File
@@ -43,10 +43,12 @@ default_launch_through_heroic = true
[amazon]
enabled = true
[flatpak]
enabled = true
[bottles]
enabled = true
[steam]
create_collections = false
optimize_for_big_picture = false
+1
View File
@@ -17,6 +17,7 @@ mod steamgriddb;
mod sync;
mod ui;
mod uplay;
mod bottles;
fn main() {
ensure_config_folder();
+5
View File
@@ -8,6 +8,9 @@ use crate::{
#[cfg(target_family = "unix")]
use crate::heroic::HeroicSettings;
#[cfg(target_family = "unix")]
use crate::bottles::BottlesSettings;
use config::{Config, ConfigError, Environment, File};
use serde::{Deserialize, Serialize};
use std::env;
@@ -30,6 +33,8 @@ pub struct Settings {
pub heroic: HeroicSettings,
pub amazon: AmazonSettings,
pub flatpak: FlatpakSettings,
#[cfg(target_family = "unix")]
pub bottles: BottlesSettings,
}
impl Settings {
+5
View File
@@ -224,6 +224,11 @@ pub fn get_platform_shortcuts(settings: &Settings) -> Vec<(String, Vec<ShortcutO
platform_results.push(update_platform_shortcuts(&FlatpakPlatform {
settings: settings.flatpak.clone(),
}));
platform_results.push(update_platform_shortcuts(&crate::bottles::BottlesPlatform {
settings: settings.bottles.clone(),
}));
}
#[cfg(windows)]
+10
View File
@@ -39,6 +39,7 @@ impl MyEguiApp {
#[cfg(target_family = "unix")]
{
self.render_heroic_settings(ui);
self.render_bottles_settings(ui);
}
self.render_legendary_settings(ui);
@@ -72,6 +73,15 @@ impl MyEguiApp {
ui.add_space(SECTION_SPACING);
}
#[cfg(target_family = "unix")]
fn render_bottles_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("Bottles");
ui.checkbox(&mut self.settings.bottles.enabled, "Import from Bottles");
ui.add_space(SECTION_SPACING);
}
#[cfg(target_family = "unix")]
fn render_heroic_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("Heroic");