diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 27622218..db5e3af3 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -246,7 +246,7 @@ async fn read_localconfig_vdf(app_handle: AppHandle, steam_active_user_id: Strin #[tauri::command] /// Applies the changes the user has made. -async fn save_changes(app_handle: AppHandle, steam_active_user_id: String, current_art: String, original_art: String, shortcuts_str: String, shortcut_icons: Map, original_shortcut_icons: Map) -> String { +async fn save_changes(app_handle: AppHandle, steam_active_user_id: String, current_art: String, original_art: String, shortcuts_str: String, shortcut_icons: Map, original_shortcut_icons: Map, changed_logo_positions: Map) -> String { let current_art_dict: GridImageCache = serde_json::from_str(current_art.as_str()).unwrap(); let original_art_dict: GridImageCache = serde_json::from_str(original_art.as_str()).unwrap(); diff --git a/src/lib/controllers/AppController.ts b/src/lib/controllers/AppController.ts index d0b476ca..31be0e35 100644 --- a/src/lib/controllers/AppController.ts +++ b/src/lib/controllers/AppController.ts @@ -426,7 +426,20 @@ export class AppController { const originalIconEntries = get(originalSteamShortcuts).map((shortcut) => [shortcut.appid, shortcut.icon]); const originalShortcutIcons = Object.fromEntries(originalIconEntries); - const changedPaths = await RustInterop.saveChanges(get(activeUserId).toString(), libraryCache, originalCache, shortcuts, shortcutIcons, originalShortcutIcons); + const originalLogoPos = get(originalLogoPositions); + const steamLogoPos = get(steamLogoPositions); + const logoPosStrings = {}; + + for (const [appid, steamLogo] of Object.entries(steamLogoPos)) { + const originalPos = originalLogoPos[appid].logoPosition; + const logoPos = steamLogo.logoPosition; + + if (logoPos.nHeightPct != originalPos.nHeightPct || logoPos.nWidthPct != originalPos.nWidthPct || logoPos.pinnedPosition != originalPos.pinnedPosition) { + logoPosStrings[appid] = logoPos.pinnedPosition == "REMOVE" ? "REMOVE" : JSON.stringify(steamLogo); + } + } + + const changedPaths = await RustInterop.saveChanges(get(activeUserId).toString(), libraryCache, originalCache, shortcuts, shortcutIcons, originalShortcutIcons, logoPosStrings); if ((changedPaths as any).error !== undefined) { ToastController.showSuccessToast("Changes failed."); @@ -444,6 +457,14 @@ export class AppController { originalSteamShortcuts.set(JSON.parse(JSON.stringify(shortcuts))); steamShortcuts.set(shortcuts); + + let logoPosEntries = Object.entries(steamLogoPos); + logoPosEntries = logoPosEntries.filter(([appid, logoPos]) => { + return logoPos.logoPosition.pinnedPosition != "REMOVE" + }); + + originalLogoPositions.set(JSON.parse(JSON.stringify(Object.fromEntries(logoPosEntries)))); + steamLogoPositions.set(JSON.parse(JSON.stringify(Object.fromEntries(logoPosEntries)))); ToastController.showSuccessToast("Changes saved!"); LogController.log("Saved changes."); } diff --git a/src/lib/controllers/RustInterop.ts b/src/lib/controllers/RustInterop.ts index 549e1ce7..1925bde1 100644 --- a/src/lib/controllers/RustInterop.ts +++ b/src/lib/controllers/RustInterop.ts @@ -154,13 +154,22 @@ export class RustInterop { * @param shortcuts The list of shortcuts. * @param shortcutIcons The map of shortcutIds to updated icons. * @param originalShortcutIcons The map of shortcutIds to original icons. + * @param changedLogoPositions The changed logo positions. * @returns A promise resolving to a string of serialized changed tuples. */ - static async saveChanges(activeUserId: string, currentArt: { [appid: string]: LibraryCacheEntry }, originalArt: { [appid: string]: LibraryCacheEntry }, shortcuts: SteamShortcut[], shortcutIcons: { [id: string]: string }, originalShortcutIcons: { [id: string]: string }): Promise { + static async saveChanges( + activeUserId: string, + currentArt: { [appid: string]: LibraryCacheEntry }, + originalArt: { [appid: string]: LibraryCacheEntry }, + shortcuts: SteamShortcut[], + shortcutIcons: { [id: string]: string }, + originalShortcutIcons: { [id: string]: string }, + changedLogoPositions: { [appid: string]: string } + ): Promise { const shortcutsObj = { "shortcuts": {...shortcuts} } - const res = await invoke("save_changes", { currentArt: JSON.stringify(currentArt), originalArt: JSON.stringify(originalArt), shortcutsStr: JSON.stringify(shortcutsObj), steamActiveUserId: activeUserId, shortcutIcons: shortcutIcons, originalShortcutIcons: originalShortcutIcons }); + const res = await invoke("save_changes", { currentArt: JSON.stringify(currentArt), originalArt: JSON.stringify(originalArt), shortcutsStr: JSON.stringify(shortcutsObj), steamActiveUserId: activeUserId, shortcutIcons: shortcutIcons, originalShortcutIcons: originalShortcutIcons, changedLogoPositions: changedLogoPositions }); return JSON.parse(res); } diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 8c5c5a36..3d989085 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -69,7 +69,7 @@ type ChangedPath = { sourcePath: string } -type LogoPinPositions = 'BottomLeft' | 'UpperLeft' | 'CenterCenter' | 'UpperCenter' | 'BottomCenter'; +type LogoPinPositions = 'BottomLeft' | 'UpperLeft' | 'CenterCenter' | 'UpperCenter' | 'BottomCenter' | "REMOVE"; type LogoPosition = { pinnedPosition: LogoPinPositions,