From 5e8e4f2451d0a4ec6e8b24c27465ec69a2749aad Mon Sep 17 00:00:00 2001 From: Philip Kristoffersen Date: Tue, 24 May 2022 19:46:12 +0200 Subject: [PATCH] Add option to always launch through heroic (#156) * Add option to always launch through heroic * Default to launche through heroic --- src/defaultconfig.toml | 1 + src/heroic/heroic_platform.rs | 15 ++++-- src/heroic/settings.rs | 1 + src/ui/ui_settings.rs | 95 ++++++++++++++++++++--------------- 4 files changed, 66 insertions(+), 46 deletions(-) diff --git a/src/defaultconfig.toml b/src/defaultconfig.toml index 0c2c976..76d4ce9 100644 --- a/src/defaultconfig.toml +++ b/src/defaultconfig.toml @@ -39,6 +39,7 @@ flatpak = false [heroic] enabled = true launch_games_through_heroic =[] +default_launch_through_heroic = true [amazon] enabled = true diff --git a/src/heroic/heroic_platform.rs b/src/heroic/heroic_platform.rs index 86332eb..10d6446 100644 --- a/src/heroic/heroic_platform.rs +++ b/src/heroic/heroic_platform.rs @@ -138,17 +138,22 @@ impl HeroicPlatform { if let Some(shortcuts) = shortcuts.as_mut() { for shortcut in shortcuts { shortcut.install_mode = Some(install_mode.clone()); - if self + + let game_in_list = self .settings .launch_games_through_heroic .contains(&shortcut.app_name) || self .settings .launch_games_through_heroic - .contains(&shortcut.title) - { - shortcut.launch_through_heroic = true; - } + .contains(&shortcut.title); + + shortcut.launch_through_heroic = + if self.settings.default_launch_through_heroic { + !game_in_list + } else { + game_in_list + }; } } shortcuts diff --git a/src/heroic/settings.rs b/src/heroic/settings.rs index 3f61d71..f5e290e 100644 --- a/src/heroic/settings.rs +++ b/src/heroic/settings.rs @@ -4,4 +4,5 @@ use serde::{Deserialize, Serialize}; pub struct HeroicSettings { pub enabled: bool, pub launch_games_through_heroic: Vec, + pub default_launch_through_heroic: bool, } diff --git a/src/ui/ui_settings.rs b/src/ui/ui_settings.rs index 3ed47e9..5434cf6 100644 --- a/src/ui/ui_settings.rs +++ b/src/ui/ui_settings.rs @@ -36,47 +36,7 @@ impl MyEguiApp { #[cfg(target_family = "unix")] { - ui.heading("Heroic"); - ui.checkbox(&mut self.settings.heroic.enabled, "Import from Heroic"); - - - let safe_mode_header = match self.settings.heroic.launch_games_through_heroic.len() { - 0 => "Force games to launch through Heroic Launcher".to_string(), - 1 => "One game forced to launch through Heroic Launcher".to_string(), - x => format!("{} games forced to launch through Heroic Launcher", x), - }; - - egui::CollapsingHeader::new(safe_mode_header) - .id_source("Heroic_Launcher_safe_launch") - .show(ui, |ui| { - ui.label("Some games must be started from the Heroic Launcher, select those games below and BoilR will create shortcuts that opens the games through the Heroic Launcher."); - let manifests =self.heroic_games.get_or_insert_with(||{ - let heroic_setting = self.settings.heroic.clone(); - - let install_modes = vec![crate::heroic::InstallationMode::FlatPak, crate::heroic::InstallationMode::UserBin]; - let heroic_platform =HeroicPlatform{ - settings:heroic_setting - }; - let heroic_games = heroic_platform.get_heroic_games(&install_modes); - heroic_games - }); - - let safe_open_games = &mut self.settings.heroic.launch_games_through_heroic; - for manifest in manifests{ - let key = &manifest.app_name; - let display_name = &manifest.title; - let mut safe_open = safe_open_games.contains(display_name) || safe_open_games.contains(key); - if ui.checkbox(&mut safe_open, display_name).clicked(){ - if safe_open{ - safe_open_games.push(key.clone()); - }else{ - safe_open_games.retain(|m| m!= display_name && m!= key); - } - } - } - }) ; - - ui.add_space(SECTION_SPACING); + self.render_heroic_settings(ui); } self.render_legendary_settings(ui); @@ -94,6 +54,59 @@ impl MyEguiApp { }); } + fn render_heroic_settings(&mut self, ui: &mut egui::Ui) { + ui.heading("Heroic"); + ui.checkbox(&mut self.settings.heroic.enabled, "Import from Heroic"); + ui.checkbox(&mut self.settings.heroic.default_launch_through_heroic, "Always launch games through Heroic"); + let safe_mode_header = match (self.settings.heroic.default_launch_through_heroic,self.settings.heroic.launch_games_through_heroic.len()) { + (false,0) => "Force games to launch through Heroic Launcher".to_string(), + (false,1) => "One game forced to launch through Heroic Launcher".to_string(), + (false,x) => format!("{} games forced to launch through Heroic Launcher", x), + + (true,0) => "Force games to launch directly".to_string(), + (true,1) => "One game forced to launch directly".to_string(), + (true,x) => format!("{} games forced to launch directly", x), + + }; + egui::CollapsingHeader::new(safe_mode_header) + .id_source("Heroic_Launcher_safe_launch") + .show(ui, |ui| { +if +self.settings.heroic.default_launch_through_heroic{ + ui.label("Some games work best when launched directly, select those games below and BoilR will create shortcuts that launch the games directly."); + + } else{ + ui.label("Some games must be started from the Heroic Launcher, select those games below and BoilR will create shortcuts that opens the games through the Heroic Launcher."); + + } + let manifests =self.heroic_games.get_or_insert_with(||{ + let heroic_setting = self.settings.heroic.clone(); + + let install_modes = vec![crate::heroic::InstallationMode::FlatPak, crate::heroic::InstallationMode::UserBin]; + let heroic_platform =HeroicPlatform{ + settings:heroic_setting + }; + let heroic_games = heroic_platform.get_heroic_games(&install_modes); + heroic_games + }); + + let safe_open_games = &mut self.settings.heroic.launch_games_through_heroic; + for manifest in manifests{ + let key = &manifest.app_name; + let display_name = &manifest.title; + let mut safe_open = safe_open_games.contains(display_name) || safe_open_games.contains(key); + if ui.checkbox(&mut safe_open, display_name).clicked(){ + if safe_open{ + safe_open_games.push(key.clone()); + }else{ + safe_open_games.retain(|m| m!= display_name && m!= key); + } + } + } + }) ; + ui.add_space(SECTION_SPACING); + } + fn render_lutris_settings(&mut self, ui: &mut egui::Ui) { ui.heading("Lutris"); ui.checkbox(&mut self.settings.lutris.enabled, "Import from Lutris");