Modular platforms (#241)

This commit is contained in:
Philip Kristoffersen
2022-10-02 21:13:31 +02:00
committed by GitHub
parent d6773c7adb
commit dcbf77b610
94 changed files with 2188 additions and 1750 deletions
+14 -14
View File
@@ -43,8 +43,12 @@ pub mod ui_images {
}
}
pub fn load_image_from_path(path: &std::path::Path) -> Result<egui::ColorImage, image::ImageError> {
let image = image::io::Reader::open(path)?.with_guessed_format()?.decode()?;
pub fn load_image_from_path(
path: &std::path::Path,
) -> Result<egui::ColorImage, image::ImageError> {
let image = image::io::Reader::open(path)?
.with_guessed_format()?
.decode()?;
let size = [image.width() as _, image.height() as _];
let image_buffer = image.to_rgba8();
let pixels = image_buffer.as_flat_samples();
@@ -53,18 +57,14 @@ pub mod ui_images {
pixels.as_slice(),
))
}
pub fn load_image_from_memory(image_data: &[u8]) -> Result<ColorImage, image::ImageError> {
pub fn load_image_from_memory(image_data: &[u8]) -> Result<ColorImage, image::ImageError> {
let image = image::load_from_memory(image_data)?;
let size = [image.width() as _, image.height() as _];
let image_buffer = image.to_rgba8();
let pixels = image_buffer.as_flat_samples();
Ok(ColorImage::from_rgba_unmultiplied(
size,
pixels.as_slice(),
))
Ok(ColorImage::from_rgba_unmultiplied(size, pixels.as_slice()))
}
}
#[cfg(test)]
@@ -95,9 +95,9 @@ mod tests {
assert!(res.is_err());
}
#[test]
pub fn test_image_load_animated_webp2() {
let res = load_image_from_path(std::path::Path::new("src/testdata/tunic.webp"));
assert!(res.is_err());
}
// #[test]
// pub fn test_image_load_animated_webp2() {
// let res = load_image_from_path(std::path::Path::new("src/testdata/tunic.webp"));
// assert!(res.is_err());
// }
}
+2 -7
View File
@@ -57,13 +57,8 @@ impl MyEguiApp {
ui.heading(&user.path.to_string_lossy().to_string());
}
for shortcut in user.shortcuts.iter() {
if shortcut.is_boilr_shortcut()
&& ui.button(&shortcut.app_name).clicked()
{
if disconnect_shortcut(&self.settings, shortcut.app_id).is_ok()
{
redraw = shortcut.app_id;
}
if shortcut.is_boilr_shortcut() && ui.button(&shortcut.app_name).clicked() && disconnect_shortcut(&self.settings, shortcut.app_id).is_ok() {
redraw = shortcut.app_id;
}
}
}
-1
View File
@@ -353,7 +353,6 @@ impl MyEguiApp {
}
pub(crate) fn render_ui_images(&mut self, ui: &mut egui::Ui) {
self.ensure_games_loaded();
self.ensure_steam_users_loaded();
if let Some(error_message) = &self.image_selected_state.settings_error {
+135 -103
View File
@@ -2,15 +2,18 @@ use eframe::egui;
use egui::ScrollArea;
use futures::executor::block_on;
use steam_shortcuts_util::shortcut::ShortcutOwned;
use tokio::sync::watch;
use crate::config::get_renames_file;
use crate::settings::Settings;
use crate::platforms::ShortcutToImport;
#[cfg(target_family = "unix")]
use crate::steam::setup_proton_games;
use crate::sync;
use crate::sync::{download_images, SyncProgress};
use super::{backup_shortcuts, ImageSelectState};
use super::{backup_shortcuts, all_ready, get_all_games};
use super::{
ui_colors::{BACKGROUND_COLOR, EXTRA_BACKGROUND_COLOR},
MyEguiApp,
@@ -32,22 +35,12 @@ impl<T> FetcStatus<T> {
FetcStatus::Fetched(_) => true,
}
}
pub fn needs_fetching(&self) -> bool {
match self {
FetcStatus::NeedsFetched => true,
FetcStatus::Fetching => false,
FetcStatus::Fetched(_) => false,
}
}
}
impl MyEguiApp {
pub(crate) fn render_import_games(&mut self, ui: &mut egui::Ui) {
ui.heading("Import Games");
self.ensure_games_loaded();
let mut scroll_style = ui.style_mut();
scroll_style.visuals.extreme_bg_color = BACKGROUND_COLOR;
scroll_style.visuals.widgets.inactive.bg_fill = EXTRA_BACKGROUND_COLOR;
@@ -60,83 +53,79 @@ impl MyEguiApp {
.auto_shrink([false,true])
.show(ui,|ui| {
ui.reset_style();
let borrowed_games = &*self.games_to_sync.borrow();
match borrowed_games{
FetcStatus::Fetched(games_to_sync) => {
ui.label("Select the games you want to import into steam");
for (platform_name, shortcuts) in games_to_sync{
ui.heading(platform_name);
for shortcut in shortcuts {
let mut import_game = !self.settings.blacklisted_games.contains(&shortcut.app_id);
ui.horizontal(|ui|{
if self.current_edit == Option::Some(shortcut.app_id){
if let Some(new_name) = self.rename_map.get_mut(&shortcut.app_id){
ui.text_edit_singleline(new_name).request_focus();
if ui.button("Rename").clicked() {
if new_name.is_empty(){
*new_name = shortcut.app_name.to_string();
ui.label("Select the games you want to import into steam");
for (name,status) in &self.games_to_sync{
ui.heading(name);
match &*status.borrow(){
FetcStatus::NeedsFetched => {ui.label("Need to find games");},
FetcStatus::Fetching => {
ui.horizontal(|ui|{
ui.spinner();
ui.label("Finding installed games");
});
},
FetcStatus::Fetched(shortcuts) => {
match shortcuts{
Ok(shortcuts) => {
if shortcuts.is_empty(){
ui.label("Did not find any games");
}
for shortcut_to_import in shortcuts {
let shortcut = &shortcut_to_import.shortcut;
let mut import_game = !self.settings.blacklisted_games.contains(&shortcut.app_id);
ui.horizontal(|ui|{
if self.current_edit == Option::Some(shortcut.app_id){
if let Some(new_name) = self.rename_map.get_mut(&shortcut.app_id){
ui.text_edit_singleline(new_name).request_focus();
if ui.button("Rename").clicked() {
if new_name.is_empty(){
*new_name = shortcut.app_name.to_string();
}
self.current_edit = Option::None;
let rename_file_path = get_renames_file();
let contents = serde_json::to_string(&self.rename_map);
if let Ok(contents) = contents{
let res = std::fs::write(&rename_file_path, contents);
println!("Write rename file at {:?} with result: {:?}",rename_file_path, res);
}
}
}
self.current_edit = Option::None;
let rename_file_path = get_renames_file();
let contents = serde_json::to_string(&self.rename_map);
if let Ok(contents) = contents{
let res = std::fs::write(&rename_file_path, contents);
println!("Write rename file at {:?} with result: {:?}",rename_file_path, res);
} else {
let name = self.rename_map.get(&shortcut.app_id).unwrap_or(&shortcut.app_name);
let checkbox = egui::Checkbox::new(&mut import_game,name);
let response = ui.add(checkbox);
if response.double_clicked(){
self.rename_map.entry(shortcut.app_id).or_insert_with(|| shortcut.app_name.to_owned());
self.current_edit = Option::Some(shortcut.app_id);
}
if response.clicked(){
if !self.settings.blacklisted_games.contains(&shortcut.app_id){
self.settings.blacklisted_games.push(shortcut.app_id);
}else{
self.settings.blacklisted_games.retain(|id| *id != shortcut.app_id);
}
}
}
} else {
let name = self.rename_map.get(&shortcut.app_id).unwrap_or(&shortcut.app_name);
let checkbox = egui::Checkbox::new(&mut import_game,name);
let response = ui.add(checkbox);
if response.double_clicked(){
if !self.rename_map.contains_key(&shortcut.app_id){
self.rename_map.insert(shortcut.app_id,shortcut.app_name.to_owned());
}
self.current_edit = Option::Some(shortcut.app_id);
}
});
}
if response.clicked(){
if !self.settings.blacklisted_games.contains(&shortcut.app_id){
self.settings.blacklisted_games.push(shortcut.app_id);
}else{
self.settings.blacklisted_games.retain(|id| *id != shortcut.app_id);
}
}
}
});
}
}
ui.add_space(SECTION_SPACING);
ui.label("Check the settings if BoilR didn't find the game you where looking for");
},
_=> {
ui.ctx().request_repaint();
ui.horizontal(|ui|{
ui.spinner();
ui.label("Finding installed games");
});
},
},
Err(err) => {
ui.label("Failed finding games").on_hover_text(format!("Error message: {err}"));
},
};
},
}
};
ui.add_space(SECTION_SPACING);
ui.label("Check the settings if BoilR didn't find the game you where looking for");
});
}
pub fn ensure_games_loaded(&mut self) {
if self.games_to_sync.borrow().needs_fetching() {
self.image_selected_state = ImageSelectState::default();
let (tx, rx) = watch::channel(FetcStatus::NeedsFetched);
self.games_to_sync = rx;
let settings = self.settings.clone();
self.rt.spawn_blocking(move || {
let _ = tx.send(FetcStatus::Fetching);
let games_to_sync = sync::get_platform_shortcuts(&settings);
let _ = tx.send(FetcStatus::Fetched(games_to_sync));
});
}
}
pub fn run_sync(&mut self, wait: bool ) {
let (sender, reciever) = watch::channel(SyncProgress::NotStarted);
let settings = self.settings.clone();
@@ -144,34 +133,77 @@ impl MyEguiApp {
crate::steam::ensure_steam_stopped();
}
//TODO This might break cli sync, test it
self.status_reciever = reciever;
let renames = self.rename_map.clone();
let handle = self.rt.spawn_blocking(move || {
MyEguiApp::save_settings_to_file(&settings);
let mut some_sender = Some(sender);
backup_shortcuts(&settings.steam);
let usersinfo = sync::run_sync(&settings, &mut some_sender,&renames).unwrap();
let task = download_images(&settings, &usersinfo, &mut some_sender);
block_on(task);
let all_ready= all_ready(&self.games_to_sync);
let _ = sender.send(SyncProgress::Starting);
if all_ready{
let shortcuts_to_import = get_all_games(&self.games_to_sync);
let handle = self.rt.spawn_blocking(move || {
//Run a second time to fix up shortcuts after images are downloaded
sync::run_sync(&settings, &mut some_sender,&renames).unwrap();
#[cfg(target_family = "unix")]
setup_proton(shortcuts_to_import.iter());
if let Some(sender) = some_sender {
let _ = sender.send(SyncProgress::Done);
let import_games = to_shortcut_owned(shortcuts_to_import);
let mut some_sender = Some(sender);
backup_shortcuts(&settings.steam);
let usersinfo = sync::sync_shortcuts(&settings, &import_games, &mut some_sender,&renames).unwrap();
let task = download_images(&settings, &usersinfo, &mut some_sender);
block_on(task);
//Run a second time to fix up shortcuts after images are downloaded
sync::sync_shortcuts(&settings, &import_games, &mut some_sender,&renames).unwrap();
if let Some(sender) = some_sender {
let _ = sender.send(SyncProgress::Done);
}
if settings.steam.start_steam {
crate::steam::ensure_steam_started(&settings.steam);
}
});
if wait {
self.rt.block_on(handle).unwrap();
}
if settings.steam.start_steam {
crate::steam::ensure_steam_started(&settings.steam);
}
});
if wait {
self.rt.block_on(handle).unwrap();
}
}
pub fn save_settings_to_file(settings: &Settings) {
let toml = toml::to_string(&settings).unwrap();
let config_path = crate::config::get_config_file();
std::fs::write(config_path, toml).unwrap();
}
}
fn to_shortcut_owned(shortcuts_to_import: Vec<(String, Vec<ShortcutToImport>)>) -> Vec<(String, Vec<ShortcutOwned>)> {
let mut import_games = vec![];
for(name,infos) in shortcuts_to_import{
let mut shortcuts = vec![];
for info in infos{
shortcuts.push(info.shortcut);
}
import_games.push((name,shortcuts));
}
import_games
}
#[cfg(target_family = "unix")]
fn setup_proton<'a, I>(shortcut_infos: I)
where I: IntoIterator<Item = &'a (String,Vec<ShortcutToImport>)>
{
let mut shortcuts_to_proton = vec![];
for (name,shortcuts) in shortcut_infos {
for shortcut_info in shortcuts{
if shortcut_info.needs_proton {
crate::sync::symlinks::ensure_links_folder_created(&name);
}
if shortcut_info.needs_proton {
shortcuts_to_proton.push(format!("{}", shortcut_info.shortcut.app_id));
}
if shortcut_info.needs_symlinks {
crate::sync::symlinks::create_sym_links(&shortcut_info.shortcut);
}
}
setup_proton_games(&shortcuts_to_proton);
}
}
+4 -263
View File
@@ -2,10 +2,6 @@ use copypasta::ClipboardProvider;
use eframe::egui;
use egui::ScrollArea;
use crate::{egs::EpicPlatform};
#[cfg(target_family = "unix")]
use crate::heroic::HeroicPlatform;
use super::{
ui_colors::{BACKGROUND_COLOR, EXTRA_BACKGROUND_COLOR},
MyEguiApp,
@@ -34,206 +30,15 @@ impl MyEguiApp {
self.render_steam_settings(ui);
self.render_epic_settings(ui);
#[cfg(target_family = "unix")]
{
self.render_heroic_settings(ui);
self.render_bottles_settings(ui);
for platform in &mut self.platforms{
platform.render_ui(ui);
ui.add_space(SECTION_SPACING);
}
self.render_legendary_settings(ui);
self.render_itch_settings(ui);
self.render_origin_settings(ui);
self.render_gog_settings(ui);
self.render_uplay_settings(ui);
self.render_lutris_settings(ui);
#[cfg(windows)]
{
self.render_amazon_settings(ui);
}
#[cfg(target_family = "unix")]
{
self.render_flatpak_settings(ui);
}
ui.add_space(SECTION_SPACING);
ui.label(format!("Version: {}", VERSION));
});
}
#[cfg(target_family = "unix")]
fn render_flatpak_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("Flatpak");
ui.checkbox(&mut self.settings.flatpak.enabled, "Import from Flatpak");
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");
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.");
}
#[cfg(target_family = "unix")]{
let manifests =self.heroic_games.get_or_insert_with(||{
let heroic_setting = self.settings.heroic.clone();
let heroic_platform =HeroicPlatform{
settings:heroic_setting
};
heroic_platform.get_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.to_string()) || safe_open_games.contains(&key.to_string());
if ui.checkbox(&mut safe_open, display_name).clicked(){
if safe_open{
safe_open_games.push(key.to_string());
}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");
if self.settings.lutris.enabled {
ui.checkbox(&mut self.settings.lutris.flatpak, "Flatpak version");
if !self.settings.lutris.flatpak {
ui.horizontal(|ui| {
let lutris_location = &mut self.settings.lutris.executable;
ui.label("Lutris Location: ");
ui.text_edit_singleline(lutris_location);
});
} else {
ui.horizontal(|ui| {
let flatpak_image = &mut self.settings.lutris.flatpak_image;
ui.label("Flatpak image");
ui.text_edit_singleline(flatpak_image);
});
}
}
ui.add_space(SECTION_SPACING);
}
#[cfg(windows)]
fn render_amazon_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("Amazon");
ui.checkbox(&mut self.settings.amazon.enabled, "Import from Amazon");
ui.add_space(SECTION_SPACING);
}
fn render_uplay_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("Uplay");
ui.checkbox(&mut self.settings.uplay.enabled, "Import from Uplay");
ui.add_space(SECTION_SPACING);
}
fn render_gog_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("GoG Galaxy");
ui.checkbox(&mut self.settings.gog.enabled, "Import from GoG Galaxy");
if self.settings.gog.enabled {
ui.horizontal(|ui| {
let mut empty_string = "".to_string();
let itch_location = self
.settings
.gog
.location
.as_mut()
.unwrap_or(&mut empty_string);
ui.label("GoG Galaxy Folder: ");
if ui.text_edit_singleline(itch_location).changed() {
self.settings.gog.location = Some(itch_location.to_string());
}
});
}
ui.add_space(SECTION_SPACING);
}
fn render_origin_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("Origin");
ui.checkbox(&mut self.settings.origin.enabled, "Import from Origin");
ui.add_space(SECTION_SPACING);
}
fn render_itch_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("Itch.io");
ui.checkbox(&mut self.settings.itch.enabled, "Import from Itch.io");
if self.settings.itch.enabled {
ui.horizontal(|ui| {
let mut empty_string = "".to_string();
let itch_location = self
.settings
.itch
.location
.as_mut()
.unwrap_or(&mut empty_string);
ui.label("Itch.io Folder: ");
if ui.text_edit_singleline(itch_location).changed() {
self.settings.itch.location = if itch_location.is_empty(){
None
}else {
Some(itch_location.to_string())
};
}else{
if !itch_location.is_empty(){
if ui.button("Reset").on_hover_text("Reset the itch path, let BoilR guess again").clicked(){
self.settings.itch.location = None;
}
}
}
});
#[cfg(target_family = "unix")]
{
ui.checkbox(&mut self.settings.itch.create_symlinks, "Create symlinks");
}
}
ui.add_space(SECTION_SPACING);
}
fn render_steam_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("Steam");
ui.horizontal(|ui| {
@@ -317,68 +122,4 @@ self.settings.heroic.default_launch_through_heroic{
}
ui.add_space(SECTION_SPACING);
}
fn render_legendary_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("Legendary & Rare");
ui.checkbox(
&mut self.settings.legendary.enabled,
"Import from Legendary & Rare",
);
if self.settings.legendary.enabled {
ui.horizontal(|ui| {
let mut empty_string = "".to_string();
let legendary_location = self
.settings
.legendary
.executable
.as_mut()
.unwrap_or(&mut empty_string);
ui.label("Legendary Executable: ")
.on_hover_text("The location of the legendary executable to use");
if ui.text_edit_singleline(legendary_location).changed() {
self.settings.legendary.executable = Some(legendary_location.to_string());
}
});
}
ui.add_space(SECTION_SPACING);
}
fn render_epic_settings(&mut self, ui: &mut egui::Ui) {
let epic_settings = &mut self.settings.epic_games;
ui.heading("Epic Games");
ui.checkbox(&mut epic_settings.enabled, "Import from Epic Games");
if epic_settings.enabled {
let safe_mode_header = match epic_settings.safe_launch.len() {
0 => "Force games to launch through Epic Launcher".to_string(),
1 => "One game forced to launch through Epic Launcher".to_string(),
x => format!("{} games forced to launch through Epic Launcher", x),
};
egui::CollapsingHeader::new(safe_mode_header)
.id_source("Epic_Launcher_safe_launch")
.show(ui, |ui| {
ui.label("Some games must be started from the Epic Launcher, select those games below and BoilR will create shortcuts that opens the games through the Epic Launcher.");
let manifests =self.epic_manifests.get_or_insert_with(||{
let epic_platform = EpicPlatform::new(epic_settings);
let manifests = crate::platform::Platform::get_shortcuts(&epic_platform);
manifests.unwrap_or_default()
});
let mut safe_open_games = epic_settings.safe_launch.clone();
for manifest in manifests{
let key = manifest.get_key();
let display_name = &manifest.display_name;
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);
}else{
safe_open_games.retain(|m| m!= display_name && m!= &key);
}
}
}
epic_settings.safe_launch = safe_open_games;
}) ;
ui.add_space(SECTION_SPACING);
}
}
}
+79 -30
View File
@@ -1,17 +1,18 @@
use std::{collections::HashMap, error::Error};
#[cfg(target_family = "unix")]
use crate::heroic::HeroicGameType;
use std::{collections::HashMap, error::Error, time::Duration};
use eframe::{egui, App, Frame};
use egui::{ImageButton, Rounding, Stroke, TextureHandle};
use steam_shortcuts_util::shortcut::ShortcutOwned;
use tokio::{
runtime::Runtime,
sync::watch::{self, Receiver},
};
use crate::{egs::ManifestItem, settings::Settings, sync::SyncProgress, config::get_renames_file};
use crate::{
config::get_renames_file,
platforms::{get_platforms, GamesPlatform, Platforms, ShortcutToImport},
settings::{save_settings, Settings},
sync::{self, SyncProgress},
};
use super::{
ui_colors::{
@@ -31,58 +32,78 @@ struct UiImages {
save_button: Option<egui::TextureHandle>,
logo_32: Option<egui::TextureHandle>,
}
type GamesToSync = Vec<(
String,
Receiver<FetcStatus<eyre::Result<Vec<ShortcutToImport>>>>,
)>;
pub(crate) fn all_ready(games: &GamesToSync) -> bool {
games.iter().all(|(_name, rx)| rx.borrow().is_some())
}
pub(crate) fn get_all_games(games: &GamesToSync) -> Vec<(String, Vec<ShortcutToImport>)> {
games
.iter()
.filter_map(|(name, rx)| {
if let FetcStatus::Fetched(Ok(data)) = &*rx.borrow() {
Some((name.to_owned(), data.to_owned()))
} else {
None
}
})
.collect()
}
pub struct MyEguiApp {
selected_menu: Menues,
pub(crate) settings: Settings,
pub(crate) rt: Runtime,
ui_images: UiImages,
pub(crate) games_to_sync: Receiver<FetcStatus<Vec<(String, Vec<ShortcutOwned>)>>>,
pub(crate) games_to_sync: GamesToSync,
pub(crate) status_reciever: Receiver<SyncProgress>,
pub(crate) epic_manifests: Option<Vec<ManifestItem>>,
#[cfg(target_family = "unix")]
pub(crate) heroic_games: Option<Vec<HeroicGameType>>,
pub(crate) image_selected_state: ImageSelectState,
pub(crate) backup_state: BackupState,
pub(crate) disconect_state: DiconnectState,
pub(crate) rename_map : HashMap<u32,String>,
pub(crate) current_edit : Option<u32>,
pub(crate) rename_map: HashMap<u32, String>,
pub(crate) current_edit: Option<u32>,
pub(crate) platforms: Platforms,
}
impl MyEguiApp {
pub fn new() -> Self {
let runtime = Runtime::new().unwrap();
let mut runtime = Runtime::new().unwrap();
let settings = Settings::new().expect("We must be able to load our settings");
let platforms = get_platforms();
let games_to_sync = create_games_to_sync(&mut runtime, &platforms);
Self {
selected_menu: Menues::Import,
settings: Settings::new().expect("We must be able to load our settings"),
settings,
rt: runtime,
games_to_sync: watch::channel(FetcStatus::NeedsFetched).1,
games_to_sync,
ui_images: UiImages::default(),
status_reciever: watch::channel(SyncProgress::NotStarted).1,
epic_manifests: None,
#[cfg(target_family = "unix")]
heroic_games: None,
image_selected_state: ImageSelectState::default(),
backup_state: BackupState::default(),
disconect_state: DiconnectState::default(),
rename_map: get_rename_map(),
current_edit: Option::None
current_edit: Option::None,
platforms,
}
}
}
fn get_rename_map() -> HashMap<u32,String>{
fn get_rename_map() -> HashMap<u32, String> {
try_get_rename_map().unwrap_or_default()
}
fn try_get_rename_map() -> Result<HashMap<u32,String>,Box<dyn Error>>{
fn try_get_rename_map() -> Result<HashMap<u32, String>, Box<dyn Error>> {
let rename_map = get_renames_file();
let file_content = std::fs::read_to_string(rename_map)?;
let deserialized = serde_json::from_str(&file_content)?;
Ok(deserialized)
}
#[derive(PartialEq)]
#[derive(PartialEq, Clone)]
enum Menues {
Import,
Settings,
@@ -97,6 +118,23 @@ impl Default for Menues {
}
}
fn create_games_to_sync(rt: &mut Runtime, platforms: &[Box<dyn GamesPlatform>]) -> GamesToSync {
let mut to_sync = vec![];
for platform in platforms {
if platform.enabled() {
let (tx, rx) = watch::channel(FetcStatus::NeedsFetched);
to_sync.push((platform.name().to_string(), rx));
let platform = platform.clone();
rt.spawn_blocking(move || {
let _ = tx.send(FetcStatus::Fetching);
let games_to_sync = sync::get_platform_shortcuts(platform);
let _ = tx.send(FetcStatus::Fetched(games_to_sync));
});
}
}
to_sync
}
impl App for MyEguiApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut Frame) {
let frame = egui::Frame::default()
@@ -111,6 +149,8 @@ impl App for MyEguiApp {
ui.image(texture, size);
ui.add_space(SECTION_SPACING);
let menu_before = self.selected_menu.clone();
let mut changed = ui
.selectable_value(&mut self.selected_menu, Menues::Import, "Import Games")
.changed();
@@ -138,9 +178,12 @@ impl App for MyEguiApp {
if changed {
self.backup_state.available_backups = None;
}
if changed && self.selected_menu == Menues::Settings {
if changed
&& menu_before == Menues::Settings
&& self.selected_menu == Menues::Import
{
//We reset games here, since user might change settings
self.games_to_sync = watch::channel(FetcStatus::NeedsFetched).1;
self.games_to_sync = create_games_to_sync(&mut self.rt, &self.platforms);
}
});
@@ -153,11 +196,11 @@ impl App for MyEguiApp {
let save_button = ImageButton::new(texture, size * 0.5);
if ui.add(save_button).on_hover_text("Save settings").clicked() {
MyEguiApp::save_settings_to_file(&self.settings.clone());
save_settings(&self.settings, &self.platforms);
}
});
}
if self.games_to_sync.borrow().is_some() {
if self.selected_menu == Menues::Import {
egui::TopBottomPanel::new(egui::panel::TopBottomSide::Bottom, "Bottom Panel")
.frame(frame)
.show(ctx, |ui| {
@@ -186,14 +229,16 @@ impl App for MyEguiApp {
ui.label(&status_string);
}
}
let all_ready = all_ready(&self.games_to_sync);
let texture = self.get_import_image(ui);
let size = texture.size_vec2();
let image_button = ImageButton::new(texture, size * 0.5);
if ui
.add(image_button)
.on_hover_text("Import your games into steam")
.clicked()
if all_ready
&& ui
.add(image_button)
.on_hover_text("Import your games into steam")
.clicked()
&& !syncing
{
self.run_sync(false);
@@ -293,6 +338,10 @@ fn setup(ctx: &egui::Context) {
}
pub fn run_sync() {
let mut app = MyEguiApp::new();
while !all_ready(&app.games_to_sync) {
println!("Finding games, trying again in 500ms");
std::thread::sleep(Duration::from_secs_f32(0.5));
}
app.run_sync(true);
}