mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Image UI handles restructure (#294)
* Move handle_grid_change into grid page * Move handle_correct_grid_request into page * Move handle_shortcut_select into page * Do not include openssl on windows * Remove unused imports * Move user select into seperate component * Move handle image selected to page * Make gog use linux cfg
This commit is contained in:
+3
-2
@@ -14,8 +14,6 @@ nom = "^7.1.1"
|
|||||||
rusty-leveldb = "^1.0.4"
|
rusty-leveldb = "^1.0.4"
|
||||||
serde_json = "^1.0.91"
|
serde_json = "^1.0.91"
|
||||||
|
|
||||||
openssl = { version = "*", features = ["vendored"] }
|
|
||||||
|
|
||||||
steam_shortcuts_util = "^1.1.8"
|
steam_shortcuts_util = "^1.1.8"
|
||||||
steamgriddb_api = "^0.3.1"
|
steamgriddb_api = "^0.3.1"
|
||||||
sysinfo = "^0.27.1"
|
sysinfo = "^0.27.1"
|
||||||
@@ -23,6 +21,9 @@ eyre = "^0.6.8"
|
|||||||
color-eyre = "^0.6.2"
|
color-eyre = "^0.6.2"
|
||||||
dyn-clone = "^1.0.10"
|
dyn-clone = "^1.0.10"
|
||||||
|
|
||||||
|
[target."cfg(not(windows))".dependencies]
|
||||||
|
openssl = { version = "*", features = ["vendored"] }
|
||||||
|
|
||||||
[dependencies.dashmap]
|
[dependencies.dashmap]
|
||||||
features = ["serde"]
|
features = ["serde"]
|
||||||
version = "^5.4.0"
|
version = "^5.4.0"
|
||||||
|
|||||||
@@ -25,8 +25,12 @@ mod uplay;
|
|||||||
mod egs;
|
mod egs;
|
||||||
pub(crate) use platform::*;
|
pub(crate) use platform::*;
|
||||||
|
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
pub(crate) use gog::get_gog_shortcuts_from_game_folders;
|
pub(crate) use gog::get_gog_shortcuts_from_game_folders;
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
pub(crate) use gog::GogShortcut;
|
pub(crate) use gog::GogShortcut;
|
||||||
|
|
||||||
|
|
||||||
pub use platforms_load::get_platforms;
|
pub use platforms_load::get_platforms;
|
||||||
pub(crate) use platforms_load::load_settings;
|
pub(crate) use platforms_load::load_settings;
|
||||||
pub(crate) use platforms_load::FromSettingsString;
|
pub(crate) use platforms_load::FromSettingsString;
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
mod steam_user_select;
|
||||||
|
|
||||||
|
pub use steam_user_select::render_user_select;
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
use crate::steam::SteamUsersInfo;
|
||||||
|
|
||||||
|
pub fn render_user_select<'a>(
|
||||||
|
steam_user: Option<&'a SteamUsersInfo>,
|
||||||
|
steam_users: &'a [SteamUsersInfo],
|
||||||
|
ui: &mut egui::Ui,
|
||||||
|
) -> Option<&'a SteamUsersInfo> {
|
||||||
|
if steam_user.is_none() {
|
||||||
|
if steam_users.len() > 0 {
|
||||||
|
return Some(&steam_users[0]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let mut selected_user = steam_user.as_ref().unwrap().clone();
|
||||||
|
let id_before = selected_user.user_id.clone();
|
||||||
|
if steam_users.len() > 0 {
|
||||||
|
let combo_box = egui::ComboBox::new("ImageUserSelect", "")
|
||||||
|
.selected_text(format!("Steam user id: {}", &selected_user.user_id));
|
||||||
|
combo_box.show_ui(ui, |ui| {
|
||||||
|
for user in steam_users {
|
||||||
|
ui.selectable_value(&mut selected_user, &user, &user.user_id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let id_now = selected_user.user_id.clone();
|
||||||
|
if !id_before.eq(&id_now) {
|
||||||
|
return Some(selected_user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
use crate::ui::images::{image_select_state::ImageSelectState, useraction::UserAction};
|
use crate::{
|
||||||
|
steamgriddb::CachedSearch,
|
||||||
|
ui::{
|
||||||
|
images::{image_select_state::ImageSelectState, useraction::UserAction},
|
||||||
|
MyEguiApp,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
pub fn render_page_change_grid_db_id(
|
pub fn render_page_change_grid_db_id(
|
||||||
possible_names: &Vec<steamgriddb_api::search::SearchResult>,
|
possible_names: &Vec<steamgriddb_api::search::SearchResult>,
|
||||||
@@ -31,3 +36,35 @@ pub fn render_page_change_grid_db_id(
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn handle_grid_change(app: &mut MyEguiApp, grid_id: usize) {
|
||||||
|
app.image_selected_state.grid_id = Some(grid_id);
|
||||||
|
app.image_selected_state.possible_names = None;
|
||||||
|
if let Some(auth_key) = &app.settings.steamgrid_db.auth_key {
|
||||||
|
let client = steamgriddb_api::Client::new(auth_key);
|
||||||
|
let mut cache = CachedSearch::new(&client);
|
||||||
|
if let Some(shortcut) = &app.image_selected_state.selected_shortcut {
|
||||||
|
cache.set_cache(shortcut.app_id(), shortcut.name(), grid_id);
|
||||||
|
cache.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn handle_correct_grid_request(app:&mut MyEguiApp) {
|
||||||
|
let app_name = app
|
||||||
|
.image_selected_state
|
||||||
|
.selected_shortcut
|
||||||
|
.as_ref()
|
||||||
|
.map(|s| s.name())
|
||||||
|
.unwrap_or_default();
|
||||||
|
let auth_key = app
|
||||||
|
.settings
|
||||||
|
.steamgrid_db
|
||||||
|
.auth_key
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_default();
|
||||||
|
let client = steamgriddb_api::Client::new(&auth_key);
|
||||||
|
let search_results = app.rt.block_on(client.search(app_name));
|
||||||
|
app.image_selected_state.possible_names = search_results.ok();
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,15 @@ mod pick_new_image;
|
|||||||
|
|
||||||
|
|
||||||
pub use change_grid_db_id::render_page_change_grid_db_id;
|
pub use change_grid_db_id::render_page_change_grid_db_id;
|
||||||
|
pub use change_grid_db_id::handle_grid_change;
|
||||||
|
pub use change_grid_db_id::handle_correct_grid_request;
|
||||||
|
|
||||||
pub use shortcut_images_overview::render_page_shortcut_images_overview;
|
pub use shortcut_images_overview::render_page_shortcut_images_overview;
|
||||||
|
pub use shortcut_images_overview::handle_shortcut_selected;
|
||||||
|
|
||||||
pub use steam_images_overview::render_page_steam_images_overview;
|
pub use steam_images_overview::render_page_steam_images_overview;
|
||||||
pub use select_image_type::render_page_shortcut_select_image_type;
|
pub use select_image_type::render_page_shortcut_select_image_type;
|
||||||
|
|
||||||
pub use pick_new_image::render_page_pick_image;
|
pub use pick_new_image::render_page_pick_image;
|
||||||
|
|
||||||
|
pub use pick_new_image::handle_image_selected;
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use egui::{Grid, ImageButton};
|
use egui::{Grid, ImageButton};
|
||||||
use futures::executor::block_on;
|
use futures::executor::block_on;
|
||||||
|
use tokio::sync::watch;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
steamgriddb::{ImageType, ToDownload},
|
steamgriddb::{get_image_extension, ImageType, ToDownload},
|
||||||
ui::{
|
ui::{
|
||||||
images::{
|
images::{
|
||||||
constants::MAX_WIDTH, image_resize::clamp_to_width,
|
constants::MAX_WIDTH, image_resize::clamp_to_width,
|
||||||
image_select_state::ImageSelectState, texturestate::TextureDownloadState,
|
image_select_state::ImageSelectState, possible_image::PossibleImage,
|
||||||
useraction::UserAction,
|
texturestate::TextureDownloadState, useraction::UserAction, hasimagekey::HasImageKey,
|
||||||
},
|
},
|
||||||
ui_images::load_image_from_path,
|
ui_images::load_image_from_path,
|
||||||
FetcStatus, MyEguiApp,
|
FetcStatus, MyEguiApp,
|
||||||
@@ -163,3 +166,86 @@ pub fn render_page_pick_image(
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn handle_image_selected(app: &mut MyEguiApp, image: PossibleImage) {
|
||||||
|
//We must have a user here
|
||||||
|
let user = app.image_selected_state.steam_user.as_ref().unwrap();
|
||||||
|
let selected_image_type = app
|
||||||
|
.image_selected_state
|
||||||
|
.image_type_selected
|
||||||
|
.as_ref()
|
||||||
|
.unwrap();
|
||||||
|
let selected_shortcut = app.image_selected_state.selected_shortcut.as_ref().unwrap();
|
||||||
|
|
||||||
|
let ext = get_image_extension(&image.mime);
|
||||||
|
let to_download_to_path = Path::new(&user.steam_user_data_folder)
|
||||||
|
.join("config")
|
||||||
|
.join("grid")
|
||||||
|
.join(selected_image_type.file_name(selected_shortcut.app_id(), ext));
|
||||||
|
|
||||||
|
//Delete old possible images
|
||||||
|
|
||||||
|
let data_folder = Path::new(&user.steam_user_data_folder);
|
||||||
|
|
||||||
|
//Keep deleting images of this type untill we don't find any more
|
||||||
|
let mut path = get_shortcut_image_path(app,data_folder);
|
||||||
|
while Path::new(&path).exists() {
|
||||||
|
let _ = std::fs::remove_file(&path);
|
||||||
|
path = get_shortcut_image_path(app,data_folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Put the loaded thumbnail into the image handler map, we can use that for preview
|
||||||
|
let full_image_key = to_download_to_path.to_string_lossy().to_string();
|
||||||
|
let _ = app
|
||||||
|
.image_selected_state
|
||||||
|
.image_handles
|
||||||
|
.remove(&full_image_key);
|
||||||
|
let thumbnail_key = image.thumbnail_path.to_string_lossy().to_string();
|
||||||
|
let thumbnail = app
|
||||||
|
.image_selected_state
|
||||||
|
.image_handles
|
||||||
|
.remove(&thumbnail_key);
|
||||||
|
if let Some((_key, thumbnail)) = thumbnail {
|
||||||
|
app.image_selected_state
|
||||||
|
.image_handles
|
||||||
|
.insert(full_image_key, thumbnail);
|
||||||
|
}
|
||||||
|
|
||||||
|
let app_name = selected_shortcut.name();
|
||||||
|
let to_download = ToDownload {
|
||||||
|
path: to_download_to_path,
|
||||||
|
url: image.full_url.clone(),
|
||||||
|
app_name: app_name.to_string(),
|
||||||
|
image_type: *selected_image_type,
|
||||||
|
};
|
||||||
|
app.rt.spawn_blocking(move || {
|
||||||
|
let _ = block_on(crate::steamgriddb::download_to_download(&to_download));
|
||||||
|
});
|
||||||
|
|
||||||
|
clear_loaded_images(app);
|
||||||
|
{
|
||||||
|
app.image_selected_state.image_type_selected = None;
|
||||||
|
app.image_selected_state.image_options = watch::channel(FetcStatus::NeedsFetched).1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_shortcut_image_path(app:&MyEguiApp, data_folder: &Path) -> String {
|
||||||
|
app.image_selected_state
|
||||||
|
.selected_shortcut
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.key(
|
||||||
|
&app.image_selected_state.image_type_selected.unwrap(),
|
||||||
|
data_folder,
|
||||||
|
)
|
||||||
|
.1
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clear_loaded_images(app: &mut MyEguiApp) {
|
||||||
|
if let FetcStatus::Fetched(options) = &*app.image_selected_state.image_options.borrow() {
|
||||||
|
for option in options {
|
||||||
|
let key = option.thumbnail_path.to_string_lossy().to_string();
|
||||||
|
app.image_selected_state.image_handles.remove(&key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ use steam_shortcuts_util::shortcut::ShortcutOwned;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
steam::SteamUsersInfo,
|
steam::SteamUsersInfo,
|
||||||
steamgriddb::ImageType,
|
steamgriddb::{ImageType, CachedSearch},
|
||||||
ui::{
|
ui::{
|
||||||
images::{
|
images::{
|
||||||
gametype::GameType, hasimagekey::HasImageKey, image_resize::clamp_to_width,
|
gametype::GameType, hasimagekey::HasImageKey, image_resize::clamp_to_width,
|
||||||
texturestate::TextureDownloadState, useraction::UserAction,
|
texturestate::TextureDownloadState, useraction::UserAction,
|
||||||
},
|
},
|
||||||
MyEguiApp,
|
MyEguiApp, ui_images::load_image_from_path,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -93,3 +93,32 @@ fn render_image(
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
pub fn handle_shortcut_selected(app: &mut MyEguiApp, shortcut: GameType, ui: &mut egui::Ui) {
|
||||||
|
let state = &mut app.image_selected_state;
|
||||||
|
//We must have a user to make see this action;
|
||||||
|
let user = state.steam_user.as_ref().unwrap();
|
||||||
|
if let Some(auth_key) = &app.settings.steamgrid_db.auth_key {
|
||||||
|
let client = steamgriddb_api::Client::new(auth_key);
|
||||||
|
let search = CachedSearch::new(&client);
|
||||||
|
state.grid_id = app
|
||||||
|
.rt
|
||||||
|
.block_on(search.search(shortcut.app_id(), shortcut.name()))
|
||||||
|
.ok()
|
||||||
|
.flatten();
|
||||||
|
}
|
||||||
|
state.selected_shortcut = Some(shortcut.clone());
|
||||||
|
|
||||||
|
for image_type in ImageType::all() {
|
||||||
|
let (path, key) = shortcut.key(image_type, Path::new(&user.steam_user_data_folder));
|
||||||
|
let image = load_image_from_path(&path);
|
||||||
|
if let Ok(image) = image {
|
||||||
|
let texture = ui
|
||||||
|
.ctx()
|
||||||
|
.load_texture(&key, image, egui::TextureOptions::LINEAR);
|
||||||
|
state
|
||||||
|
.image_handles
|
||||||
|
.insert(key, TextureDownloadState::Loaded(texture));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state.selected_shortcut = Some(shortcut);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,24 +1,33 @@
|
|||||||
use super::{texturestate::TextureDownloadState, gamemode::GameMode, possible_image::PossibleImage, gametype::GameType, pages::{render_page_shortcut_images_overview, render_page_steam_images_overview, render_page_pick_image, render_page_shortcut_select_image_type}, useraction::UserAction, constants::POSSIBLE_EXTENSIONS, hasimagekey::HasImageKey, image_select_state::ImageSelectState};
|
use super::{
|
||||||
|
constants::POSSIBLE_EXTENSIONS,
|
||||||
use std::{
|
gamemode::GameMode,
|
||||||
path::{Path},
|
hasimagekey::HasImageKey,
|
||||||
|
image_select_state::ImageSelectState,
|
||||||
|
pages::{
|
||||||
|
handle_correct_grid_request, handle_grid_change, handle_shortcut_selected,
|
||||||
|
render_page_pick_image, render_page_shortcut_images_overview,
|
||||||
|
render_page_shortcut_select_image_type, render_page_steam_images_overview, handle_image_selected,
|
||||||
|
},
|
||||||
|
possible_image::PossibleImage,
|
||||||
|
texturestate::TextureDownloadState,
|
||||||
|
useraction::UserAction,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::get_thumbnails_folder,
|
config::get_thumbnails_folder,
|
||||||
steam::{get_installed_games, SteamUsersInfo,},
|
steam::get_shortcuts_paths,
|
||||||
steam::{get_shortcuts_paths },
|
steam::{get_installed_games, SteamUsersInfo},
|
||||||
steamgriddb::{get_image_extension, get_query_type, CachedSearch, ImageType, ToDownload},
|
steamgriddb::{get_image_extension, get_query_type, ImageType},
|
||||||
sync::{download_images, SyncProgress}, ui::{MyEguiApp, FetcStatus, ui_images::load_image_from_path},
|
sync::{download_images, SyncProgress},
|
||||||
|
ui::{components::render_user_select, ui_images::load_image_from_path, FetcStatus, MyEguiApp},
|
||||||
};
|
};
|
||||||
use egui::{ScrollArea};
|
use egui::ScrollArea;
|
||||||
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;
|
use tokio::sync::watch;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl MyEguiApp {
|
impl MyEguiApp {
|
||||||
fn render_ui_image_action(&self, ui: &mut egui::Ui) -> UserAction {
|
fn render_ui_image_action(&self, ui: &mut egui::Ui) -> UserAction {
|
||||||
let state = &self.image_selected_state;
|
let state = &self.image_selected_state;
|
||||||
@@ -32,8 +41,13 @@ impl MyEguiApp {
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
if let Some(value) = render_user_select(state, ui) {
|
let users = state.steam_users.as_ref();
|
||||||
return Some(value);
|
if let Some(users) = users {
|
||||||
|
if let Some(value) =
|
||||||
|
render_user_select(state.steam_user.as_ref(), &users, ui)
|
||||||
|
{
|
||||||
|
return Some(UserAction::UserSelected(value.clone()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
render_shortcut_mode_select(state, ui)
|
render_shortcut_mode_select(state, ui)
|
||||||
}
|
}
|
||||||
@@ -47,11 +61,13 @@ impl MyEguiApp {
|
|||||||
ui.heading(shortcut.name());
|
ui.heading(shortcut.name());
|
||||||
|
|
||||||
if let Some(possible_names) = state.possible_names.as_ref() {
|
if let Some(possible_names) = state.possible_names.as_ref() {
|
||||||
if let Some(value) = super::pages::render_page_change_grid_db_id(possible_names, ui, state) {
|
if let Some(value) =
|
||||||
|
super::pages::render_page_change_grid_db_id(possible_names, ui, state)
|
||||||
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
} else if let Some(image_type) = state.image_type_selected.as_ref() {
|
} else if let Some(image_type) = state.image_type_selected.as_ref() {
|
||||||
if let Some(action) = render_page_pick_image(&self,ui, image_type, state) {
|
if let Some(action) = render_page_pick_image(&self, ui, image_type, state) {
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
} else if let Some(action) = render_page_shortcut_select_image_type(ui, state) {
|
} else if let Some(action) = render_page_shortcut_select_image_type(ui, state) {
|
||||||
@@ -60,7 +76,7 @@ impl MyEguiApp {
|
|||||||
} else {
|
} else {
|
||||||
let is_shortcut = state.game_mode.is_shortcuts();
|
let is_shortcut = state.game_mode.is_shortcuts();
|
||||||
if is_shortcut {
|
if is_shortcut {
|
||||||
if let Some(action) = render_page_shortcut_images_overview(&self,ui) {
|
if let Some(action) = render_page_shortcut_images_overview(&self, ui) {
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
} else if let Some(action) = render_page_steam_images_overview(ui, state) {
|
} else if let Some(action) = render_page_steam_images_overview(ui, state) {
|
||||||
@@ -100,9 +116,6 @@ impl MyEguiApp {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn ensure_steam_users_loaded(&mut self) {
|
fn ensure_steam_users_loaded(&mut self) {
|
||||||
if self.image_selected_state.settings_error.is_none()
|
if self.image_selected_state.settings_error.is_none()
|
||||||
&& self.image_selected_state.steam_users.is_none()
|
&& self.image_selected_state.steam_users.is_none()
|
||||||
@@ -138,28 +151,48 @@ impl MyEguiApp {
|
|||||||
self.handle_user_selected(user, ui);
|
self.handle_user_selected(user, ui);
|
||||||
}
|
}
|
||||||
UserAction::ShortcutSelected(shortcut) => {
|
UserAction::ShortcutSelected(shortcut) => {
|
||||||
self.handle_shortcut_selected(shortcut, ui);
|
handle_shortcut_selected(self, shortcut, ui);
|
||||||
}
|
}
|
||||||
UserAction::ImageTypeSelected(image_type) => {
|
UserAction::ImageTypeSelected(image_type) => {
|
||||||
self.handle_image_type_selected(image_type);
|
self.handle_image_type_selected(image_type);
|
||||||
}
|
}
|
||||||
UserAction::ImageSelected(image) => {
|
UserAction::ImageSelected(image) => {
|
||||||
self.handle_image_selected(image);
|
handle_image_selected(self,image);
|
||||||
}
|
}
|
||||||
UserAction::BackButton => {
|
UserAction::BackButton => {
|
||||||
self.handle_back_button_action();
|
self.handle_back_button_action();
|
||||||
}
|
}
|
||||||
UserAction::GridIdChanged(grid_id) => {
|
UserAction::GridIdChanged(grid_id) => {
|
||||||
self.handle_grid_change(grid_id);
|
handle_grid_change(self, grid_id);
|
||||||
}
|
}
|
||||||
UserAction::SetGamesMode(game_mode) => {
|
UserAction::SetGamesMode(game_mode) => {
|
||||||
self.handle_set_game_mode(game_mode);
|
self.handle_set_game_mode(game_mode);
|
||||||
}
|
}
|
||||||
UserAction::NoAction => {}
|
UserAction::NoAction => {}
|
||||||
UserAction::CorrectGridId => {
|
UserAction::CorrectGridId => {
|
||||||
self.handle_correct_grid_request();
|
handle_correct_grid_request(self);
|
||||||
}
|
}
|
||||||
UserAction::ImageTypeCleared(image_type, should_ban) => {
|
UserAction::ImageTypeCleared(image_type, should_ban) => {
|
||||||
|
self.handle_image_type_cleared(image_type, should_ban)
|
||||||
|
}
|
||||||
|
UserAction::ClearImages => {
|
||||||
|
self.handle_clear_all_images();
|
||||||
|
}
|
||||||
|
UserAction::DownloadAllImages => {
|
||||||
|
self.handle_download_all_images();
|
||||||
|
}
|
||||||
|
UserAction::RefreshImages => {
|
||||||
|
let (_, reciever) = watch::channel(SyncProgress::NotStarted);
|
||||||
|
let user = self.image_selected_state.steam_user.clone();
|
||||||
|
if let Some(user) = &user {
|
||||||
|
load_image_grids(user, &mut self.image_selected_state, ui);
|
||||||
|
}
|
||||||
|
self.status_reciever = reciever;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_image_type_cleared(&mut self, image_type: ImageType, should_ban: bool) {
|
||||||
let app_id = self
|
let app_id = self
|
||||||
.image_selected_state
|
.image_selected_state
|
||||||
.selected_shortcut
|
.selected_shortcut
|
||||||
@@ -171,13 +204,15 @@ impl MyEguiApp {
|
|||||||
.set_image_banned(&image_type, app_id, should_ban);
|
.set_image_banned(&image_type, app_id, should_ban);
|
||||||
self.handle_image_type_clear(image_type);
|
self.handle_image_type_clear(image_type);
|
||||||
}
|
}
|
||||||
UserAction::ClearImages => {
|
|
||||||
|
fn handle_clear_all_images(&mut self) {
|
||||||
for image_type in ImageType::all() {
|
for image_type in ImageType::all() {
|
||||||
self.handle_image_type_clear(*image_type);
|
self.handle_image_type_clear(*image_type);
|
||||||
}
|
}
|
||||||
self.handle_back_button_action();
|
self.handle_back_button_action();
|
||||||
}
|
}
|
||||||
UserAction::DownloadAllImages => {
|
|
||||||
|
fn handle_download_all_images(&mut self) {
|
||||||
if let Some(users) = &self.image_selected_state.steam_users {
|
if let Some(users) = &self.image_selected_state.steam_users {
|
||||||
let (sender, reciever) = watch::channel(SyncProgress::FindingImages);
|
let (sender, reciever) = watch::channel(SyncProgress::FindingImages);
|
||||||
self.status_reciever = reciever;
|
self.status_reciever = reciever;
|
||||||
@@ -191,16 +226,6 @@ impl MyEguiApp {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UserAction::RefreshImages => {
|
|
||||||
let (_, reciever) = watch::channel(SyncProgress::NotStarted);
|
|
||||||
let user = self.image_selected_state.steam_user.clone();
|
|
||||||
if let Some(user) = &user {
|
|
||||||
load_image_grids(user, &mut self.image_selected_state, ui);
|
|
||||||
}
|
|
||||||
self.status_reciever = reciever;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_image_type_clear(&mut self, image_type: ImageType) {
|
fn handle_image_type_clear(&mut self, image_type: ImageType) {
|
||||||
let data_folder = &self
|
let data_folder = &self
|
||||||
@@ -231,40 +256,10 @@ impl MyEguiApp {
|
|||||||
self.image_selected_state.image_type_selected = None;
|
self.image_selected_state.image_type_selected = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_correct_grid_request(&mut self) {
|
|
||||||
let app_name = self
|
|
||||||
.image_selected_state
|
|
||||||
.selected_shortcut
|
|
||||||
.as_ref()
|
|
||||||
.map(|s| s.name())
|
|
||||||
.unwrap_or_default();
|
|
||||||
let auth_key = self
|
|
||||||
.settings
|
|
||||||
.steamgrid_db
|
|
||||||
.auth_key
|
|
||||||
.clone()
|
|
||||||
.unwrap_or_default();
|
|
||||||
let client = steamgriddb_api::Client::new(&auth_key);
|
|
||||||
let search_results = self.rt.block_on(client.search(app_name));
|
|
||||||
self.image_selected_state.possible_names = search_results.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_set_game_mode(&mut self, game_mode: GameMode) {
|
fn handle_set_game_mode(&mut self, game_mode: GameMode) {
|
||||||
self.image_selected_state.game_mode = game_mode;
|
self.image_selected_state.game_mode = game_mode;
|
||||||
self.image_selected_state.steam_games = Some(get_installed_games(&self.settings.steam));
|
self.image_selected_state.steam_games = Some(get_installed_games(&self.settings.steam));
|
||||||
}
|
}
|
||||||
fn handle_grid_change(&mut self, grid_id: usize) {
|
|
||||||
self.image_selected_state.grid_id = Some(grid_id);
|
|
||||||
self.image_selected_state.possible_names = None;
|
|
||||||
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.name(), grid_id);
|
|
||||||
cache.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_user_selected(&mut self, user: SteamUsersInfo, ui: &mut egui::Ui) {
|
fn handle_user_selected(&mut self, user: SteamUsersInfo, ui: &mut egui::Ui) {
|
||||||
let state = &mut self.image_selected_state;
|
let state = &mut self.image_selected_state;
|
||||||
@@ -309,122 +304,10 @@ 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_shortcut = self
|
|
||||||
.image_selected_state
|
|
||||||
.selected_shortcut
|
|
||||||
.as_ref()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let ext = get_image_extension(&image.mime);
|
|
||||||
let to_download_to_path = Path::new(&user.steam_user_data_folder)
|
|
||||||
.join("config")
|
|
||||||
.join("grid")
|
|
||||||
.join(selected_image_type.file_name(selected_shortcut.app_id(), ext));
|
|
||||||
|
|
||||||
//Delete old possible images
|
|
||||||
|
|
||||||
let data_folder = Path::new(&user.steam_user_data_folder);
|
|
||||||
|
|
||||||
//Keep deleting images of this type untill we don't find any more
|
|
||||||
let mut path = self.get_shortcut_image_path(data_folder);
|
|
||||||
while Path::new(&path).exists() {
|
|
||||||
let _ = std::fs::remove_file(&path);
|
|
||||||
path = self.get_shortcut_image_path(data_folder);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Put the loaded thumbnail into the image handler map, we can use that for preview
|
|
||||||
let full_image_key = to_download_to_path.to_string_lossy().to_string();
|
|
||||||
let _ = self
|
|
||||||
.image_selected_state
|
|
||||||
.image_handles
|
|
||||||
.remove(&full_image_key);
|
|
||||||
let thumbnail_key = image.thumbnail_path.to_string_lossy().to_string();
|
|
||||||
let thumbnail = self
|
|
||||||
.image_selected_state
|
|
||||||
.image_handles
|
|
||||||
.remove(&thumbnail_key);
|
|
||||||
if let Some((_key, thumbnail)) = thumbnail {
|
|
||||||
self.image_selected_state
|
|
||||||
.image_handles
|
|
||||||
.insert(full_image_key, thumbnail);
|
|
||||||
}
|
|
||||||
|
|
||||||
let app_name = selected_shortcut.name();
|
|
||||||
let to_download = ToDownload {
|
|
||||||
path: to_download_to_path,
|
|
||||||
url: image.full_url.clone(),
|
|
||||||
app_name: app_name.to_string(),
|
|
||||||
image_type: *selected_image_type,
|
|
||||||
};
|
|
||||||
self.rt.spawn_blocking(move || {
|
|
||||||
let _ = block_on(crate::steamgriddb::download_to_download(&to_download));
|
|
||||||
});
|
|
||||||
|
|
||||||
self.clear_loaded_images();
|
|
||||||
{
|
|
||||||
self.image_selected_state.image_type_selected = None;
|
|
||||||
self.image_selected_state.image_options = watch::channel(FetcStatus::NeedsFetched).1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_shortcut_image_path(&self, data_folder: &Path) -> String {
|
|
||||||
self.image_selected_state
|
|
||||||
.selected_shortcut
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.key(
|
|
||||||
&self.image_selected_state.image_type_selected.unwrap(),
|
|
||||||
data_folder,
|
|
||||||
)
|
|
||||||
.1
|
|
||||||
}
|
|
||||||
|
|
||||||
fn clear_loaded_images(&mut self) {
|
|
||||||
if let FetcStatus::Fetched(options) = &*self.image_selected_state.image_options.borrow() {
|
|
||||||
for option in options {
|
|
||||||
let key = option.thumbnail_path.to_string_lossy().to_string();
|
|
||||||
self.image_selected_state.image_handles.remove(&key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_shortcut_selected(&mut self, shortcut: GameType, ui: &mut egui::Ui) {
|
|
||||||
let state = &mut self.image_selected_state;
|
|
||||||
//We must have a user to make see this action;
|
|
||||||
let user = state.steam_user.as_ref().unwrap();
|
|
||||||
if let Some(auth_key) = &self.settings.steamgrid_db.auth_key {
|
|
||||||
let client = steamgriddb_api::Client::new(auth_key);
|
|
||||||
let search = CachedSearch::new(&client);
|
|
||||||
state.grid_id = self
|
|
||||||
.rt
|
|
||||||
.block_on(search.search(shortcut.app_id(), shortcut.name()))
|
|
||||||
.ok()
|
|
||||||
.flatten();
|
|
||||||
}
|
|
||||||
state.selected_shortcut = Some(shortcut.clone());
|
|
||||||
|
|
||||||
for image_type in ImageType::all() {
|
|
||||||
let (path, key) = shortcut.key(image_type, Path::new(&user.steam_user_data_folder));
|
|
||||||
let image = load_image_from_path(&path);
|
|
||||||
if let Ok(image) = image {
|
|
||||||
let texture = ui
|
|
||||||
.ctx()
|
|
||||||
.load_texture(&key, image, egui::TextureOptions::LINEAR);
|
|
||||||
state
|
|
||||||
.image_handles
|
|
||||||
.insert(key, TextureDownloadState::Loaded(texture));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
state.selected_shortcut = Some(shortcut);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_back_button_action(&mut self) {
|
fn handle_back_button_action(&mut self) {
|
||||||
let state = &mut self.image_selected_state;
|
let state = &mut self.image_selected_state;
|
||||||
@@ -493,36 +376,3 @@ fn render_shortcut_mode_select(state: &ImageSelectState, ui: &mut egui::Ui) -> O
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn render_user_select(state: &ImageSelectState, ui: &mut egui::Ui) -> Option<UserAction> {
|
|
||||||
if state.steam_user.is_none() {
|
|
||||||
if let Some(users) = &state.steam_users {
|
|
||||||
if users.len() > 0 {
|
|
||||||
return Some(UserAction::UserSelected(users[0].clone()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let mut selected_user = state.steam_user.as_ref().unwrap().clone();
|
|
||||||
let id_before = selected_user.user_id.clone();
|
|
||||||
if let Some(steam_users) = &state.steam_users {
|
|
||||||
if steam_users.len() > 0 {
|
|
||||||
let combo_box = egui::ComboBox::new("ImageUserSelect", "")
|
|
||||||
.selected_text(format!("Steam user id: {}", &selected_user.user_id));
|
|
||||||
combo_box.show_ui(ui, |ui| {
|
|
||||||
for user in steam_users {
|
|
||||||
ui.selectable_value(&mut selected_user, user.clone(), &user.user_id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let id_now = selected_user.user_id.clone();
|
|
||||||
if !id_before.eq(&id_now) {
|
|
||||||
return Some(UserAction::UserSelected(selected_user.clone()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
const MAX_WIDTH: f32 = 300.;
|
|
||||||
@@ -5,6 +5,7 @@ mod ui_import_games;
|
|||||||
mod ui_settings;
|
mod ui_settings;
|
||||||
mod uiapp;
|
mod uiapp;
|
||||||
mod images;
|
mod images;
|
||||||
|
mod components;
|
||||||
|
|
||||||
pub use defines::*;
|
pub use defines::*;
|
||||||
pub use ui_backup::*;
|
pub use ui_backup::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user