mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 14:03:42 +02:00
Unblock UI when finding shortcuts
This commit is contained in:
+66
-26
@@ -9,6 +9,7 @@ use crate::{settings::Settings, sync::{download_images, self, SyncProgress}};
|
|||||||
|
|
||||||
use super::{ui_images::{get_import_image, get_logo, get_logo_icon}, ui_colors::{TEXT_COLOR, BACKGROUND_COLOR, BG_STROKE_COLOR, ORANGE, PURLPLE, LIGHT_ORANGE, EXTRA_BACKGROUND_COLOR}};
|
use super::{ui_images::{get_import_image, get_logo, get_logo_icon}, ui_colors::{TEXT_COLOR, BACKGROUND_COLOR, BG_STROKE_COLOR, ORANGE, PURLPLE, LIGHT_ORANGE, EXTRA_BACKGROUND_COLOR}};
|
||||||
|
|
||||||
|
const SECTION_SPACING : f32 = 25.0;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct UiImages{
|
struct UiImages{
|
||||||
@@ -17,12 +18,36 @@ struct UiImages{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
enum FetchGameStatus{
|
||||||
|
NeedsFetched,
|
||||||
|
Fetching,
|
||||||
|
Fetched(Vec<(String, Vec<ShortcutOwned>)>)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FetchGameStatus{
|
||||||
|
pub fn is_some(&self) -> bool{
|
||||||
|
match self{
|
||||||
|
FetchGameStatus::NeedsFetched => false,
|
||||||
|
FetchGameStatus::Fetching => false,
|
||||||
|
FetchGameStatus::Fetched(_) => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn needs_fetching(&self) -> bool{
|
||||||
|
match self{
|
||||||
|
FetchGameStatus::NeedsFetched => true,
|
||||||
|
FetchGameStatus::Fetching => false,
|
||||||
|
FetchGameStatus::Fetched(_) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct MyEguiApp {
|
struct MyEguiApp {
|
||||||
selected_menu: Menues,
|
selected_menu: Menues,
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
rt: Runtime,
|
rt: Runtime,
|
||||||
ui_images: UiImages,
|
ui_images: UiImages,
|
||||||
games_to_sync:Option<Vec<(String, Vec<ShortcutOwned>)>>,
|
games_to_sync: Receiver<FetchGameStatus>,
|
||||||
status_reciever: Receiver<SyncProgress>,
|
status_reciever: Receiver<SyncProgress>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +60,7 @@ impl MyEguiApp {
|
|||||||
selected_menu: Menues::Import,
|
selected_menu: Menues::Import,
|
||||||
settings: Settings::new().expect("We must be able to load our settings"),
|
settings: Settings::new().expect("We must be able to load our settings"),
|
||||||
rt: runtime,
|
rt: runtime,
|
||||||
games_to_sync:None,
|
games_to_sync:watch::channel(FetchGameStatus::NeedsFetched).1,
|
||||||
ui_images: UiImages::default(),
|
ui_images: UiImages::default(),
|
||||||
status_reciever: watch::channel(SyncProgress::NotStarted).1,
|
status_reciever: watch::channel(SyncProgress::NotStarted).1,
|
||||||
}
|
}
|
||||||
@@ -51,7 +76,6 @@ impl MyEguiApp {
|
|||||||
self.rt.spawn_blocking(move || {
|
self.rt.spawn_blocking(move || {
|
||||||
|
|
||||||
MyEguiApp::save_settings_to_file(&settings);
|
MyEguiApp::save_settings_to_file(&settings);
|
||||||
//TODO get status back to ui
|
|
||||||
let mut some_sender =Some(sender);
|
let mut some_sender =Some(sender);
|
||||||
let usersinfo = sync::run_sync(&settings,&mut some_sender).unwrap();
|
let usersinfo = sync::run_sync(&settings,&mut some_sender).unwrap();
|
||||||
let task = download_images(&settings, &usersinfo,&mut some_sender);
|
let task = download_images(&settings, &usersinfo,&mut some_sender);
|
||||||
@@ -109,11 +133,15 @@ impl epi::App for MyEguiApp {
|
|||||||
let texture = self.get_logo_image(ui);
|
let texture = self.get_logo_image(ui);
|
||||||
let size = texture.size_vec2();
|
let size = texture.size_vec2();
|
||||||
ui.image(texture, size);
|
ui.image(texture, size);
|
||||||
ui.separator();
|
ui.add_space(SECTION_SPACING);
|
||||||
ui.selectable_value(&mut self.selected_menu, Menues::Import, "Import Games");
|
let changed = ui.selectable_value(&mut self.selected_menu, Menues::Import, "Import Games").changed();
|
||||||
ui.selectable_value(&mut self.selected_menu, Menues::Settings, "Settings");
|
let changed = changed || ui.selectable_value(&mut self.selected_menu, Menues::Settings, "Settings").changed();
|
||||||
|
if changed{
|
||||||
|
self.games_to_sync =watch::channel(FetchGameStatus::NeedsFetched).1;
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
if self.games_to_sync.is_some(){
|
if self.games_to_sync.borrow().is_some(){
|
||||||
|
|
||||||
egui::TopBottomPanel::new(egui::panel::TopBottomSide::Bottom, "Bottom Panel")
|
egui::TopBottomPanel::new(egui::panel::TopBottomSide::Bottom, "Bottom Panel")
|
||||||
.show(ctx,|ui|{
|
.show(ctx,|ui|{
|
||||||
@@ -150,10 +178,6 @@ impl epi::App for MyEguiApp {
|
|||||||
|
|
||||||
egui::CentralPanel::default()
|
egui::CentralPanel::default()
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
if let Menues::Import = self.selected_menu{
|
|
||||||
}else{
|
|
||||||
self.games_to_sync = None;
|
|
||||||
}
|
|
||||||
match self.selected_menu {
|
match self.selected_menu {
|
||||||
Menues::Import => {
|
Menues::Import => {
|
||||||
self.render_import_games(ui);
|
self.render_import_games(ui);
|
||||||
@@ -237,7 +261,7 @@ impl MyEguiApp{
|
|||||||
});
|
});
|
||||||
ui.checkbox(&mut self.settings.steamgrid_db.prefer_animated, "Prefer animated images").on_hover_text("Prefer downloading animated images over static images (this can slow Steam down but looks neat)");
|
ui.checkbox(&mut self.settings.steamgrid_db.prefer_animated, "Prefer animated images").on_hover_text("Prefer downloading animated images over static images (this can slow Steam down but looks neat)");
|
||||||
|
|
||||||
ui.separator();
|
ui.add_space(SECTION_SPACING);
|
||||||
|
|
||||||
ui.heading("Steam");
|
ui.heading("Steam");
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
@@ -253,7 +277,7 @@ impl MyEguiApp{
|
|||||||
ui.checkbox(&mut self.settings.steam.stop_steam, "Stop Steam before import").on_hover_text("Stops Steam if it is running when import starts");
|
ui.checkbox(&mut self.settings.steam.stop_steam, "Stop Steam before import").on_hover_text("Stops Steam if it is running when import starts");
|
||||||
ui.checkbox(&mut self.settings.steam.start_steam, "Start Steam after import").on_hover_text("Starts Steam is it is not running after the import");
|
ui.checkbox(&mut self.settings.steam.start_steam, "Start Steam after import").on_hover_text("Starts Steam is it is not running after the import");
|
||||||
|
|
||||||
ui.separator();
|
ui.add_space(SECTION_SPACING);
|
||||||
|
|
||||||
ui.heading("Epic Games");
|
ui.heading("Epic Games");
|
||||||
ui.checkbox(&mut self.settings.epic_games.enabled, "Import form Epic Games");
|
ui.checkbox(&mut self.settings.epic_games.enabled, "Import form Epic Games");
|
||||||
@@ -266,14 +290,14 @@ impl MyEguiApp{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.separator();
|
ui.add_space(SECTION_SPACING);
|
||||||
|
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
{
|
{
|
||||||
ui.heading("Heroic");
|
ui.heading("Heroic");
|
||||||
ui.checkbox(&mut self.settings.heroic.enabled, "Import form Heroic");
|
ui.checkbox(&mut self.settings.heroic.enabled, "Import form Heroic");
|
||||||
|
|
||||||
ui.separator();
|
ui.add_space(SECTION_SPACING);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.heading("Legendary & Rare");
|
ui.heading("Legendary & Rare");
|
||||||
@@ -287,7 +311,7 @@ impl MyEguiApp{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.separator();
|
ui.add_space(SECTION_SPACING);
|
||||||
|
|
||||||
ui.heading("Itch.io");
|
ui.heading("Itch.io");
|
||||||
ui.checkbox(&mut self.settings.itch.enabled, "Import form Itch.io");
|
ui.checkbox(&mut self.settings.itch.enabled, "Import form Itch.io");
|
||||||
@@ -300,12 +324,12 @@ impl MyEguiApp{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.separator();
|
ui.add_space(SECTION_SPACING);
|
||||||
|
|
||||||
ui.heading("Origin");
|
ui.heading("Origin");
|
||||||
ui.checkbox(&mut self.settings.origin.enabled, "Import from Origin");
|
ui.checkbox(&mut self.settings.origin.enabled, "Import from Origin");
|
||||||
|
|
||||||
ui.separator();
|
ui.add_space(SECTION_SPACING);
|
||||||
|
|
||||||
ui.heading("GoG Galaxy");
|
ui.heading("GoG Galaxy");
|
||||||
ui.checkbox(&mut self.settings.gog.enabled, "Import form GoG Galaxy");
|
ui.checkbox(&mut self.settings.gog.enabled, "Import form GoG Galaxy");
|
||||||
@@ -318,12 +342,12 @@ impl MyEguiApp{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.separator();
|
ui.add_space(SECTION_SPACING);
|
||||||
|
|
||||||
ui.heading("Uplay");
|
ui.heading("Uplay");
|
||||||
ui.checkbox(&mut self.settings.uplay.enabled, "Import form Uplay");
|
ui.checkbox(&mut self.settings.uplay.enabled, "Import form Uplay");
|
||||||
|
|
||||||
ui.separator();
|
ui.add_space(SECTION_SPACING);
|
||||||
|
|
||||||
ui.heading("Lutris");
|
ui.heading("Lutris");
|
||||||
ui.checkbox(&mut self.settings.lutris.enabled, "Import form Uplay");
|
ui.checkbox(&mut self.settings.lutris.enabled, "Import form Uplay");
|
||||||
@@ -340,11 +364,25 @@ impl MyEguiApp{
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render_import_games(&mut self, ui: &mut egui::Ui){
|
fn render_import_games(&mut self, ui: &mut egui::Ui){
|
||||||
|
|
||||||
ui.heading("Import Games");
|
ui.heading("Import Games");
|
||||||
ui.label("Select the games you want to import into steam");
|
|
||||||
|
if self.games_to_sync.borrow().needs_fetching(){
|
||||||
|
let (tx, rx) = watch::channel(FetchGameStatus::NeedsFetched);
|
||||||
|
self.games_to_sync = rx;
|
||||||
|
let settings = self.settings.clone();
|
||||||
|
self.rt.spawn_blocking(move || {
|
||||||
|
let _= tx.send(FetchGameStatus::Fetching);
|
||||||
|
let games_to_sync = sync::get_platform_shortcuts(&settings);
|
||||||
|
let _= tx.send(FetchGameStatus::Fetched(games_to_sync));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ScrollArea::vertical().show(ui,|ui| {
|
ScrollArea::vertical().show(ui,|ui| {
|
||||||
match &self.games_to_sync{
|
let borrowed_games = &*self.games_to_sync.borrow();
|
||||||
Some(games_to_sync) => {
|
match borrowed_games{
|
||||||
|
FetchGameStatus::Fetched(games_to_sync) => {
|
||||||
|
ui.label("Select the games you want to import into steam");
|
||||||
for (platform_name, shortcuts) in games_to_sync{
|
for (platform_name, shortcuts) in games_to_sync{
|
||||||
ui.heading(platform_name);
|
ui.heading(platform_name);
|
||||||
for shortcut in shortcuts {
|
for shortcut in shortcuts {
|
||||||
@@ -360,12 +398,14 @@ impl MyEguiApp{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ui.add_space(SECTION_SPACING);
|
||||||
|
ui.label("Check the settings if BoilR didn't find the game you where looking for");
|
||||||
},
|
},
|
||||||
None => {
|
_=> {
|
||||||
self.games_to_sync = Some(sync::get_platform_shortcuts(&self.settings));
|
ui.label("Finding installed games");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
ui.label("Check the settings if BoilR didn't find the game you where looking for");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user