Skip to content

Commit

Permalink
fix: grids now save for apps without previous ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed Apr 20, 2023
1 parent dce6574 commit 4759e51
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ fn filter_paths(app_handle: &AppHandle, steam_active_user_id: String, current_pa

for (appid, grids_map) in current_paths.into_iter() {
for (grid_type, source_path) in grids_map.into_iter() {
let grid_path: &String = original_paths.get(appid.as_str()).unwrap().get(grid_type.as_str()).unwrap();
let mut grid_path: &String = &String::from("");

if original_paths.get(appid.as_str()).is_some() && original_paths.get(appid.as_str()).unwrap().get(grid_type.as_str()).is_some() {
grid_path = original_paths.get(appid.as_str()).unwrap().get(grid_type.as_str()).unwrap();
}

let grid_path_owned = grid_path.to_owned();
let source_path_owned = source_path.to_owned();

Expand Down
12 changes: 12 additions & 0 deletions src/lib/controllers/AppController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@ export class AppController {
const gameName = get(selectedGameName);
const selectedGridType = get(gridType);
const gameImages = get(appLibraryCache);

if (!gameImages[selectedGameId]) {
// @ts-ignore
gameImages[selectedGameId] = {};
}

gameImages[selectedGameId][selectedGridType] = path;

if (get(currentPlatform) == Platforms.NON_STEAM) {
Expand Down Expand Up @@ -449,6 +455,12 @@ export class AppController {
const gameName = get(selectedGameName);
const selectedGridType = get(gridType);
const gameImages = get(appLibraryCache);

if (!gameImages[selectedGameId]) {
// @ts-ignore
gameImages[selectedGameId] = {};
}

gameImages[selectedGameId][selectedGridType] = localPath;

if (get(currentPlatform) == Platforms.NON_STEAM) {
Expand Down
28 changes: 20 additions & 8 deletions src/lib/controllers/CacheController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,17 @@ export class CacheController {
steamGridSteamAppIdMap[appId] = gameId;
}

const choosenResult = selectedSteamGridId ? results.find((game) => game.id.toString() == selectedSteamGridId) : results.find((game) => game.id.toString() == gameId);
let choosenResult = selectedSteamGridId ? results.find((game) => game.id.toString() == selectedSteamGridId) : results.find((game) => game.id.toString() == gameId);
if (!choosenResult && results.length > 0) choosenResult = results[0];

selectedSteamGridGameId.set(choosenResult.id.toString());
steamGridSearchCache.set(searchCache);
return await this.fetchGridsForNonSteamGame(choosenResult.id, type);
if (choosenResult?.id) {
selectedSteamGridGameId.set(choosenResult.id.toString());
steamGridSearchCache.set(searchCache);
return await this.fetchGridsForNonSteamGame(choosenResult.id, type);
} else {
LogController.log(`No results for ${type} for ${gameName}.`);
return [];
}
} else if (selectedPlatform == Platforms.NON_STEAM) {
const gameName = get(selectedGameName);
const searchCache = get(steamGridSearchCache);
Expand All @@ -253,11 +259,17 @@ export class CacheController {
searchCache[appId] = results;
}

const choosenResult = selectedSteamGridId ? results.find((game) => game.id.toString() == selectedSteamGridId) : results.find((game) => game.name == gameName);
let choosenResult = selectedSteamGridId ? results.find((game) => game.id.toString() == selectedSteamGridId) : results.find((game) => game.name == gameName);
if (!choosenResult && results.length > 0) choosenResult = results[0];

selectedSteamGridGameId.set(choosenResult.id.toString());
steamGridSearchCache.set(searchCache);
return await this.fetchGridsForNonSteamGame(choosenResult.id, type);
if (choosenResult?.id) {
selectedSteamGridGameId.set(choosenResult.id.toString());
steamGridSearchCache.set(searchCache);
return await this.fetchGridsForNonSteamGame(choosenResult.id, type);
} else {
LogController.log(`No results for ${type} for ${gameName}.`);
return [];
}
}
}

Expand Down

0 comments on commit 4759e51

Please sign in to comment.