From 0fc0d4850eeca74410c35beff62bab02ad617e5d Mon Sep 17 00:00:00 2001 From: Tormak <63308171+Tormak9970@users.noreply.github.com> Date: Sat, 13 May 2023 11:58:29 -0500 Subject: [PATCH] feat: now able to set logo position --- src-tauri/src/main.rs | 31 +++++++++++++++++++++++++-- src/components/core/games/Game.svelte | 2 +- src/lib/controllers/AppController.ts | 6 +++--- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index db5e3af3..134e1b93 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -10,7 +10,7 @@ mod appinfo_vdf_parser; mod shortcuts_vdf_parser; mod vdf_reader; -use std::{path::PathBuf, collections::HashMap, fs::{self, File}, io::Write}; +use std::{path::PathBuf, collections::HashMap, fs::{self, File, write}, io::Write}; use appinfo_vdf_parser::open_appinfo_vdf; use serde_json::{Map, Value}; @@ -291,7 +291,34 @@ async fn save_changes(app_handle: AppHandle, steam_active_user_id: String, curre } } - let should_change_shortcuts = check_for_shortcut_changes(&shortcut_icons, &original_shortcut_icons); + let grids_directory: PathBuf = PathBuf::from(steam::get_grids_directory(app_handle.to_owned(), steam_active_user_id.clone())); + for (appid, steam_logo_str_val) in changed_logo_positions.into_iter() { + let steam_logo_str: &str = steam_logo_str_val.as_str().expect("Should have been able to convert steamLogo pos into str."); + let logo_config_path: PathBuf = grids_directory.join(format!("{}.json", appid)); + + if steam_logo_str == "Remove" { + let remove_res = fs::remove_file(logo_config_path); + if remove_res.is_err() { + let err = remove_res.err().unwrap(); + return format!("{{ \"error\": \"{}\"}}", err.to_string()); + } + logger::log_to_file(app_handle.to_owned(), format!("Removed logo position config for {}.", appid).as_str(), 0); + } else { + // let config_file = fs::File::create(&logo_config_path).expect("Should have been able to create or truncate logo pos config file."); + + let write_res = write(&logo_config_path, steam_logo_str); + + if write_res.is_ok() { + logger::log_to_file(app_handle.to_owned(), format!("Wrote logo pos to config for {}.", appid).as_str(), 0); + } else { + logger::log_to_file(app_handle.to_owned(), format!("Failed to write logo pos to config for {}.", appid).as_str(), 2); + let err = write_res.err().unwrap(); + return format!("{{ \"error\": \"{}\"}}", err.to_string()); + } + } + } + + let should_change_shortcuts: bool = check_for_shortcut_changes(&shortcut_icons, &original_shortcut_icons); if should_change_shortcuts { logger::log_to_file(app_handle.to_owned(), "Changes to shortcuts detected. Writing shortcuts.vdf...", 0); diff --git a/src/components/core/games/Game.svelte b/src/components/core/games/Game.svelte index 91a25d40..032e0064 100644 --- a/src/components/core/games/Game.svelte +++ b/src/components/core/games/Game.svelte @@ -19,7 +19,7 @@ $: originalLogoPos = $originalLogoPositions[game.appid]?.logoPosition; $: steamLogoPos = $steamLogoPositions[game.appid]?.logoPosition; $: canDiscard = (($currentPlatform == Platforms.STEAM && $appLibraryCache[game.appid]) ? $appLibraryCache[game.appid][$gridType] != $originalAppLibraryCache[game.appid][$gridType] : false) - || (steamLogoPos ? (steamLogoPos.nHeightPct != originalLogoPos.nHeightPct || steamLogoPos.nWidthPct != originalLogoPos.nWidthPct || steamLogoPos.pinnedPosition != originalLogoPos.pinnedPosition) : false); + || (steamLogoPos ? (steamLogoPos.nHeightPct != originalLogoPos?.nHeightPct || steamLogoPos.nWidthPct != originalLogoPos?.nWidthPct || steamLogoPos.pinnedPosition != originalLogoPos?.pinnedPosition) : false); $: hasCustomArt = ($currentPlatform == Platforms.STEAM && $unfilteredLibraryCache[game.appid]) ? $appLibraryCache[game.appid][$gridType] != $unfilteredLibraryCache[game.appid][$gridType] : false; /** diff --git a/src/lib/controllers/AppController.ts b/src/lib/controllers/AppController.ts index 31be0e35..41bf85d5 100644 --- a/src/lib/controllers/AppController.ts +++ b/src/lib/controllers/AppController.ts @@ -431,10 +431,10 @@ export class AppController { const logoPosStrings = {}; for (const [appid, steamLogo] of Object.entries(steamLogoPos)) { - const originalPos = originalLogoPos[appid].logoPosition; + const originalPos = originalLogoPos[appid]?.logoPosition; const logoPos = steamLogo.logoPosition; - if (logoPos.nHeightPct != originalPos.nHeightPct || logoPos.nWidthPct != originalPos.nWidthPct || logoPos.pinnedPosition != originalPos.pinnedPosition) { + if (logoPos.nHeightPct != originalPos?.nHeightPct || logoPos.nWidthPct != originalPos?.nWidthPct || logoPos.pinnedPosition != originalPos?.pinnedPosition) { logoPosStrings[appid] = logoPos.pinnedPosition == "REMOVE" ? "REMOVE" : JSON.stringify(steamLogo); } } @@ -680,7 +680,7 @@ export class AppController { const currentPos = logoPositions[appId]; logoPositions[appId] = { - nVersion: currentPos.nVersion, + nVersion: currentPos?.nVersion ?? 1, logoPosition: { pinnedPosition: pinPosition, nHeightPct: heightPct,