Skip to content

Commit

Permalink
fix: grids now properly display on load and after clear
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed Nov 25, 2024
1 parent 42ce7fb commit c854bf5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src-tauri/src/grids_cache_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ async fn filter_library_dir(app_handle: &AppHandle, steam_path: String, grid_cac
}

library_cache_entry.insert(type_key.to_owned(), Value::String(path_str.clone()));
grid_cache_entry.insert(type_key.to_owned(), Value::String(path_str));
if !grid_cache_entry.contains_key(type_key) {
grid_cache_entry.insert(type_key.to_owned(), Value::String(path_str));
}

unfiltered_cache.insert(app_id.clone(), Value::Object(library_cache_entry));
grid_cache_data.insert(app_id, Value::Object(grid_cache_entry));
Expand Down
1 change: 0 additions & 1 deletion src/components/core/games/grid-view/GridEntry.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
</script>

<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div class="game" class:selected={$selectedGameAppId === game.appid.toString()} on:click={selectGame}>
<div class="button-container">
<div
Expand Down
12 changes: 7 additions & 5 deletions src/lib/controllers/AppController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { createTippy } from "svelte-tippy";
import { get } from "svelte/store";
import { hideAll, type Instance, type Props } from "tippy.js";
import "tippy.js/dist/tippy.css";
import { Platforms, activeUserId, appLibraryCache, canSave, currentPlatform, customGameNames, gridType, isOnline, loadingGames, manualSteamGames, needsSGDBAPIKey, needsSteamKey, nonSteamGames, originalAppLibraryCache, originalLogoPositions, originalSteamShortcuts, selectedGameAppId, selectedGameName, showErrorSnackbar, showInfoSnackbar, steamGames, steamKey, steamLogoPositions, steamShortcuts, steamUsers } from "../../stores/AppState";
import { Platforms, activeUserId, appLibraryCache, canSave, currentPlatform, customGameNames, gridType, isOnline, loadingGames, manualSteamGames, needsSGDBAPIKey, needsSteamKey, nonSteamGames, originalAppLibraryCache, originalLogoPositions, originalSteamShortcuts, selectedGameAppId, selectedGameName, showErrorSnackbar, showInfoSnackbar, steamGames, steamKey, steamLogoPositions, steamShortcuts, steamUsers, unfilteredLibraryCache } from "../../stores/AppState";
import { cleanConflicts, gameSearchModalCancel, gameSearchModalDefault, gameSearchModalSelect, gridModalInfo, showCleanConflictDialog, showGameSearchModal, showGridModal, showSettingsModal } from "../../stores/Modals";
import { CacheController } from "./CacheController";
import { SteamController } from "./SteamController";
Expand All @@ -43,7 +43,7 @@ export class AppController {
duration: 100,
theme: "sarm",
arrow: true,
appendTo: 'parent'
appendTo: "parent"
});

static onTippyShow(instance: Instance<Props>): void {
Expand Down Expand Up @@ -93,6 +93,7 @@ export class AppController {
static async saveChanges(): Promise<void> {
LogController.log("Saving changes...");

const unfilteredCache = get(unfilteredLibraryCache);
const originalCache = get(originalAppLibraryCache);
const libraryCache = get(appLibraryCache);
const shortcuts = get(steamShortcuts);
Expand Down Expand Up @@ -125,7 +126,8 @@ export class AppController {
LogController.log("Changes failed.");
} else {
for (const changedPath of (changedPaths as ChangedPath[])) {
libraryCache[changedPath.appId][changedPath.gridType] = changedPath.targetPath === "REMOVE" ? "" : changedPath.targetPath;
const originalPath = unfilteredCache[changedPath.appId][changedPath.gridType] ?? "";
libraryCache[changedPath.appId][changedPath.gridType] = changedPath.targetPath === "REMOVE" ? originalPath : changedPath.targetPath;

if (changedPath.gridType === GridTypes.ICON && shortcutIds.includes(changedPath.appId)) {
const shortcut = shortcuts.find((s) => s.appid.toString() === changedPath.appId)!;
Expand All @@ -139,7 +141,7 @@ export class AppController {
steamShortcuts.set(shortcuts);

let logoPosEntries = Object.entries(steamLogoPos);
logoPosEntries = logoPosEntries.filter(([ appid, logoPos ]) => {
logoPosEntries = logoPosEntries.filter(([ _, logoPos ]) => {
return logoPos.logoPosition && logoPos.logoPosition.pinnedPosition !== "REMOVE";
});

Expand Down Expand Up @@ -450,7 +452,7 @@ export class AppController {
await AppController.saveChanges();

const filteredCache = await SteamController.getCacheData(get(nonSteamGames));
originalAppLibraryCache.set(filteredCache);
originalAppLibraryCache.set(structuredClone(filteredCache));
appLibraryCache.set(filteredCache);
} else {
LogController.log("Import grids cancelled.");
Expand Down
1 change: 1 addition & 0 deletions src/lib/controllers/SteamController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export class SteamController {


const filteredCache = await SteamController.getCacheData(structuredShortcuts);
console.log("filteredCache:", JSON.parse(JSON.stringify(filteredCache)));
const filteredKeys = Object.keys(filteredCache);


Expand Down
13 changes: 11 additions & 2 deletions src/stores/AppState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,17 @@ export const hiddenGameIds = writable<number[]>([]);
export const manualSteamGames = writable<GameStruct[]>([]);
export const customGameNames = writable<{ [appid: string]: string }>({});

/**
* The default library art provided by Steam.
*/
export const unfilteredLibraryCache = writable<{ [appid: string]: LibraryCacheEntry }>({});
/**
* The user's library art including custom art.
*/
export const originalAppLibraryCache = writable<{ [appid: string]: LibraryCacheEntry }>({});
/**
* The user's library art including custom art and changes made in this session.
*/
export const appLibraryCache = writable<{ [appid: string]: LibraryCacheEntry }>({});


Expand All @@ -93,8 +102,8 @@ export const steamLogoPositions = writable<{ [appid: string]: SteamLogoConfig }>
export const dbFilters: Writable<DBFilters> = writable(DEFAULT_FILTERS);

export const selectedGameName = derived(
[selectedGameAppId, steamGames, nonSteamGames, manualSteamGames, customGameNames],
([$selectedGameAppId, $steamGames, $nonSteamGames, $manualSteamGames, $customGameNames]) => {
[ selectedGameAppId, steamGames, nonSteamGames, manualSteamGames, customGameNames ],
([ $selectedGameAppId, $steamGames, $nonSteamGames, $manualSteamGames, $customGameNames ]) => {
if ($selectedGameAppId === "") return "None";

if ($customGameNames[$selectedGameAppId]) return $customGameNames[$selectedGameAppId];
Expand Down

0 comments on commit c854bf5

Please sign in to comment.