mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
UI image selection (#97)
This commit is contained in:
@@ -11,6 +11,8 @@ pub mod ui_colors {
|
||||
}
|
||||
|
||||
pub mod ui_images {
|
||||
use std::path::Path;
|
||||
|
||||
use eframe::epi::IconData;
|
||||
use egui::{ColorImage, ImageData};
|
||||
|
||||
@@ -36,6 +38,14 @@ pub mod ui_images {
|
||||
rgba: pixels.as_slice().to_vec(),
|
||||
}
|
||||
}
|
||||
pub fn load_image_from_path(path: &Path) -> Option<ColorImage> {
|
||||
if path.exists() {
|
||||
if let Ok(data) = std::fs::read(path) {
|
||||
return load_image_from_memory(&data).ok();
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn load_image_from_memory(image_data: &[u8]) -> Result<ColorImage, image::ImageError> {
|
||||
let image = image::load_from_memory(image_data)?;
|
||||
|
||||
+9
-2
@@ -1,4 +1,11 @@
|
||||
mod uiapp;
|
||||
mod defines;
|
||||
pub use uiapp::*;
|
||||
mod ui_image_download;
|
||||
mod ui_import_games;
|
||||
mod ui_settings;
|
||||
mod uiapp;
|
||||
|
||||
pub use defines::*;
|
||||
pub use ui_image_download::*;
|
||||
pub use ui_import_games::*;
|
||||
pub use ui_settings::*;
|
||||
pub use uiapp::*;
|
||||
|
||||
@@ -0,0 +1,409 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::{
|
||||
steam::{get_shortcuts_paths, SteamUsersInfo},
|
||||
steamgriddb::{CachedSearch, ImageType, get_query_type, ToDownload},
|
||||
};
|
||||
use dashmap::DashMap;
|
||||
use egui::{ImageButton, ScrollArea};
|
||||
use futures::executor::block_on;
|
||||
use steam_shortcuts_util::shortcut::ShortcutOwned;
|
||||
use tokio::sync::watch::{self, Receiver};
|
||||
|
||||
use super::{ui_images::load_image_from_path, FetcStatus, MyEguiApp};
|
||||
|
||||
pub struct ImageSelectState {
|
||||
pub selected_image: Option<ShortcutOwned>,
|
||||
pub grid_id: Option<usize>,
|
||||
|
||||
pub hero_image: Option<egui::TextureHandle>,
|
||||
pub grid_image: Option<egui::TextureHandle>,
|
||||
pub logo_image: Option<egui::TextureHandle>,
|
||||
pub icon_image: Option<egui::TextureHandle>,
|
||||
pub wide_image: Option<egui::TextureHandle>,
|
||||
|
||||
pub steam_user: Option<SteamUsersInfo>,
|
||||
pub steam_users: Option<Vec<SteamUsersInfo>>,
|
||||
|
||||
pub image_to_replace: Option<ImageType>,
|
||||
pub image_options: Receiver<FetcStatus<Vec<PossibleImage>>>,
|
||||
|
||||
pub image_handles: DashMap<String,egui::TextureHandle>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PossibleImage{
|
||||
thumbnail_path: PathBuf,
|
||||
full_url: String
|
||||
}
|
||||
|
||||
impl Default for ImageSelectState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
selected_image: Default::default(),
|
||||
grid_id: Default::default(),
|
||||
hero_image: Default::default(),
|
||||
grid_image: Default::default(),
|
||||
logo_image: Default::default(),
|
||||
icon_image: Default::default(),
|
||||
wide_image: Default::default(),
|
||||
steam_user: Default::default(),
|
||||
steam_users: Default::default(),
|
||||
image_to_replace: Default::default(),
|
||||
image_options: watch::channel(FetcStatus::NeedsFetched).1,
|
||||
image_handles: DashMap::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MyEguiApp {
|
||||
pub(crate) fn render_ui_images(&mut self, ui: &mut egui::Ui) {
|
||||
self.ensure_games_loaded();
|
||||
|
||||
ui.heading("Images");
|
||||
|
||||
match &self.image_selected_state.steam_user {
|
||||
Some(user) => {
|
||||
if self.image_selected_state.selected_image.is_some(){
|
||||
if ui.button("Back").clicked() {
|
||||
if self.image_selected_state.image_to_replace.is_some(){
|
||||
self.image_selected_state.image_to_replace = None;
|
||||
}else{
|
||||
self.image_selected_state.selected_image = None;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ScrollArea::vertical()
|
||||
.stick_to_right()
|
||||
.auto_shrink([false, true])
|
||||
.show(ui, |ui| {
|
||||
ui.reset_style();
|
||||
let borrowed_games = &*self.games_to_sync.borrow();
|
||||
match borrowed_games {
|
||||
super::FetcStatus::Fetched(games_to_sync) => {
|
||||
match &self.image_selected_state.selected_image {
|
||||
Some(selected_image) => {
|
||||
|
||||
ui.heading(&selected_image.app_name);
|
||||
let mut reset = false;
|
||||
if let Some(selected_image_type) =
|
||||
&self.image_selected_state.image_to_replace
|
||||
{
|
||||
let borrowed_images =
|
||||
&*self.image_selected_state.image_options.borrow();
|
||||
match borrowed_images {
|
||||
FetcStatus::Fetched(images) => {
|
||||
for image in images{
|
||||
let image_key = image.thumbnail_path.as_path().to_string_lossy().to_string();
|
||||
if ! self.image_selected_state.image_handles.contains_key(&image_key){
|
||||
//TODO remove this unwrap
|
||||
let image_data = load_image_from_path(&image.thumbnail_path).unwrap();
|
||||
let handle = ui.ctx().load_texture(&image_key, image_data);
|
||||
self.image_selected_state.image_handles.insert(image_key.clone(),handle);
|
||||
}
|
||||
if let Some(texture_handle) = self.image_selected_state.image_handles.get(&image_key){
|
||||
let mut size = texture_handle.size_vec2();
|
||||
clamp_to_width(&mut size,MAX_WIDTH);
|
||||
let image_button = ImageButton::new(texture_handle.value(), size);
|
||||
if ui.add(image_button).clicked(){
|
||||
let to =
|
||||
Path::new(&user.steam_user_data_folder)
|
||||
.join("config")
|
||||
.join("grid")
|
||||
.join(selected_image_type.file_name(selected_image.app_id));
|
||||
let app_name = selected_image.app_name.clone();
|
||||
|
||||
let to_download = ToDownload{
|
||||
path: to,
|
||||
url: image.full_url.clone(),
|
||||
app_name: app_name.clone(),
|
||||
image_type: selected_image_type.clone()
|
||||
};
|
||||
//TODO make this actually parallel
|
||||
self.rt.spawn_blocking(move ||{
|
||||
let _ = block_on(crate::steamgriddb::download_to_download(&to_download));
|
||||
});
|
||||
|
||||
let image_ref = match selected_image_type {
|
||||
ImageType::Hero => {
|
||||
&mut self.image_selected_state.hero_image
|
||||
}
|
||||
ImageType::Grid => {
|
||||
&mut self.image_selected_state.grid_image
|
||||
}
|
||||
ImageType::WideGrid => {
|
||||
&mut self.image_selected_state.wide_image
|
||||
}
|
||||
ImageType::Logo => {
|
||||
&mut self.image_selected_state.logo_image
|
||||
}
|
||||
ImageType::BigPicture => {
|
||||
&mut self.image_selected_state.wide_image
|
||||
}
|
||||
ImageType::Icon => {
|
||||
&mut self.image_selected_state.icon_image
|
||||
}
|
||||
};
|
||||
*image_ref = Some(texture_handle.clone());
|
||||
reset = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
ui.label("Finding possible images");
|
||||
},
|
||||
|
||||
}
|
||||
} else {
|
||||
if let Some(grid_id) = self.image_selected_state.grid_id
|
||||
{
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Grid id:");
|
||||
let mut text_id = format!("{}", grid_id);
|
||||
if ui
|
||||
.text_edit_singleline(&mut text_id)
|
||||
.changed()
|
||||
{
|
||||
if let Ok(grid_id) =
|
||||
text_id.parse::<usize>()
|
||||
{
|
||||
if let Some(auth_key) =
|
||||
&self.settings.steamgrid_db.auth_key
|
||||
{
|
||||
let client =
|
||||
steamgriddb_api::Client::new(
|
||||
auth_key,
|
||||
);
|
||||
let mut search =
|
||||
CachedSearch::new(&client);
|
||||
search.set_cache(
|
||||
selected_image.app_id,
|
||||
selected_image
|
||||
.app_name
|
||||
.to_string(),
|
||||
grid_id,
|
||||
);
|
||||
}
|
||||
self.image_selected_state.grid_id =
|
||||
Some(grid_id);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
for image_type in ImageType::all() {
|
||||
ui.label(image_type.name());
|
||||
|
||||
let image_ref = match image_type {
|
||||
ImageType::Hero => {
|
||||
&mut self.image_selected_state.hero_image
|
||||
}
|
||||
ImageType::Grid => {
|
||||
&mut self.image_selected_state.grid_image
|
||||
}
|
||||
ImageType::WideGrid => {
|
||||
&mut self.image_selected_state.wide_image
|
||||
}
|
||||
ImageType::Logo => {
|
||||
&mut self.image_selected_state.logo_image
|
||||
}
|
||||
ImageType::BigPicture => {
|
||||
&mut self.image_selected_state.wide_image
|
||||
}
|
||||
ImageType::Icon => {
|
||||
&mut self.image_selected_state.icon_image
|
||||
}
|
||||
};
|
||||
if render_image(ui, image_ref) {
|
||||
self.image_selected_state.image_to_replace =
|
||||
Some(image_type.clone());
|
||||
let (mut tx,rx)= watch::channel(FetcStatus::Fetching);
|
||||
self.image_selected_state.image_options = rx;
|
||||
let settings = self.settings.clone();
|
||||
if let Some(auth_key) = settings.steamgrid_db.auth_key{
|
||||
if let Some(grid_id) = self.image_selected_state.grid_id{
|
||||
let auth_key = auth_key.clone();
|
||||
let image_type = image_type.clone();
|
||||
let app_name = selected_image.app_name.clone();
|
||||
self.rt.spawn_blocking( move|| {
|
||||
//Find somewhere else to put this
|
||||
std::fs::create_dir_all(".thumbnails");
|
||||
let thumbnails_folder = Path::new(".thumbnails");
|
||||
let client =steamgriddb_api::Client::new(auth_key);
|
||||
let query = get_query_type(false,&image_type);
|
||||
let search_res = block_on(client.get_images_for_id(grid_id, &query));
|
||||
|
||||
if let Ok(possible_images) = search_res{
|
||||
let mut result = vec![];
|
||||
for possible_image in &possible_images{
|
||||
let path = thumbnails_folder.join(format!("{}.png",possible_image.id));
|
||||
|
||||
if !&path.exists(){
|
||||
let to_download = ToDownload{
|
||||
path: path.clone(),
|
||||
url: possible_image.thumb.clone(),
|
||||
app_name: app_name.clone(),
|
||||
image_type: image_type.clone()
|
||||
};
|
||||
//TODO make this actually parallel
|
||||
block_on(crate::steamgriddb::download_to_download(&to_download));
|
||||
}
|
||||
result.push(PossibleImage { thumbnail_path: path, full_url: possible_image.url.clone() });
|
||||
let _ = tx.send(FetcStatus::Fetched(result.clone()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
if reset {
|
||||
self.image_selected_state.image_to_replace = None;
|
||||
self.image_selected_state.image_options = watch::channel(FetcStatus::NeedsFetched).1;
|
||||
self.image_selected_state.image_handles.clear();
|
||||
}
|
||||
}
|
||||
None => {
|
||||
for (platform_name, shortcuts) in games_to_sync {
|
||||
ui.heading(platform_name);
|
||||
for shortcut in shortcuts {
|
||||
if ui.button(&shortcut.app_name).clicked() {
|
||||
if let Some(auth_key) =
|
||||
&self.settings.steamgrid_db.auth_key
|
||||
{
|
||||
let client =
|
||||
steamgriddb_api::Client::new(auth_key);
|
||||
let search = CachedSearch::new(&client);
|
||||
//TODO make this multithreaded
|
||||
self.image_selected_state.grid_id = self
|
||||
.rt
|
||||
.block_on(search.search(
|
||||
shortcut.app_id,
|
||||
&shortcut.app_name,
|
||||
))
|
||||
.ok()
|
||||
.flatten();
|
||||
}
|
||||
|
||||
self.image_selected_state.selected_image =
|
||||
Some(shortcut.clone());
|
||||
|
||||
let folder =
|
||||
Path::new(&user.steam_user_data_folder)
|
||||
.join("config")
|
||||
.join("grid");
|
||||
|
||||
//TODO put this in seperate thread
|
||||
self.image_selected_state.hero_image =
|
||||
get_image(
|
||||
ui,
|
||||
shortcut,
|
||||
&folder,
|
||||
&ImageType::Hero,
|
||||
);
|
||||
self.image_selected_state.grid_image =
|
||||
get_image(
|
||||
ui,
|
||||
shortcut,
|
||||
&folder,
|
||||
&ImageType::Grid,
|
||||
);
|
||||
self.image_selected_state.icon_image =
|
||||
get_image(
|
||||
ui,
|
||||
shortcut,
|
||||
&folder,
|
||||
&ImageType::Icon,
|
||||
);
|
||||
self.image_selected_state.logo_image =
|
||||
get_image(
|
||||
ui,
|
||||
shortcut,
|
||||
&folder,
|
||||
&ImageType::Logo,
|
||||
);
|
||||
self.image_selected_state.wide_image =
|
||||
get_image(
|
||||
ui,
|
||||
shortcut,
|
||||
&folder,
|
||||
&ImageType::WideGrid,
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
ui.label("Finding installed games");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
None => {
|
||||
let users = self
|
||||
.image_selected_state
|
||||
.steam_users
|
||||
.get_or_insert_with(|| {
|
||||
get_shortcuts_paths(&self.settings.steam).expect("Should have steam user")
|
||||
});
|
||||
if users.len() == 1{
|
||||
self.image_selected_state.steam_user = Some(users[0].clone())
|
||||
}
|
||||
for user in users {
|
||||
if ui.button(&user.user_id).clicked() {
|
||||
self.image_selected_state.steam_user = Some(user.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const MAX_WIDTH:f32 = 300.;
|
||||
|
||||
fn render_image(ui: &mut egui::Ui, image: &mut Option<egui::TextureHandle>) -> bool {
|
||||
match image {
|
||||
Some(texture) => {
|
||||
let mut size = texture.size_vec2();
|
||||
clamp_to_width(&mut size,MAX_WIDTH);
|
||||
let image_button = ImageButton::new(texture, size);
|
||||
ui.add(image_button)
|
||||
.on_hover_text("Click to change image")
|
||||
.clicked()
|
||||
}
|
||||
None => ui.button("Pick an image").clicked(),
|
||||
}
|
||||
}
|
||||
|
||||
fn clamp_to_width(size: &mut egui::Vec2, max_width :f32) {
|
||||
let mut x = size.x;
|
||||
let mut y = size.y;
|
||||
if size.x > max_width{
|
||||
let ratio = size.y / size.x;
|
||||
x = max_width;
|
||||
y = x * ratio;
|
||||
}
|
||||
size.x = x;
|
||||
size.y = y;
|
||||
}
|
||||
|
||||
fn get_image(
|
||||
ui: &mut egui::Ui,
|
||||
shortcut: &ShortcutOwned,
|
||||
folder: &std::path::Path,
|
||||
image_type: &ImageType,
|
||||
) -> Option<egui::TextureHandle> {
|
||||
let file_name = ImageType::file_name(image_type, shortcut.app_id);
|
||||
let file_path = folder.join(file_name);
|
||||
let image = load_image_from_path(file_path.as_path()).map(|img_data| {
|
||||
ui.ctx()
|
||||
.load_texture(file_path.to_string_lossy().to_string(), img_data)
|
||||
});
|
||||
image
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
use eframe::egui;
|
||||
use egui::ScrollArea;
|
||||
use futures::executor::block_on;
|
||||
|
||||
use tokio::sync::watch;
|
||||
|
||||
use crate::settings::Settings;
|
||||
use crate::sync;
|
||||
|
||||
use crate::sync::{download_images, SyncProgress};
|
||||
|
||||
use super::ImageSelectState;
|
||||
use super::{
|
||||
ui_colors::{BACKGROUND_COLOR, EXTRA_BACKGROUND_COLOR},
|
||||
MyEguiApp,
|
||||
};
|
||||
|
||||
const SECTION_SPACING: f32 = 25.0;
|
||||
|
||||
pub enum FetcStatus<T> {
|
||||
NeedsFetched,
|
||||
Fetching,
|
||||
Fetched(T),
|
||||
}
|
||||
|
||||
impl<T> FetcStatus<T> {
|
||||
pub fn is_some(&self) -> bool {
|
||||
match self {
|
||||
FetcStatus::NeedsFetched => false,
|
||||
FetcStatus::Fetching => false,
|
||||
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;
|
||||
scroll_style.visuals.widgets.active.bg_fill = EXTRA_BACKGROUND_COLOR;
|
||||
scroll_style.visuals.selection.bg_fill = EXTRA_BACKGROUND_COLOR;
|
||||
scroll_style.visuals.widgets.hovered.bg_fill = EXTRA_BACKGROUND_COLOR;
|
||||
|
||||
ScrollArea::vertical()
|
||||
.stick_to_right()
|
||||
.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);
|
||||
let checkbox = egui::Checkbox::new(&mut import_game,&shortcut.app_name);
|
||||
let response = ui.add(checkbox);
|
||||
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.label("Finding installed games");
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
let (sender, reciever) = watch::channel(SyncProgress::NotStarted);
|
||||
let settings = self.settings.clone();
|
||||
if settings.steam.stop_steam {
|
||||
crate::steam::ensure_steam_stopped();
|
||||
}
|
||||
|
||||
self.status_reciever = reciever;
|
||||
self.rt.spawn_blocking(move || {
|
||||
MyEguiApp::save_settings_to_file(&settings);
|
||||
let mut some_sender = Some(sender);
|
||||
let usersinfo = sync::run_sync(&settings, &mut some_sender).unwrap();
|
||||
let task = download_images(&settings, &usersinfo, &mut some_sender);
|
||||
block_on(task);
|
||||
if let Some(sender) = some_sender {
|
||||
let _ = sender.send(SyncProgress::Done);
|
||||
}
|
||||
if settings.steam.start_steam {
|
||||
crate::steam::ensure_steam_started(&settings.steam);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn save_settings_to_file(settings: &Settings) {
|
||||
let toml = toml::to_string(&settings).unwrap();
|
||||
std::fs::write("config.toml", toml).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
use eframe::egui;
|
||||
use egui::ScrollArea;
|
||||
|
||||
use crate::egs::EpicPlatform;
|
||||
|
||||
use super::{
|
||||
ui_colors::{BACKGROUND_COLOR, EXTRA_BACKGROUND_COLOR},
|
||||
MyEguiApp,
|
||||
};
|
||||
const SECTION_SPACING: f32 = 25.0;
|
||||
|
||||
impl MyEguiApp {
|
||||
pub(crate) fn render_settings(&mut self, ui: &mut egui::Ui) {
|
||||
ui.heading("Settings");
|
||||
|
||||
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;
|
||||
scroll_style.visuals.widgets.active.bg_fill = EXTRA_BACKGROUND_COLOR;
|
||||
scroll_style.visuals.selection.bg_fill = EXTRA_BACKGROUND_COLOR;
|
||||
scroll_style.visuals.widgets.hovered.bg_fill = EXTRA_BACKGROUND_COLOR;
|
||||
|
||||
ScrollArea::vertical()
|
||||
.stick_to_right()
|
||||
.auto_shrink([false, true])
|
||||
.show(ui, |ui| {
|
||||
ui.reset_style();
|
||||
|
||||
self.render_steamgriddb_settings(ui);
|
||||
|
||||
self.render_steam_settings(ui);
|
||||
|
||||
self.render_epic_settings(ui);
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
{
|
||||
ui.heading("Heroic");
|
||||
ui.checkbox(&mut self.settings.heroic.enabled, "Import form Heroic");
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn render_lutris_settings(&mut self, ui: &mut egui::Ui) {
|
||||
ui.heading("Lutris");
|
||||
ui.checkbox(&mut self.settings.lutris.enabled, "Import form Lutris");
|
||||
if self.settings.lutris.enabled {
|
||||
ui.horizontal(|ui| {
|
||||
let mut empty_string = "".to_string();
|
||||
let lutris_location = self
|
||||
.settings
|
||||
.lutris
|
||||
.executable
|
||||
.as_mut()
|
||||
.unwrap_or(&mut empty_string);
|
||||
ui.label("Lutris Location: ");
|
||||
if ui.text_edit_singleline(lutris_location).changed() {
|
||||
self.settings.lutris.executable = Some(lutris_location.to_string());
|
||||
}
|
||||
});
|
||||
}
|
||||
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 form 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 form 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 form 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 form 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 = Some(itch_location.to_string());
|
||||
}
|
||||
});
|
||||
}
|
||||
ui.add_space(SECTION_SPACING);
|
||||
}
|
||||
|
||||
fn render_steam_settings(&mut self, ui: &mut egui::Ui) {
|
||||
ui.heading("Steam");
|
||||
ui.horizontal(|ui| {
|
||||
let mut empty_string = "".to_string();
|
||||
let steam_location = self
|
||||
.settings
|
||||
.steam
|
||||
.location
|
||||
.as_mut()
|
||||
.unwrap_or(&mut empty_string);
|
||||
ui.label("Steam Location: ");
|
||||
if ui.text_edit_singleline(steam_location).changed() {
|
||||
self.settings.steam.location = Some(steam_location.to_string());
|
||||
}
|
||||
});
|
||||
ui.checkbox(
|
||||
&mut self.settings.steam.create_collections,
|
||||
"Create collections",
|
||||
)
|
||||
.on_hover_text("Tries to create a games collection for each platform");
|
||||
ui.checkbox(&mut self.settings.steam.optimize_for_big_picture, "Optimize for big picture").on_hover_text("Set icons to be larger horizontal images, this looks nice in steam big picture mode, but a bit off in desktop mode");
|
||||
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.add_space(SECTION_SPACING);
|
||||
}
|
||||
|
||||
fn render_steamgriddb_settings(&mut self, ui: &mut egui::Ui) {
|
||||
ui.heading("SteamGridDB");
|
||||
ui.checkbox(&mut self.settings.steamgrid_db.enabled, "Download images");
|
||||
if self.settings.steamgrid_db.enabled {
|
||||
ui.horizontal(|ui| {
|
||||
let mut empty_string = "".to_string();
|
||||
let auth_key = self
|
||||
.settings
|
||||
.steamgrid_db
|
||||
.auth_key
|
||||
.as_mut()
|
||||
.unwrap_or(&mut empty_string);
|
||||
ui.label("Authentication key: ");
|
||||
if ui.text_edit_singleline(auth_key).changed() {
|
||||
self.settings.steamgrid_db.auth_key = Some(auth_key.to_string());
|
||||
}
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(
|
||||
"To download images you need an API Key from SteamGridDB, you can find yours",
|
||||
);
|
||||
ui.hyperlink_to(
|
||||
"here",
|
||||
"https://www.steamgriddb.com/profile/preferences/api",
|
||||
)
|
||||
});
|
||||
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.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 form 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 form Epic Games");
|
||||
if epic_settings.enabled {
|
||||
ui.horizontal(|ui| {
|
||||
let mut empty_string = "".to_string();
|
||||
let epic_location = epic_settings.location.as_mut().unwrap_or(&mut empty_string);
|
||||
ui.label("Epic Manifests Location: ").on_hover_text(
|
||||
"The location where Epic stores its manifest files that BoilR needs to read",
|
||||
);
|
||||
if ui.text_edit_singleline(epic_location).changed() {
|
||||
epic_settings.location = Some(epic_location.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+128
-443
@@ -1,59 +1,44 @@
|
||||
use eframe::{egui, epi::{self},};
|
||||
use egui::{ScrollArea, TextureHandle, Stroke, Rounding, ImageButton};
|
||||
use futures::executor::block_on;
|
||||
use std::error::Error;
|
||||
|
||||
use eframe::{egui, epi};
|
||||
use egui::{ImageButton, Rounding, Stroke, TextureHandle};
|
||||
use steam_shortcuts_util::shortcut::ShortcutOwned;
|
||||
use std::{error::Error};
|
||||
use tokio::{runtime::Runtime, sync::watch::{Receiver, self}};
|
||||
use tokio::{
|
||||
runtime::Runtime,
|
||||
sync::watch::{self, Receiver},
|
||||
};
|
||||
|
||||
use crate::{settings::Settings, sync::{download_images, self, SyncProgress}, egs::{EpicPlatform, ManifestItem}};
|
||||
use crate::{egs::ManifestItem, settings::Settings, sync::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_colors::{
|
||||
BACKGROUND_COLOR, BG_STROKE_COLOR, EXTRA_BACKGROUND_COLOR, LIGHT_ORANGE, ORANGE, PURLPLE,
|
||||
TEXT_COLOR,
|
||||
},
|
||||
ui_images::{get_import_image, get_logo, get_logo_icon},
|
||||
ui_import_games::FetcStatus,
|
||||
ImageSelectState,
|
||||
};
|
||||
|
||||
const SECTION_SPACING : f32 = 25.0;
|
||||
const SECTION_SPACING: f32 = 25.0;
|
||||
|
||||
#[derive(Default)]
|
||||
struct UiImages{
|
||||
struct UiImages {
|
||||
import_button: Option<egui::TextureHandle>,
|
||||
logo_32: Option<egui::TextureHandle>,
|
||||
}
|
||||
|
||||
|
||||
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 {
|
||||
pub struct MyEguiApp {
|
||||
selected_menu: Menues,
|
||||
settings: Settings,
|
||||
rt: Runtime,
|
||||
ui_images: UiImages,
|
||||
games_to_sync: Receiver<FetchGameStatus>,
|
||||
status_reciever: Receiver<SyncProgress>,
|
||||
epic_manifests: Option<Vec<ManifestItem>>,
|
||||
pub(crate) settings: Settings,
|
||||
pub(crate) rt: Runtime,
|
||||
ui_images: UiImages,
|
||||
pub(crate) games_to_sync: Receiver<FetcStatus<Vec<(String, Vec<ShortcutOwned>)>>>,
|
||||
pub(crate) status_reciever: Receiver<SyncProgress>,
|
||||
pub(crate) epic_manifests: Option<Vec<ManifestItem>>,
|
||||
pub(crate) image_selected_state: ImageSelectState,
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl MyEguiApp {
|
||||
pub fn new() -> Self {
|
||||
let runtime = Runtime::new().unwrap();
|
||||
@@ -61,47 +46,20 @@ impl MyEguiApp {
|
||||
selected_menu: Menues::Import,
|
||||
settings: Settings::new().expect("We must be able to load our settings"),
|
||||
rt: runtime,
|
||||
games_to_sync:watch::channel(FetchGameStatus::NeedsFetched).1,
|
||||
ui_images: UiImages::default(),
|
||||
games_to_sync: watch::channel(FetcStatus::NeedsFetched).1,
|
||||
ui_images: UiImages::default(),
|
||||
status_reciever: watch::channel(SyncProgress::NotStarted).1,
|
||||
epic_manifests : None,
|
||||
epic_manifests: None,
|
||||
image_selected_state: ImageSelectState::default(),
|
||||
}
|
||||
}
|
||||
pub fn run_sync(&mut self) {
|
||||
let (sender,reciever ) = watch::channel(SyncProgress::NotStarted);
|
||||
let settings = self.settings.clone();
|
||||
if settings.steam.stop_steam{
|
||||
crate::steam::ensure_steam_stopped();
|
||||
}
|
||||
|
||||
self.status_reciever = reciever;
|
||||
self.rt.spawn_blocking(move || {
|
||||
|
||||
MyEguiApp::save_settings_to_file(&settings);
|
||||
let mut some_sender =Some(sender);
|
||||
let usersinfo = sync::run_sync(&settings,&mut some_sender).unwrap();
|
||||
let task = download_images(&settings, &usersinfo,&mut some_sender);
|
||||
block_on(task);
|
||||
if let Some(sender) = some_sender{
|
||||
let _ = sender.send(SyncProgress::Done);
|
||||
}
|
||||
if settings.steam.start_steam{
|
||||
crate::steam::ensure_steam_started(&settings.steam);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
fn save_settings_to_file(settings: &Settings) {
|
||||
let toml = toml::to_string(&settings).unwrap();
|
||||
std::fs::write("config.toml", toml).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum Menues {
|
||||
Import,
|
||||
Settings,
|
||||
Import,
|
||||
Settings,
|
||||
Images,
|
||||
}
|
||||
|
||||
impl Default for Menues {
|
||||
@@ -113,22 +71,24 @@ impl Default for Menues {
|
||||
impl epi::App for MyEguiApp {
|
||||
fn name(&self) -> &str {
|
||||
"BoilR"
|
||||
}
|
||||
}
|
||||
|
||||
fn setup(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
_frame: &epi::Frame,
|
||||
_storage: Option<&dyn epi::Storage>
|
||||
) {
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
_frame: &epi::Frame,
|
||||
_storage: Option<&dyn epi::Storage>,
|
||||
) {
|
||||
ctx.set_pixels_per_point(1.0);
|
||||
let mut style: egui::Style = (*ctx.style()).clone();
|
||||
create_style(&mut style);
|
||||
ctx.set_style(style);
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) {
|
||||
let frame = egui::Frame::default().stroke(Stroke::new(0., BACKGROUND_COLOR)).fill(BACKGROUND_COLOR);
|
||||
let frame = egui::Frame::default()
|
||||
.stroke(Stroke::new(0., BACKGROUND_COLOR))
|
||||
.fill(BACKGROUND_COLOR);
|
||||
egui::SidePanel::new(egui::panel::Side::Left, "Side Panel")
|
||||
.default_width(40.0)
|
||||
.frame(frame)
|
||||
@@ -136,68 +96,72 @@ impl epi::App for MyEguiApp {
|
||||
let texture = self.get_logo_image(ui);
|
||||
let size = texture.size_vec2();
|
||||
ui.image(texture, size);
|
||||
ui.add_space(SECTION_SPACING);
|
||||
|
||||
let changed = ui.selectable_value(&mut self.selected_menu, Menues::Import, "Import Games").changed();
|
||||
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;
|
||||
ui.add_space(SECTION_SPACING);
|
||||
|
||||
let changed = ui
|
||||
.selectable_value(&mut self.selected_menu, Menues::Import, "Import Games")
|
||||
.changed();
|
||||
let changed = changed
|
||||
|| ui
|
||||
.selectable_value(&mut self.selected_menu, Menues::Settings, "Settings")
|
||||
.changed();
|
||||
let changed = changed
|
||||
|| ui
|
||||
.selectable_value(&mut self.selected_menu, Menues::Images, "Images")
|
||||
.changed();
|
||||
if changed && self.selected_menu == Menues::Settings {
|
||||
//We reset games here, since user might change settings
|
||||
self.games_to_sync = watch::channel(FetcStatus::NeedsFetched).1;
|
||||
}
|
||||
|
||||
});
|
||||
if self.games_to_sync.borrow().is_some(){
|
||||
|
||||
if self.games_to_sync.borrow().is_some() {
|
||||
egui::TopBottomPanel::new(egui::panel::TopBottomSide::Bottom, "Bottom Panel")
|
||||
.frame(frame)
|
||||
.show(ctx,|ui|{
|
||||
let (status_string,syncing) = match &*self.status_reciever.borrow(){
|
||||
SyncProgress::NotStarted => {
|
||||
("".to_string(),false)
|
||||
},
|
||||
SyncProgress::Starting => {
|
||||
("Starting Import".to_string(),true)
|
||||
},
|
||||
.frame(frame)
|
||||
.show(ctx, |ui| {
|
||||
let (status_string, syncing) = match &*self.status_reciever.borrow() {
|
||||
SyncProgress::NotStarted => ("".to_string(), false),
|
||||
SyncProgress::Starting => ("Starting Import".to_string(), true),
|
||||
SyncProgress::FoundGames { games_found } => {
|
||||
(format!("Found {} games to import",games_found),true)
|
||||
},
|
||||
SyncProgress::FindingImages => {
|
||||
(format!("Searching for images"),true)
|
||||
},
|
||||
SyncProgress::DownloadingImages { to_download } => {
|
||||
(format!("Downloading {} images ",to_download),true)
|
||||
},
|
||||
SyncProgress::Done => {
|
||||
(format!("Done importing games"),false)
|
||||
},
|
||||
};
|
||||
if status_string != "" {
|
||||
ui.label(status_string);
|
||||
}
|
||||
|
||||
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() && !syncing{
|
||||
(format!("Found {} games to import", games_found), true)
|
||||
}
|
||||
SyncProgress::FindingImages => ("Searching for images".to_string(), true),
|
||||
SyncProgress::DownloadingImages { to_download } => {
|
||||
(format!("Downloading {} images ", to_download), true)
|
||||
}
|
||||
SyncProgress::Done => ("Done importing games".to_string(), false),
|
||||
};
|
||||
if !status_string.is_empty() {
|
||||
ui.label(status_string);
|
||||
}
|
||||
|
||||
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()
|
||||
&& !syncing
|
||||
{
|
||||
self.run_sync();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
egui::CentralPanel::default()
|
||||
.show(ctx, |ui| {
|
||||
match self.selected_menu {
|
||||
Menues::Import => {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
match self.selected_menu {
|
||||
Menues::Import => {
|
||||
self.render_import_games(ui);
|
||||
|
||||
},
|
||||
}
|
||||
Menues::Settings => {
|
||||
self.render_settings(ui);
|
||||
},
|
||||
self.render_settings(ui);
|
||||
}
|
||||
Menues::Images => {
|
||||
self.render_ui_images(ui);
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn create_style(style: &mut egui::Style) {
|
||||
@@ -205,339 +169,60 @@ fn create_style(style: &mut egui::Style) {
|
||||
style.visuals.button_frame = false;
|
||||
style.visuals.dark_mode = true;
|
||||
style.visuals.override_text_color = Some(TEXT_COLOR);
|
||||
style.visuals.widgets.noninteractive.rounding = Rounding{
|
||||
ne:0.0,
|
||||
nw:0.0,
|
||||
se:0.0,
|
||||
sw:0.0
|
||||
style.visuals.widgets.noninteractive.rounding = Rounding {
|
||||
ne: 0.0,
|
||||
nw: 0.0,
|
||||
se: 0.0,
|
||||
sw: 0.0,
|
||||
};
|
||||
style.visuals.faint_bg_color = PURLPLE;
|
||||
style.visuals.extreme_bg_color = EXTRA_BACKGROUND_COLOR;
|
||||
style.visuals.widgets.active.bg_fill = BACKGROUND_COLOR;
|
||||
style.visuals.widgets.active.bg_stroke = Stroke::new(2.0,BG_STROKE_COLOR);
|
||||
style.visuals.widgets.active.fg_stroke = Stroke::new(2.0,LIGHT_ORANGE);
|
||||
style.visuals.widgets.active.bg_stroke = Stroke::new(2.0, BG_STROKE_COLOR);
|
||||
style.visuals.widgets.active.fg_stroke = Stroke::new(2.0, LIGHT_ORANGE);
|
||||
style.visuals.widgets.open.bg_fill = BACKGROUND_COLOR;
|
||||
style.visuals.widgets.open.bg_stroke = Stroke::new(2.0,BG_STROKE_COLOR);
|
||||
style.visuals.widgets.open.fg_stroke = Stroke::new(2.0,LIGHT_ORANGE);
|
||||
style.visuals.widgets.open.bg_stroke = Stroke::new(2.0, BG_STROKE_COLOR);
|
||||
style.visuals.widgets.open.fg_stroke = Stroke::new(2.0, LIGHT_ORANGE);
|
||||
style.visuals.widgets.noninteractive.bg_fill = BACKGROUND_COLOR;
|
||||
style.visuals.widgets.noninteractive.bg_stroke = Stroke::new(2.0,BG_STROKE_COLOR);
|
||||
style.visuals.widgets.noninteractive.fg_stroke = Stroke::new(2.0,ORANGE);
|
||||
style.visuals.widgets.noninteractive.bg_stroke = Stroke::new(2.0, BG_STROKE_COLOR);
|
||||
style.visuals.widgets.noninteractive.fg_stroke = Stroke::new(2.0, ORANGE);
|
||||
style.visuals.widgets.inactive.bg_fill = BACKGROUND_COLOR;
|
||||
style.visuals.widgets.inactive.bg_stroke = Stroke::new(2.0,BG_STROKE_COLOR);
|
||||
style.visuals.widgets.inactive.fg_stroke = Stroke::new(2.0,ORANGE);
|
||||
style.visuals.widgets.inactive.bg_stroke = Stroke::new(2.0, BG_STROKE_COLOR);
|
||||
style.visuals.widgets.inactive.fg_stroke = Stroke::new(2.0, ORANGE);
|
||||
style.visuals.widgets.hovered.bg_fill = BACKGROUND_COLOR;
|
||||
style.visuals.widgets.hovered.bg_stroke = Stroke::new(2.0,BG_STROKE_COLOR);
|
||||
style.visuals.widgets.hovered.fg_stroke = Stroke::new(2.0,LIGHT_ORANGE);
|
||||
style.visuals.widgets.hovered.bg_stroke = Stroke::new(2.0, BG_STROKE_COLOR);
|
||||
style.visuals.widgets.hovered.fg_stroke = Stroke::new(2.0, LIGHT_ORANGE);
|
||||
style.visuals.selection.bg_fill = PURLPLE;
|
||||
}
|
||||
|
||||
impl MyEguiApp{
|
||||
|
||||
fn get_import_image(&mut self, ui:&mut egui::Ui) -> &mut TextureHandle {
|
||||
self.ui_images.import_button.get_or_insert_with(|| {
|
||||
// Load the texture only once.
|
||||
ui.ctx().load_texture("import_image", get_import_image())
|
||||
})
|
||||
|
||||
impl MyEguiApp {
|
||||
fn get_import_image(&mut self, ui: &mut egui::Ui) -> &mut TextureHandle {
|
||||
self.ui_images.import_button.get_or_insert_with(|| {
|
||||
// Load the texture only once.
|
||||
ui.ctx().load_texture("import_image", get_import_image())
|
||||
})
|
||||
}
|
||||
|
||||
fn get_logo_image(&mut self, ui:&mut egui::Ui) -> &mut TextureHandle {
|
||||
fn get_logo_image(&mut self, ui: &mut egui::Ui) -> &mut TextureHandle {
|
||||
self.ui_images.logo_32.get_or_insert_with(|| {
|
||||
// Load the texture only once.
|
||||
ui.ctx().load_texture("logo32", get_logo())
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
fn render_settings(&mut self, ui: &mut egui::Ui){
|
||||
ui.heading("Settings");
|
||||
|
||||
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;
|
||||
scroll_style.visuals.widgets.active.bg_fill = EXTRA_BACKGROUND_COLOR;
|
||||
scroll_style.visuals.selection.bg_fill = EXTRA_BACKGROUND_COLOR;
|
||||
scroll_style.visuals.widgets.hovered.bg_fill = EXTRA_BACKGROUND_COLOR;
|
||||
|
||||
ScrollArea::vertical()
|
||||
.stick_to_right()
|
||||
.auto_shrink([false,true])
|
||||
.show(ui,|ui| {
|
||||
ui.reset_style();
|
||||
|
||||
self.render_steamgriddb_settings(ui);
|
||||
|
||||
self.render_steam_settings(ui);
|
||||
|
||||
self.render_epic_settings(ui);
|
||||
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
{
|
||||
ui.heading("Heroic");
|
||||
ui.checkbox(&mut self.settings.heroic.enabled, "Import form Heroic");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
fn render_lutris_settings(&mut self, ui: &mut egui::Ui) {
|
||||
ui.heading("Lutris");
|
||||
ui.checkbox(&mut self.settings.lutris.enabled, "Import form Lutris");
|
||||
if self.settings.lutris.enabled{
|
||||
ui.horizontal(|ui| {
|
||||
let mut empty_string ="".to_string();
|
||||
let lutris_location = self.settings.lutris.executable.as_mut().unwrap_or(&mut empty_string);
|
||||
ui.label("Lutris Location: ");
|
||||
if ui.text_edit_singleline(lutris_location).changed(){
|
||||
self.settings.lutris.executable = Some(lutris_location.to_string());
|
||||
}
|
||||
});
|
||||
}
|
||||
ui.add_space(SECTION_SPACING);
|
||||
}
|
||||
|
||||
fn render_amazon_settings(&mut self, ui: &mut egui::Ui) {
|
||||
ui.heading("Amazon");
|
||||
ui.checkbox(&mut self.settings.amazon.enabled, "Import form 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 form 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 form 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 form 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 = Some(itch_location.to_string());
|
||||
}
|
||||
});
|
||||
}
|
||||
ui.add_space(SECTION_SPACING);
|
||||
}
|
||||
|
||||
fn render_steam_settings(&mut self, ui: &mut egui::Ui) {
|
||||
ui.heading("Steam");
|
||||
ui.horizontal(|ui| {
|
||||
let mut empty_string ="".to_string();
|
||||
let steam_location = self.settings.steam.location.as_mut().unwrap_or(&mut empty_string);
|
||||
ui.label("Steam Location: ");
|
||||
if ui.text_edit_singleline(steam_location).changed(){
|
||||
self.settings.steam.location = Some(steam_location.to_string());
|
||||
}
|
||||
});
|
||||
ui.checkbox(&mut self.settings.steam.create_collections, "Create collections").on_hover_text("Tries to create a games collection for each platform");
|
||||
ui.checkbox(&mut self.settings.steam.optimize_for_big_picture, "Optimize for big picture").on_hover_text("Set icons to be larger horizontal images, this looks nice in steam big picture mode, but a bit off in desktop mode");
|
||||
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.add_space(SECTION_SPACING);
|
||||
}
|
||||
|
||||
fn render_steamgriddb_settings(&mut self, ui: &mut egui::Ui) {
|
||||
ui.heading("SteamGridDB");
|
||||
ui.checkbox(&mut self.settings.steamgrid_db.enabled, "Download images");
|
||||
if self.settings.steamgrid_db.enabled{
|
||||
ui.horizontal(|ui| {
|
||||
let mut empty_string ="".to_string();
|
||||
let auth_key = self.settings.steamgrid_db.auth_key.as_mut().unwrap_or(&mut empty_string);
|
||||
ui.label("Authentication key: ");
|
||||
if ui.text_edit_singleline(auth_key).changed(){
|
||||
self.settings.steamgrid_db.auth_key = Some(auth_key.to_string());
|
||||
}
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("To download images you need an API Key from SteamGridDB, you can find yours");
|
||||
ui.hyperlink_to("here", "https://www.steamgriddb.com/profile/preferences/api")
|
||||
});
|
||||
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.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 form 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 form Epic Games");
|
||||
if epic_settings.enabled{
|
||||
ui.horizontal(|ui| {
|
||||
let mut empty_string ="".to_string();
|
||||
let epic_location = epic_settings.location.as_mut().unwrap_or(&mut empty_string);
|
||||
ui.label("Epic Manifests Location: ").on_hover_text("The location where Epic stores its manifest files that BoilR needs to read");
|
||||
if ui.text_edit_singleline(epic_location).changed(){
|
||||
epic_settings.location = Some(epic_location.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
fn render_import_games(&mut self, ui: &mut egui::Ui){
|
||||
|
||||
ui.heading("Import Games");
|
||||
|
||||
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));
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
scroll_style.visuals.widgets.active.bg_fill = EXTRA_BACKGROUND_COLOR;
|
||||
scroll_style.visuals.selection.bg_fill = EXTRA_BACKGROUND_COLOR;
|
||||
scroll_style.visuals.widgets.hovered.bg_fill = EXTRA_BACKGROUND_COLOR;
|
||||
|
||||
|
||||
ScrollArea::vertical()
|
||||
.stick_to_right()
|
||||
.auto_shrink([false,true])
|
||||
.show(ui,|ui| {
|
||||
ui.reset_style();
|
||||
|
||||
let borrowed_games = &*self.games_to_sync.borrow();
|
||||
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{
|
||||
ui.heading(platform_name);
|
||||
for shortcut in shortcuts {
|
||||
let mut import_game = !self.settings.blacklisted_games.contains(&shortcut.app_id);
|
||||
let checkbox = egui::Checkbox::new(&mut import_game,&shortcut.app_name);
|
||||
let response = ui.add(checkbox);
|
||||
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.label("Finding installed games");
|
||||
},
|
||||
};
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn run_sync() {
|
||||
let mut app = MyEguiApp::new();
|
||||
app.run_sync();
|
||||
}
|
||||
|
||||
|
||||
pub fn run_ui() -> Result<(), Box<dyn Error>> {
|
||||
let app = MyEguiApp::new();
|
||||
|
||||
let mut native_options = eframe::NativeOptions::default();
|
||||
native_options.initial_window_size = Some(egui::Vec2{
|
||||
x:800.,
|
||||
y:500.
|
||||
});
|
||||
native_options.icon_data = Some(get_logo_icon());
|
||||
let native_options = eframe::NativeOptions {
|
||||
initial_window_size: Some(egui::Vec2 { x: 800., y: 500. }),
|
||||
icon_data: Some(get_logo_icon()),
|
||||
..Default::default()
|
||||
};
|
||||
eframe::run_native(Box::new(app), native_options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user