Skip to content

Commit

Permalink
fix: clearing grids no longer erases image in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed May 2, 2023
1 parent af10a9d commit a7abbce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/Stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const steamGames: Writable<GameStruct[]> = writable([]);
export const nonSteamGames: Writable<GameStruct[]> = writable([]);
export const hiddenGameIds: Writable<number[]> = writable([]);

export const unfilteredLibraryCache: Writable<{ [appid: string]: LibraryCacheEntry }> = writable({});
export const originalAppLibraryCache: Writable<{ [appid: string]: LibraryCacheEntry }> = writable({});
export const appLibraryCache: Writable<{ [appid: string]: LibraryCacheEntry }> = writable({});

Expand Down
28 changes: 15 additions & 13 deletions src/components/core/games/Game.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type { Unsubscriber } from "svelte/store";
import { SettingsManager } from "../../../lib/utils/SettingsManager";
import { appLibraryCache, gridType, hiddenGameIds, originalAppLibraryCache, selectedGameAppId, selectedGameName } from "../../../Stores";
import { appLibraryCache, gridType, hiddenGameIds, originalAppLibraryCache, selectedGameAppId, selectedGameName, unfilteredLibraryCache } from "../../../Stores";
import { AppController } from "../../../lib/controllers/AppController";
import GridImage from "../GridImage.svelte";
Expand Down Expand Up @@ -60,27 +60,29 @@
}
onMount(() => {
gridTypeUnsub = gridType.subscribe(async (type) => {
gridTypeUnsub = gridType.subscribe((type) => {
if ($appLibraryCache[game.appid]) {
if ($appLibraryCache[game.appid][type] && $appLibraryCache[game.appid][type] != "REMOVE") {
if ($appLibraryCache[game.appid][type]) {
showImage = true;
// TODO: check if ico and convert to base64
imagePath = tauri.convertFileSrc($appLibraryCache[game.appid][type]);
// if ($appLibraryCache[game.appid][type].endsWith(".ico")) {
// const icoData = await getIcoImage(imagePath);
// imagePath = icoData;
// }
} else {
if ($appLibraryCache[game.appid][type] == "REMOVE") {
imagePath = tauri.convertFileSrc($unfilteredLibraryCache[game.appid][type]);
} else {
imagePath = tauri.convertFileSrc($appLibraryCache[game.appid][type]);
}
} else {
showImage = false;
}
}
});
libraryCacheUnsub = appLibraryCache.subscribe((cache) => {
if (cache[game.appid]) {
if (cache[game.appid][$gridType] && cache[game.appid][$gridType] != "REMOVE") {
if (cache[game.appid][$gridType]) {
showImage = true;
imagePath = tauri.convertFileSrc(cache[game.appid][$gridType]);
if (cache[game.appid][$gridType] == "REMOVE") {
imagePath = tauri.convertFileSrc($unfilteredLibraryCache[game.appid][$gridType]);
} else {
imagePath = tauri.convertFileSrc(cache[game.appid][$gridType]);
}
} else {
showImage = false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/controllers/AppController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ToastController } from "./ToastController";
import { SettingsManager } from "../utils/SettingsManager";
import { LogController } from "./LogController";
import { get } from "svelte/store";
import { GridTypes, Platforms, activeUserId, appLibraryCache, canSave, currentPlatform, gridModalInfo, gridType, hiddenGameIds, isOnline, loadingGames, needsSGDBAPIKey, needsSteamKey, nonSteamGames, originalAppLibraryCache, originalSteamShortcuts, selectedGameAppId, selectedGameName, showGridModal, steamGames, steamGridDBKey, steamKey, steamShortcuts, steamUsers, theme } from "../../Stores";
import { GridTypes, Platforms, activeUserId, appLibraryCache, canSave, currentPlatform, gridModalInfo, gridType, hiddenGameIds, isOnline, loadingGames, needsSGDBAPIKey, needsSteamKey, nonSteamGames, originalAppLibraryCache, originalSteamShortcuts, selectedGameAppId, selectedGameName, showGridModal, steamGames, steamGridDBKey, steamKey, steamShortcuts, steamUsers, theme, unfilteredLibraryCache } from "../../Stores";
import { CacheController } from "./CacheController";
import { RustInterop } from "./RustInterop";
import type { SGDBImage } from "../models/SGDB";
Expand Down Expand Up @@ -183,6 +183,7 @@ export class AppController {
}

const entries = Object.entries(res);
unfilteredLibraryCache.set(JSON.parse(JSON.stringify(res)));
const filtered = entries.filter(([appId, entry]) => Object.keys(entry).length >= 4 || shortcutIds.includes(appId));
return Object.fromEntries(filtered);
}
Expand Down

0 comments on commit a7abbce

Please sign in to comment.