mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
UI for image download refactor and fixes (#98)
This commit is contained in:
+1
-1
@@ -43,7 +43,7 @@ pub struct ShortcutInfo {
|
|||||||
pub shortcuts: Vec<ShortcutOwned>,
|
pub shortcuts: Vec<ShortcutOwned>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Clone)]
|
#[derive(Default, PartialEq, Clone, Debug)]
|
||||||
pub struct SteamUsersInfo {
|
pub struct SteamUsersInfo {
|
||||||
pub steam_user_data_folder: String,
|
pub steam_user_data_folder: String,
|
||||||
pub shortcut_path: Option<String>,
|
pub shortcut_path: Option<String>,
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ impl<'a> CachedSearch<'a> {
|
|||||||
save_search_map(&self.search_map);
|
save_search_map(&self.search_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_cache<S>(&mut self, app_id: u32, name:S, new_grid_id:usize)
|
pub fn set_cache<S>(&mut self, app_id: u32, name: S, new_grid_id: usize)
|
||||||
where
|
where
|
||||||
S: Into<String>{
|
S: Into<String>,
|
||||||
self.search_map.insert(app_id,(name.into(),new_grid_id));
|
{
|
||||||
|
self.search_map.insert(app_id, (name.into(), new_grid_id));
|
||||||
self.save();
|
self.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -248,9 +248,12 @@ async fn get_images_for_ids(
|
|||||||
image_search_result.map_err(|e| format!("Image search failed {:?}", e))
|
image_search_result.map_err(|e| format!("Image search failed {:?}", e))
|
||||||
}
|
}
|
||||||
|
|
||||||
const BIG_PICTURE_DIMS : [GridDimentions;2] = [GridDimentions::D920x430, GridDimentions::D460x215];
|
const BIG_PICTURE_DIMS: [GridDimentions; 2] = [GridDimentions::D920x430, GridDimentions::D460x215];
|
||||||
|
|
||||||
pub fn get_query_type(download_animated: bool, image_type: &ImageType) -> steamgriddb_api::QueryType {
|
pub fn get_query_type(
|
||||||
|
download_animated: bool,
|
||||||
|
image_type: &ImageType,
|
||||||
|
) -> steamgriddb_api::QueryType {
|
||||||
let anymation_type = if download_animated {
|
let anymation_type = if download_animated {
|
||||||
Some(&[steamgriddb_api::query_parameters::AnimtionType::Animated][..])
|
Some(&[steamgriddb_api::query_parameters::AnimtionType::Animated][..])
|
||||||
} else {
|
} else {
|
||||||
@@ -366,6 +369,3 @@ pub struct ToDownload {
|
|||||||
pub app_name: String,
|
pub app_name: String,
|
||||||
pub image_type: ImageType,
|
pub image_type: ImageType,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Send for ToDownload {
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#[derive(Debug, Clone, Copy,PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum ImageType {
|
pub enum ImageType {
|
||||||
Hero,
|
Hero,
|
||||||
Grid,
|
Grid,
|
||||||
@@ -8,16 +8,21 @@ pub enum ImageType {
|
|||||||
Icon,
|
Icon,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const ALL_TYPES : [ImageType;6] =
|
pub const ALL_TYPES: [ImageType; 6] = [
|
||||||
[ImageType::Hero,ImageType::Grid,ImageType::WideGrid,ImageType::Logo,ImageType::BigPicture,ImageType::Icon];
|
ImageType::Hero,
|
||||||
|
ImageType::Grid,
|
||||||
|
ImageType::WideGrid,
|
||||||
|
ImageType::Logo,
|
||||||
|
ImageType::BigPicture,
|
||||||
|
ImageType::Icon,
|
||||||
|
];
|
||||||
|
|
||||||
impl ImageType {
|
impl ImageType {
|
||||||
|
pub fn all() -> &'static [ImageType; 6] {
|
||||||
pub fn all() -> &'static [ImageType;6]{
|
|
||||||
&ALL_TYPES
|
&ALL_TYPES
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &str{
|
pub fn name(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
ImageType::Hero => "Hero",
|
ImageType::Hero => "Hero",
|
||||||
ImageType::Grid => "Grid",
|
ImageType::Grid => "Grid",
|
||||||
|
|||||||
+356
-282
@@ -1,11 +1,14 @@
|
|||||||
use std::path::{Path, PathBuf};
|
use std::{
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
sync::Arc,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
steam::{get_shortcuts_paths, SteamUsersInfo},
|
steam::{get_shortcuts_paths, SteamUsersInfo},
|
||||||
steamgriddb::{CachedSearch, ImageType, get_query_type, ToDownload},
|
steamgriddb::{get_query_type, CachedSearch, ImageType, ToDownload},
|
||||||
};
|
};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use egui::{ImageButton, ScrollArea};
|
use egui::{ImageButton, ScrollArea, TextureHandle};
|
||||||
use futures::executor::block_on;
|
use futures::executor::block_on;
|
||||||
use steam_shortcuts_util::shortcut::ShortcutOwned;
|
use steam_shortcuts_util::shortcut::ShortcutOwned;
|
||||||
use tokio::sync::watch::{self, Receiver};
|
use tokio::sync::watch::{self, Receiver};
|
||||||
@@ -13,7 +16,7 @@ use tokio::sync::watch::{self, Receiver};
|
|||||||
use super::{ui_images::load_image_from_path, FetcStatus, MyEguiApp};
|
use super::{ui_images::load_image_from_path, FetcStatus, MyEguiApp};
|
||||||
|
|
||||||
pub struct ImageSelectState {
|
pub struct ImageSelectState {
|
||||||
pub selected_image: Option<ShortcutOwned>,
|
pub selected_shortcut: Option<ShortcutOwned>,
|
||||||
pub grid_id: Option<usize>,
|
pub grid_id: Option<usize>,
|
||||||
|
|
||||||
pub hero_image: Option<egui::TextureHandle>,
|
pub hero_image: Option<egui::TextureHandle>,
|
||||||
@@ -25,22 +28,39 @@ pub struct ImageSelectState {
|
|||||||
pub steam_user: Option<SteamUsersInfo>,
|
pub steam_user: Option<SteamUsersInfo>,
|
||||||
pub steam_users: Option<Vec<SteamUsersInfo>>,
|
pub steam_users: Option<Vec<SteamUsersInfo>>,
|
||||||
|
|
||||||
pub image_to_replace: Option<ImageType>,
|
pub image_type_selected: Option<ImageType>,
|
||||||
pub image_options: Receiver<FetcStatus<Vec<PossibleImage>>>,
|
pub image_options: Receiver<FetcStatus<Vec<PossibleImage>>>,
|
||||||
|
|
||||||
pub image_handles: DashMap<String,egui::TextureHandle>,
|
pub image_handles: std::sync::Arc<DashMap<String, TextureState>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
pub enum TextureState {
|
||||||
pub struct PossibleImage{
|
Downloading,
|
||||||
|
Downloaded,
|
||||||
|
Loaded(egui::TextureHandle),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ImageSelectState {
|
||||||
|
pub fn has_multiple_users(&self) -> bool {
|
||||||
|
match &self.steam_users {
|
||||||
|
Some(users) => users.len() > 1,
|
||||||
|
None => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct PossibleImage {
|
||||||
thumbnail_path: PathBuf,
|
thumbnail_path: PathBuf,
|
||||||
full_url: String
|
thumbnail_url: String,
|
||||||
|
full_url: String,
|
||||||
|
id: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ImageSelectState {
|
impl Default for ImageSelectState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
selected_image: Default::default(),
|
selected_shortcut: Default::default(),
|
||||||
grid_id: Default::default(),
|
grid_id: Default::default(),
|
||||||
hero_image: Default::default(),
|
hero_image: Default::default(),
|
||||||
grid_image: Default::default(),
|
grid_image: Default::default(),
|
||||||
@@ -49,209 +69,237 @@ impl Default for ImageSelectState {
|
|||||||
wide_image: Default::default(),
|
wide_image: Default::default(),
|
||||||
steam_user: Default::default(),
|
steam_user: Default::default(),
|
||||||
steam_users: Default::default(),
|
steam_users: Default::default(),
|
||||||
image_to_replace: Default::default(),
|
image_type_selected: Default::default(),
|
||||||
image_options: watch::channel(FetcStatus::NeedsFetched).1,
|
image_options: watch::channel(FetcStatus::NeedsFetched).1,
|
||||||
image_handles: DashMap::new()
|
image_handles: Arc::new(DashMap::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum UserAction {
|
||||||
|
UserSelected(SteamUsersInfo),
|
||||||
|
ShortcutSelected(ShortcutOwned),
|
||||||
|
ImageTypeSelected(ImageType),
|
||||||
|
ImageSelected(PossibleImage),
|
||||||
|
GridIdChanged(usize),
|
||||||
|
BackButton,
|
||||||
|
NoAction,
|
||||||
|
}
|
||||||
|
|
||||||
impl MyEguiApp {
|
impl MyEguiApp {
|
||||||
|
fn render_ui_image_action(&self, ui: &mut egui::Ui) -> UserAction {
|
||||||
|
let state = &self.image_selected_state;
|
||||||
|
ui.heading("Images");
|
||||||
|
if (state.selected_shortcut.is_some() || state.has_multiple_users())
|
||||||
|
&& ui.button("Back").clicked()
|
||||||
|
{
|
||||||
|
return UserAction::BackButton;
|
||||||
|
}
|
||||||
|
if state.steam_user.is_none() {
|
||||||
|
return render_user_select(state, ui);
|
||||||
|
}
|
||||||
|
if let Some(shortcut) = state.selected_shortcut.as_ref() {
|
||||||
|
ui.heading(&shortcut.app_name);
|
||||||
|
if let Some(image_type) = state.image_type_selected.as_ref() {
|
||||||
|
if let Some(action) = self.render_possible_images(ui, image_type, state) {
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
} else if let Some(action) = render_shortcut_images(ui, state) {
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
} else if let Some(action) = self.render_shortcut_select(ui) {
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
UserAction::NoAction
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_shortcut_select(&self, ui: &mut egui::Ui) -> Option<UserAction> {
|
||||||
|
match &*self.games_to_sync.borrow() {
|
||||||
|
FetcStatus::Fetched(shortcuts) => {
|
||||||
|
for (platform_name, shortcuts) in shortcuts {
|
||||||
|
ui.heading(platform_name);
|
||||||
|
for shortcut in shortcuts {
|
||||||
|
if ui.button(&shortcut.app_name).clicked() {
|
||||||
|
return Some(UserAction::ShortcutSelected(shortcut.clone()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
ui.ctx().request_repaint();
|
||||||
|
ui.label("Finding installed games");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_possible_images(
|
||||||
|
&self,
|
||||||
|
ui: &mut egui::Ui,
|
||||||
|
image_type: &ImageType,
|
||||||
|
state: &ImageSelectState,
|
||||||
|
) -> Option<UserAction> {
|
||||||
|
ui.heading(image_type.name());
|
||||||
|
|
||||||
|
match &*state.image_options.borrow() {
|
||||||
|
FetcStatus::Fetched(images) => {
|
||||||
|
for image in images {
|
||||||
|
let image_key = image.thumbnail_path.as_path().to_string_lossy().to_string();
|
||||||
|
|
||||||
|
match state.image_handles.get_mut(&image_key) {
|
||||||
|
Some(mut state) => {
|
||||||
|
match state.value() {
|
||||||
|
TextureState::Downloading => {
|
||||||
|
ui.ctx().request_repaint();
|
||||||
|
//nothing to do,just wait
|
||||||
|
ui.label(format!("Downloading id {}", image.id));
|
||||||
|
}
|
||||||
|
TextureState::Downloaded => {
|
||||||
|
//Need to load
|
||||||
|
let image_data =
|
||||||
|
load_image_from_path(&image.thumbnail_path).unwrap();
|
||||||
|
let handle = ui.ctx().load_texture(&image_key, image_data);
|
||||||
|
*state.value_mut() = TextureState::Loaded(handle);
|
||||||
|
ui.ctx().request_repaint();
|
||||||
|
ui.label("Loading");
|
||||||
|
}
|
||||||
|
TextureState::Loaded(texture_handle) => {
|
||||||
|
//need to show
|
||||||
|
let mut size = texture_handle.size_vec2();
|
||||||
|
clamp_to_width(&mut size, MAX_WIDTH);
|
||||||
|
let image_button = ImageButton::new(texture_handle, size);
|
||||||
|
if ui.add(image_button).clicked() {
|
||||||
|
return Some(UserAction::ImageSelected(image.clone()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
//We need to start a download
|
||||||
|
let image_handles = &self.image_selected_state.image_handles;
|
||||||
|
let path = &image.thumbnail_path;
|
||||||
|
if !path.exists() {
|
||||||
|
image_handles.insert(image_key.clone(), TextureState::Downloading);
|
||||||
|
let to_download = ToDownload {
|
||||||
|
path: path.clone(),
|
||||||
|
url: image.thumbnail_url.clone(),
|
||||||
|
app_name: "Thumbnail".to_string(),
|
||||||
|
image_type: *image_type,
|
||||||
|
};
|
||||||
|
let image_handles = image_handles.clone();
|
||||||
|
let image_key = image_key.clone();
|
||||||
|
self.rt.spawn_blocking(move || {
|
||||||
|
block_on(crate::steamgriddb::download_to_download(
|
||||||
|
&to_download,
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
image_handles.insert(image_key, TextureState::Downloaded);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
image_handles.insert(image_key.clone(), TextureState::Downloaded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
ui.label("Finding possible images");
|
||||||
|
ui.ctx().request_repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ensure_steam_users_loaded(&mut self) {
|
||||||
|
self.image_selected_state
|
||||||
|
.steam_users
|
||||||
|
.get_or_insert_with(|| {
|
||||||
|
get_shortcuts_paths(&self.settings.steam).expect("Should have steam user")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn render_ui_images(&mut self, ui: &mut egui::Ui) {
|
pub(crate) fn render_ui_images(&mut self, ui: &mut egui::Ui) {
|
||||||
self.ensure_games_loaded();
|
self.ensure_games_loaded();
|
||||||
|
self.ensure_steam_users_loaded();
|
||||||
|
|
||||||
ui.heading("Images");
|
let mut action = UserAction::NoAction;
|
||||||
|
|
||||||
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()
|
ScrollArea::vertical()
|
||||||
.stick_to_right()
|
.stick_to_right()
|
||||||
.auto_shrink([false, true])
|
.auto_shrink([false, true])
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
ui.reset_style();
|
ui.reset_style();
|
||||||
let borrowed_games = &*self.games_to_sync.borrow();
|
action = self.render_ui_image_action(ui);
|
||||||
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));
|
|
||||||
});
|
});
|
||||||
|
match action {
|
||||||
|
UserAction::UserSelected(user) => {
|
||||||
|
self.handle_user_selected(user);
|
||||||
|
}
|
||||||
|
UserAction::ShortcutSelected(shortcut) => {
|
||||||
|
self.handle_shortcut_selected(shortcut, ui);
|
||||||
|
}
|
||||||
|
UserAction::ImageTypeSelected(image_type) => {
|
||||||
|
self.handle_image_type_selected(image_type);
|
||||||
|
}
|
||||||
|
UserAction::ImageSelected(image) => {
|
||||||
|
self.handle_image_selected(image);
|
||||||
|
}
|
||||||
|
UserAction::BackButton => {
|
||||||
|
let state = &mut self.image_selected_state;
|
||||||
|
handle_back_button_action(state);
|
||||||
|
}
|
||||||
|
UserAction::GridIdChanged(grid_id) => {
|
||||||
|
self.handle_grid_change(grid_id);
|
||||||
|
}
|
||||||
|
|
||||||
let image_ref = match selected_image_type {
|
UserAction::NoAction => {}
|
||||||
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() {
|
fn handle_grid_change(&mut self, grid_id: usize) {
|
||||||
ui.label(image_type.name());
|
self.image_selected_state.grid_id = Some(grid_id);
|
||||||
|
if let Some(auth_key) = &self.settings.steamgrid_db.auth_key {
|
||||||
|
let client = steamgriddb_api::Client::new(auth_key);
|
||||||
|
let mut cache = CachedSearch::new(&client);
|
||||||
|
if let Some(shortcut) = &self.image_selected_state.selected_shortcut {
|
||||||
|
cache.set_cache(shortcut.app_id, shortcut.app_name.clone(), grid_id);
|
||||||
|
cache.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let image_ref = match image_type {
|
fn handle_user_selected(&mut self, user: SteamUsersInfo) {
|
||||||
ImageType::Hero => {
|
let state = &mut self.image_selected_state;
|
||||||
&mut self.image_selected_state.hero_image
|
state.steam_user = Some(user);
|
||||||
}
|
}
|
||||||
ImageType::Grid => {
|
|
||||||
&mut self.image_selected_state.grid_image
|
fn handle_image_type_selected(&mut self, image_type: ImageType) {
|
||||||
}
|
let state = &mut self.image_selected_state;
|
||||||
ImageType::WideGrid => {
|
state.image_type_selected = Some(image_type);
|
||||||
&mut self.image_selected_state.wide_image
|
let (tx, rx) = watch::channel(FetcStatus::Fetching);
|
||||||
}
|
|
||||||
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;
|
self.image_selected_state.image_options = rx;
|
||||||
let settings = self.settings.clone();
|
let settings = self.settings.clone();
|
||||||
if let Some(auth_key) = settings.steamgrid_db.auth_key{
|
if let Some(auth_key) = settings.steamgrid_db.auth_key {
|
||||||
if let Some(grid_id) = self.image_selected_state.grid_id{
|
if let Some(grid_id) = self.image_selected_state.grid_id {
|
||||||
let auth_key = auth_key.clone();
|
let auth_key = auth_key;
|
||||||
let image_type = image_type.clone();
|
let image_type = image_type;
|
||||||
let app_name = selected_image.app_name.clone();
|
self.rt.spawn_blocking(move || {
|
||||||
self.rt.spawn_blocking( move|| {
|
|
||||||
//Find somewhere else to put this
|
//Find somewhere else to put this
|
||||||
std::fs::create_dir_all(".thumbnails");
|
let _ = std::fs::create_dir_all(".thumbnails");
|
||||||
let thumbnails_folder = Path::new(".thumbnails");
|
let thumbnails_folder = Path::new(".thumbnails");
|
||||||
let client =steamgriddb_api::Client::new(auth_key);
|
let client = steamgriddb_api::Client::new(auth_key);
|
||||||
let query = get_query_type(false,&image_type);
|
let query = get_query_type(false, &image_type);
|
||||||
let search_res = block_on(client.get_images_for_id(grid_id, &query));
|
let search_res = block_on(client.get_images_for_id(grid_id, &query));
|
||||||
|
if let Ok(possible_images) = search_res {
|
||||||
if let Ok(possible_images) = search_res{
|
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
for possible_image in &possible_images{
|
for possible_image in &possible_images {
|
||||||
let path = thumbnails_folder.join(format!("{}.png",possible_image.id));
|
let path = thumbnails_folder.join(format!("{}.png", possible_image.id));
|
||||||
|
result.push(PossibleImage {
|
||||||
if !&path.exists(){
|
thumbnail_path: path,
|
||||||
let to_download = ToDownload{
|
thumbnail_url: possible_image.thumb.clone(),
|
||||||
path: path.clone(),
|
full_url: possible_image.url.clone(),
|
||||||
url: possible_image.thumb.clone(),
|
id: possible_image.id,
|
||||||
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()));
|
let _ = tx.send(FetcStatus::Fetched(result.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -259,119 +307,131 @@ impl MyEguiApp {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_image_selected(&mut self, image: PossibleImage) {
|
||||||
|
//We must have a user here
|
||||||
|
let user = self.image_selected_state.steam_user.as_ref().unwrap();
|
||||||
|
let selected_image_type = self
|
||||||
|
.image_selected_state
|
||||||
|
.image_type_selected
|
||||||
|
.as_ref()
|
||||||
|
.unwrap();
|
||||||
|
let selected_image = self
|
||||||
|
.image_selected_state
|
||||||
|
.selected_shortcut
|
||||||
|
.as_ref()
|
||||||
|
.unwrap();
|
||||||
|
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,
|
||||||
|
image_type: *selected_image_type,
|
||||||
|
};
|
||||||
|
//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,
|
||||||
|
};
|
||||||
|
let image_key = image.thumbnail_path.as_path().to_string_lossy().to_string();
|
||||||
|
let texture_handle = self
|
||||||
|
.image_selected_state
|
||||||
|
.image_handles
|
||||||
|
.get(&image_key)
|
||||||
|
.unwrap();
|
||||||
|
if let TextureState::Loaded(texture_handle) = texture_handle.value() {
|
||||||
|
*image_ref = Some(texture_handle.clone());
|
||||||
}
|
}
|
||||||
}
|
self.image_selected_state.image_type_selected = None;
|
||||||
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_options = watch::channel(FetcStatus::NeedsFetched).1;
|
||||||
self.image_selected_state.image_handles.clear();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
None => {
|
fn handle_shortcut_selected(&mut self, shortcut: ShortcutOwned, ui: &mut egui::Ui) {
|
||||||
for (platform_name, shortcuts) in games_to_sync {
|
let state = &mut self.image_selected_state;
|
||||||
ui.heading(platform_name);
|
//We must have a user to make see this action;
|
||||||
for shortcut in shortcuts {
|
let user = state.steam_user.as_ref().unwrap();
|
||||||
if ui.button(&shortcut.app_name).clicked() {
|
if let Some(auth_key) = &self.settings.steamgrid_db.auth_key {
|
||||||
if let Some(auth_key) =
|
let client = steamgriddb_api::Client::new(auth_key);
|
||||||
&self.settings.steamgrid_db.auth_key
|
|
||||||
{
|
|
||||||
let client =
|
|
||||||
steamgriddb_api::Client::new(auth_key);
|
|
||||||
let search = CachedSearch::new(&client);
|
let search = CachedSearch::new(&client);
|
||||||
//TODO make this multithreaded
|
//TODO make this multithreaded
|
||||||
self.image_selected_state.grid_id = self
|
state.grid_id = self
|
||||||
.rt
|
.rt
|
||||||
.block_on(search.search(
|
.block_on(search.search(shortcut.app_id, &shortcut.app_name))
|
||||||
shortcut.app_id,
|
|
||||||
&shortcut.app_name,
|
|
||||||
))
|
|
||||||
.ok()
|
.ok()
|
||||||
.flatten();
|
.flatten();
|
||||||
}
|
}
|
||||||
|
state.selected_shortcut = Some(shortcut.clone());
|
||||||
self.image_selected_state.selected_image =
|
let folder = Path::new(&user.steam_user_data_folder)
|
||||||
Some(shortcut.clone());
|
|
||||||
|
|
||||||
let folder =
|
|
||||||
Path::new(&user.steam_user_data_folder)
|
|
||||||
.join("config")
|
.join("config")
|
||||||
.join("grid");
|
.join("grid");
|
||||||
|
|
||||||
//TODO put this in seperate thread
|
//TODO put this in seperate thread
|
||||||
self.image_selected_state.hero_image =
|
state.hero_image = get_image(ui, &shortcut, &folder, &ImageType::Hero);
|
||||||
get_image(
|
state.grid_image = get_image(ui, &shortcut, &folder, &ImageType::Grid);
|
||||||
ui,
|
state.icon_image = get_image(ui, &shortcut, &folder, &ImageType::Icon);
|
||||||
shortcut,
|
state.logo_image = get_image(ui, &shortcut, &folder, &ImageType::Logo);
|
||||||
&folder,
|
state.wide_image = get_image(ui, &shortcut, &folder, &ImageType::WideGrid);
|
||||||
&ImageType::Hero,
|
state.selected_shortcut = Some(shortcut);
|
||||||
);
|
|
||||||
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_shortcut_images(ui: &mut egui::Ui, state: &ImageSelectState) -> Option<UserAction> {
|
||||||
|
let mut grid_id_text = state.grid_id.map(|id| id.to_string()).unwrap_or_default();
|
||||||
|
if ui.text_edit_singleline(&mut grid_id_text).changed() {
|
||||||
|
if let Ok(grid_id) = grid_id_text.parse::<usize>() {
|
||||||
|
return Some(UserAction::GridIdChanged(grid_id));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
for image_type in ImageType::all() {
|
||||||
|
ui.label(image_type.name());
|
||||||
|
let image_ref = get_image_ref(image_type, state);
|
||||||
|
if render_thumbnail(ui, image_ref) {
|
||||||
|
return Some(UserAction::ImageTypeSelected(*image_type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
fn render_image(ui: &mut egui::Ui, image: &mut Option<egui::TextureHandle>) -> bool {
|
fn render_user_select(state: &ImageSelectState, ui: &mut egui::Ui) -> UserAction {
|
||||||
|
let users = state.steam_users.as_ref().unwrap();
|
||||||
|
if users.len() == 1 {
|
||||||
|
return UserAction::UserSelected(users[0].clone());
|
||||||
|
}
|
||||||
|
for user in users {
|
||||||
|
if ui.button(&user.user_id).clicked() {
|
||||||
|
return UserAction::UserSelected(user.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UserAction::NoAction
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_back_button_action(state: &mut ImageSelectState) {
|
||||||
|
if state.image_type_selected.is_some() {
|
||||||
|
state.image_type_selected = None;
|
||||||
|
} else if state.selected_shortcut.is_some() {
|
||||||
|
state.selected_shortcut = None;
|
||||||
|
} else {
|
||||||
|
state.steam_user = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const MAX_WIDTH: f32 = 300.;
|
||||||
|
|
||||||
|
fn render_thumbnail(ui: &mut egui::Ui, image: &Option<egui::TextureHandle>) -> bool {
|
||||||
match image {
|
match image {
|
||||||
Some(texture) => {
|
Some(texture) => {
|
||||||
let mut size = texture.size_vec2();
|
let mut size = texture.size_vec2();
|
||||||
clamp_to_width(&mut size,MAX_WIDTH);
|
clamp_to_width(&mut size, MAX_WIDTH);
|
||||||
let image_button = ImageButton::new(texture, size);
|
let image_button = ImageButton::new(texture, size);
|
||||||
ui.add(image_button)
|
ui.add(image_button)
|
||||||
.on_hover_text("Click to change image")
|
.on_hover_text("Click to change image")
|
||||||
@@ -381,10 +441,10 @@ fn render_image(ui: &mut egui::Ui, image: &mut Option<egui::TextureHandle>) -> b
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clamp_to_width(size: &mut egui::Vec2, max_width :f32) {
|
fn clamp_to_width(size: &mut egui::Vec2, max_width: f32) {
|
||||||
let mut x = size.x;
|
let mut x = size.x;
|
||||||
let mut y = size.y;
|
let mut y = size.y;
|
||||||
if size.x > max_width{
|
if size.x > max_width {
|
||||||
let ratio = size.y / size.x;
|
let ratio = size.y / size.x;
|
||||||
x = max_width;
|
x = max_width;
|
||||||
y = x * ratio;
|
y = x * ratio;
|
||||||
@@ -407,3 +467,17 @@ fn get_image(
|
|||||||
});
|
});
|
||||||
image
|
image
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_image_ref<'a>(
|
||||||
|
image_type: &ImageType,
|
||||||
|
state: &'a ImageSelectState,
|
||||||
|
) -> &'a Option<TextureHandle> {
|
||||||
|
match image_type {
|
||||||
|
ImageType::Hero => &state.hero_image,
|
||||||
|
ImageType::Grid => &state.grid_image,
|
||||||
|
ImageType::WideGrid => &state.wide_image,
|
||||||
|
ImageType::Logo => &state.logo_image,
|
||||||
|
ImageType::BigPicture => &state.wide_image,
|
||||||
|
ImageType::Icon => &state.icon_image,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ impl MyEguiApp {
|
|||||||
ui.label("Check the settings if BoilR didn't find the game you where looking for");
|
ui.label("Check the settings if BoilR didn't find the game you where looking for");
|
||||||
},
|
},
|
||||||
_=> {
|
_=> {
|
||||||
|
ui.ctx().request_repaint();
|
||||||
ui.label("Finding installed games");
|
ui.label("Finding installed games");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -130,6 +130,9 @@ impl epi::App for MyEguiApp {
|
|||||||
}
|
}
|
||||||
SyncProgress::Done => ("Done importing games".to_string(), false),
|
SyncProgress::Done => ("Done importing games".to_string(), false),
|
||||||
};
|
};
|
||||||
|
if syncing {
|
||||||
|
ui.ctx().request_repaint();
|
||||||
|
}
|
||||||
if !status_string.is_empty() {
|
if !status_string.is_empty() {
|
||||||
ui.label(status_string);
|
ui.label(status_string);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user