Skip to content

Commit

Permalink
chore: now passes logo poses to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed May 13, 2023
1 parent 9e1a11c commit 0afcd81
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Value>, original_shortcut_icons: Map<String, Value>) -> 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<String, Value>, original_shortcut_icons: Map<String, Value>, changed_logo_positions: Map<String, Value>) -> 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();

Expand Down
23 changes: 22 additions & 1 deletion src/lib/controllers/AppController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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.");
}
Expand Down
13 changes: 11 additions & 2 deletions src/lib/controllers/RustInterop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChangedPath[] | { error: string }> {
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<ChangedPath[] | { error: string }> {
const shortcutsObj = {
"shortcuts": {...shortcuts}
}
const res = await invoke<string>("save_changes", { currentArt: JSON.stringify(currentArt), originalArt: JSON.stringify(originalArt), shortcutsStr: JSON.stringify(shortcutsObj), steamActiveUserId: activeUserId, shortcutIcons: shortcutIcons, originalShortcutIcons: originalShortcutIcons });
const res = await invoke<string>("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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0afcd81

Please sign in to comment.