mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Bottles (#233)
* Add bottles platform * Add bottles UI * Only inc create_symlinks on unix
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
mod platform;
|
||||||
|
mod settings;
|
||||||
|
|
||||||
|
pub use platform::*;
|
||||||
|
pub use settings::*;
|
||||||
@@ -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,
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||||
|
pub struct BottlesSettings {
|
||||||
|
pub enabled: bool,
|
||||||
|
}
|
||||||
@@ -43,10 +43,12 @@ default_launch_through_heroic = true
|
|||||||
[amazon]
|
[amazon]
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|
||||||
|
|
||||||
[flatpak]
|
[flatpak]
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|
||||||
|
[bottles]
|
||||||
|
enabled = true
|
||||||
|
|
||||||
[steam]
|
[steam]
|
||||||
create_collections = false
|
create_collections = false
|
||||||
optimize_for_big_picture = false
|
optimize_for_big_picture = false
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ mod steamgriddb;
|
|||||||
mod sync;
|
mod sync;
|
||||||
mod ui;
|
mod ui;
|
||||||
mod uplay;
|
mod uplay;
|
||||||
|
mod bottles;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
ensure_config_folder();
|
ensure_config_folder();
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ use crate::{
|
|||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
use crate::heroic::HeroicSettings;
|
use crate::heroic::HeroicSettings;
|
||||||
|
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
use crate::bottles::BottlesSettings;
|
||||||
|
|
||||||
use config::{Config, ConfigError, Environment, File};
|
use config::{Config, ConfigError, Environment, File};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::env;
|
use std::env;
|
||||||
@@ -30,6 +33,8 @@ pub struct Settings {
|
|||||||
pub heroic: HeroicSettings,
|
pub heroic: HeroicSettings,
|
||||||
pub amazon: AmazonSettings,
|
pub amazon: AmazonSettings,
|
||||||
pub flatpak: FlatpakSettings,
|
pub flatpak: FlatpakSettings,
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
pub bottles: BottlesSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
|
|||||||
@@ -224,6 +224,11 @@ pub fn get_platform_shortcuts(settings: &Settings) -> Vec<(String, Vec<ShortcutO
|
|||||||
platform_results.push(update_platform_shortcuts(&FlatpakPlatform {
|
platform_results.push(update_platform_shortcuts(&FlatpakPlatform {
|
||||||
settings: settings.flatpak.clone(),
|
settings: settings.flatpak.clone(),
|
||||||
}));
|
}));
|
||||||
|
platform_results.push(update_platform_shortcuts(&crate::bottles::BottlesPlatform {
|
||||||
|
settings: settings.bottles.clone(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ impl MyEguiApp {
|
|||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
{
|
{
|
||||||
self.render_heroic_settings(ui);
|
self.render_heroic_settings(ui);
|
||||||
|
self.render_bottles_settings(ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.render_legendary_settings(ui);
|
self.render_legendary_settings(ui);
|
||||||
@@ -72,7 +73,16 @@ impl MyEguiApp {
|
|||||||
ui.add_space(SECTION_SPACING);
|
ui.add_space(SECTION_SPACING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(target_family = "unix")]
|
#[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) {
|
fn render_heroic_settings(&mut self, ui: &mut egui::Ui) {
|
||||||
ui.heading("Heroic");
|
ui.heading("Heroic");
|
||||||
ui.checkbox(&mut self.settings.heroic.enabled, "Import from Heroic");
|
ui.checkbox(&mut self.settings.heroic.enabled, "Import from Heroic");
|
||||||
|
|||||||
Reference in New Issue
Block a user