Skip to content

Commit

Permalink
Merge pull request #184 from Tormak9970/dev
Browse files Browse the repository at this point in the history
chore: build 3.6.3
  • Loading branch information
Tormak9970 authored May 8, 2024
2 parents 4c972ff + c9c3e9f commit 9c69322
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tauri-build = { version = "1.5.1", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.6.1", features = ["dialog-all", "fs-all", "http-request", "os-all", "path-all", "process-exit", "process-relaunch", "protocol-all", "reqwest-client", "shell-open", "updater", "window-all", "devtools"] }
tauri = { version = "1.6.1", features = ["devtools", "dialog-all", "fs-all", "http-request", "os-all", "path-all", "process-exit", "process-relaunch", "protocol-all", "reqwest-client", "shell-open", "updater", "window-all"] }
tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
chrono = "0.4.34"
home = "0.5.9"
Expand Down
33 changes: 20 additions & 13 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,24 +538,31 @@ async fn clean_grids(app_handle: AppHandle, steam_path: String, steam_active_use
// Validates the steam install path
async fn validate_steam_path(app_handle: AppHandle, target_path: String) -> bool {
let pre_canonicalized_path: PathBuf = PathBuf::from(&target_path);
let steam_path: PathBuf = pre_canonicalized_path.canonicalize().expect("Should have been able to resolve target path.");
let steam_path_str: String = steam_path.to_str().expect("Should have been able to convert pathbuf to string").to_owned();
let steam_path_res = pre_canonicalized_path.canonicalize();

add_path_to_scope(app_handle, steam_path_str).await;
if steam_path_res.is_ok() {
let steam_path = steam_path_res.ok().unwrap();
let steam_path_str: String = steam_path.to_str().expect("Should have been able to convert pathbuf to string").to_owned();

if steam_path.exists() {
let contents_res = fs::read_dir(steam_path);
let mut contents = contents_res.ok().expect("Should have been able to read the provided directory.");
add_path_to_scope(app_handle, steam_path_str).await;

return contents.any(| entry_res | {
if entry_res.is_ok() {
let entry = entry_res.ok().expect("Entry should have been ok");
if steam_path.exists() {
let contents_res = fs::read_dir(steam_path);
let mut contents = contents_res.ok().expect("Should have been able to read the provided directory.");

return entry.file_name().eq_ignore_ascii_case("steam.exe") || entry.file_name().eq_ignore_ascii_case("steam.sh");
}
return contents.any(| entry_res | {
if entry_res.is_ok() {
let entry = entry_res.ok().expect("Entry should have been ok");

return false;
});
return entry.file_name().eq_ignore_ascii_case("steam.exe") || entry.file_name().eq_ignore_ascii_case("steam.sh");
}

return false;
});
}
} else {
let path_err = steam_path_res.err().unwrap();
logger::log_to_core_file(app_handle.to_owned(), format!("Error canonicalizing {}: {}.", target_path, path_err.to_string()).as_str(), 1);
}

return false;
Expand Down
4 changes: 4 additions & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"/var/home/*/.config/dev.tormak.steam-art-manager",
"$APPCONFIG/**",
"/var/home/*/.config/dev.tormak.steam-art-manager/**",
"$Home/**",
"/var/home/*/**",
"$DATA",
"$DATA/**",
"$APPLOG",
Expand Down Expand Up @@ -59,6 +61,8 @@
"/var/home/*/.config/dev.tormak.steam-art-manager",
"$APPCONFIG/**",
"/var/home/*/.config/dev.tormak.steam-art-manager/**",
"$Home/**",
"/var/home/*/**",
"$DATA",
"$DATA/**",
"$APPLOG",
Expand Down
44 changes: 26 additions & 18 deletions src/components/core/grids/GridResults.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { AppController } from "../../../lib/controllers/AppController";
import type { SGDBImage } from "../../../lib/models/SGDB";
import { dbFilters, gridType, GridTypes, isOnline, needsSGDBAPIKey, selectedGameAppId, selectedGameName, steamGridDBKey, selectedSteamGridGameId, lastPageCache, hasMorePagesCache, loadingSettings } from "../../../stores/AppState";
import { dbFilters, gridType, GridTypes, isOnline, needsSGDBAPIKey, selectedGameAppId, selectedGameName, steamGridDBKey, selectedSteamGridGameId, lastPageCache, hasMorePagesCache, loadingSettings, steamGridSearchCache } from "../../../stores/AppState";
import Grid from "./Grid.svelte";
import { debounce, filterGrids, getHasMorePages, getPageNumberForGame } from "../../../lib/utils/Utils";
import GridLoadingSkeleton from "../../layout/GridLoadingSkeleton.svelte";
Expand All @@ -23,28 +23,27 @@
/**
* Filters the grids based when relevant state changes.
* @param resultsPage The results page to show.
* @param isCustomName Whether the app name is custom or not.
*/
async function filterGridsOnStateChange(resultsPage: number, isCustomName: boolean = false): Promise<void> {
if ($isOnline && $steamGridDBKey !== "" && !!$selectedGameAppId) {
const unfilteredGrids = await AppController.getSteamGridArt($selectedGameAppId, resultsPage, $selectedSteamGridGameId, isCustomName);
grids = filterGrids(unfilteredGrids, $gridType, $dbFilters, $selectedGameName);
}
async function filterGridsOnStateChange(resultsPage: number): Promise<void> {
const unfilteredGrids = await AppController.getSteamGridArt($selectedGameAppId, resultsPage, $selectedSteamGridGameId);
grids = filterGrids(unfilteredGrids, $gridType, $dbFilters, $selectedGameName);
}
/**
* Handles loading new grids when the user scrolls to the bottom.
*/
async function handleLoadOnScroll() {
const lastPageLoaded = getPageNumberForGame($selectedSteamGridGameId, $gridType);
const oldGridsLength = grids.length;
await filterGridsOnStateChange(lastPageLoaded + 1, hasCustomName);
if (oldGridsLength !== grids.length) {
lastPageCache[parseInt($selectedSteamGridGameId)][$gridType] = lastPageLoaded + 1;
} else {
hasMorePagesCache[parseInt($selectedSteamGridGameId)][$gridType] = false;
hasMorePages = false;
if ($isOnline && $steamGridDBKey !== "" && !!$selectedGameAppId) {
const lastPageLoaded = getPageNumberForGame($selectedSteamGridGameId, $gridType);
const oldGridsLength = grids.length;
await filterGridsOnStateChange(lastPageLoaded + 1);
if (oldGridsLength !== grids.length) {
lastPageCache[parseInt($selectedSteamGridGameId)][$gridType] = lastPageLoaded + 1;
} else {
hasMorePagesCache[parseInt($selectedSteamGridGameId)][$gridType] = false;
hasMorePages = false;
}
}
}
Expand All @@ -56,9 +55,18 @@
const debouncedResize = debounce(handleResize, 500);
onMount(() => {
filterGridsOnStateChange(getPageNumberForGame($selectedSteamGridGameId, $gridType), hasCustomName).then(() => {
if ($selectedGameAppId) {
if ($selectedSteamGridGameId === "None") {
AppController.chooseSteamGridGameId($selectedGameAppId, hasCustomName).then((sgdbGameId) => {
$selectedSteamGridGameId = sgdbGameId;
});
} else {
handleLoadOnScroll();
isLoading = false;
}
} else {
isLoading = false;
});
}
});
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/settings/SettingsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
<div class="settings-container">
<FilePathEntry
label="Steam Install Path"
description={"The root of your Steam installation. The default on Windows is <b>C:/Program Files (x86)/Steam</b> and <b>~/.steam/Steam</b> on Linux. You must restart after changing this."}
description={"The root of your Steam installation. The default on Windows is <b>C:/Program Files (x86)/Steam</b> and <b>~/.steam/steam</b> on Linux. You must restart after changing this."}
value={steamInstallLocation}
onChange={onInstallLocationChange}
useValidator
Expand Down
16 changes: 13 additions & 3 deletions src/lib/controllers/AppController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,17 +488,27 @@ export class AppController {
}
}

/**
* Chooses the steam grid game id for the provided game.
* @param appId The id of the app to get.
* @param isCustomName Whether the app name is custom or not.
* @returns A promise resolving to the id.
* ? Logging complete.
*/
static async chooseSteamGridGameId(appId: number, isCustomName: boolean): Promise<string> {
return await AppController.cacheController.chooseSteamGridGameId(appId, get(selectedGameName), get(currentPlatform), true, isCustomName);
}

/**
* Gets a list of grids for the provided game.
* @param appId The id of the app to get.
* @param page The page of results to get.
* @param selectedSteamGridId Optional id of the current steamGridGame.
* @param isCustomName Whether the app name is custom or not.
* @returns A promise resolving to a list of the results.
* ? Logging complete.
*/
static async getSteamGridArt(appId: number, page: number, selectedSteamGridId: string | null, isCustomName: boolean): Promise<SGDBImage[]> {
return await AppController.cacheController.fetchGrids(appId, get(selectedGameName), page, get(currentPlatform), true, selectedSteamGridId, isCustomName);
static async getSteamGridArt(appId: number, page: number, selectedSteamGridId: string | null): Promise<SGDBImage[]> {
return await AppController.cacheController.fetchGrids(appId, page, true, selectedSteamGridId);
}

/**
Expand Down
42 changes: 27 additions & 15 deletions src/lib/controllers/CacheController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,17 @@ export class CacheController {
}

/**
* Gets the current type of grid for the provided app id.
* Gets the sgdb game id for the provided game.
* @param appId The id of the app to fetch.
* @param gameName The name of the game to fetch grids for.
* @param page The page of results to get.
* @param selectedPlatform The game's platforms.
* @param useCoreFile Whether or not to use the core log file.
* @param selectedSteamGridId Optional id of the current steamGridGame.
* @param isCustomName Whether the app name is custom or not.
* @returns A promise resolving to the grids.
* ? Logging complete.
*/
async fetchGrids(appId: number, gameName: string, page: number, selectedPlatform: Platforms, useCoreFile: boolean, selectedSteamGridId: string | null, isCustomName?: boolean): Promise<SGDBImage[]> {
logToFile(`Fetching grids for game ${appId}...`, useCoreFile);
async chooseSteamGridGameId(appId: number, gameName: string, selectedPlatform: Platforms, useCoreFile: boolean, isCustomName?: boolean): Promise<string> {
logToFile(`Finding SGDB game for ${appId}...`, useCoreFile);

const type = get(gridType);
const searchCache = get(steamGridSearchCache);
Expand All @@ -266,7 +264,7 @@ export class CacheController {
} catch (e: any) {
logErrorToFile(`Error searching for game on SGDB. Game: ${gameName}. Platform: ${selectedPlatform}. Error: ${e.message}.`, useCoreFile);
ToastController.showWarningToast("Error searching for game on SGDB.");
return [];
return "None";
}
}

Expand All @@ -283,29 +281,42 @@ export class CacheController {
} catch (e: any) {
logErrorToFile(`Error getting game from SGDB by steam id. Game: ${gameName}. AppId: ${appId}. Error: ${e.message}.`, useCoreFile);
ToastController.showWarningToast("Error getting game from SGDB.");
return [];
return "None";
}
}

chosenResult = selectedSteamGridId ? results.find((game) => game.id.toString() === selectedSteamGridId) : null;
chosenResult ||= results.find((game) => game.id.toString() === gameId);
chosenResult = results.find((game) => game.id.toString() === gameId);
if (!chosenResult && results.length > 0) chosenResult = results[0];
} else {
chosenResult = selectedSteamGridId ? results.find((game) => game.id.toString() === selectedSteamGridId) : results.find((game) => game.name === gameName);
chosenResult = results.find((game) => game.name === gameName);
if (!chosenResult && results.length > 0) chosenResult = results[0];
}

if (chosenResult?.id) {
if (useCoreFile) selectedSteamGridGameId.set(chosenResult.id.toString());
steamGridSearchCache.set(searchCache);

return await this.fetchGridsForGame(chosenResult.id, type, page, getPageNumberForGame(chosenResult.id.toString(), type), useCoreFile);
return chosenResult.id.toString();
} else {
logToFile(`No results for ${type} for ${gameName}.`, useCoreFile);
return [];
return "None";
}
}

/**
* Gets the current type of grid for the provided app id.
* @param appId The id of the app to fetch.
* @param page The page of results to get.
* @param useCoreFile Whether or not to use the core log file.
* @param selectedSteamGridId Optional id of the current steamGridGame.
* @returns A promise resolving to the grids.
* ? Logging complete.
*/
async fetchGrids(appId: number, page: number, useCoreFile: boolean, selectedSteamGridId: string): Promise<SGDBImage[]> {
logToFile(`Fetching grids for game ${appId}...`, useCoreFile);
const type = get(gridType);

return await this.fetchGridsForGame(parseInt(selectedSteamGridId), type, page, getPageNumberForGame(selectedSteamGridId, type), useCoreFile);
}

/**
* Searches SGDB for the provided query.
* @param query The search query to use.
Expand Down Expand Up @@ -365,7 +376,8 @@ export class CacheController {
gameName = nonSteamGameNameMap[appid];
}

const grids = await this.fetchGrids(appidInt, gameName, 0, isSteamGame ? Platforms.STEAM : Platforms.NON_STEAM, false, null);
const sgdbGameId = await this.chooseSteamGridGameId(appidInt, gameName, isSteamGame ? Platforms.STEAM : Platforms.NON_STEAM, false);
const grids = await this.fetchGrids(appidInt, 0, false, sgdbGameId);
const filtered = filterGrids(grids, selectedGridType, filters, gameName, false);

if (filtered.length > 0) {
Expand Down
16 changes: 8 additions & 8 deletions src/lib/controllers/SettingsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,21 @@ export class SettingsController {
this.hiddenGameIdsSub = hiddenGameIds.subscribe((newIds) => {
if (JSON.stringify(newIds) !== JSON.stringify(this.oldHiddenGameIds)) {
SettingsManager.updateSetting("hiddenGameIds", newIds);
this.oldHiddenGameIds = newIds;
this.oldHiddenGameIds = structuredClone(newIds);
}
});

this.manualSteamGamesSub = manualSteamGames.subscribe((newGames) => {
if (JSON.stringify(newGames) !== JSON.stringify(this.oldManualSteamGames)) {
SettingsManager.updateSetting("manualSteamGames", newGames);
this.oldManualSteamGames = newGames;
this.oldManualSteamGames = structuredClone(newGames);
}
});

this.customGameNamesSub = customGameNames.subscribe((newGameNames) => {
if (JSON.stringify(newGameNames) !== JSON.stringify(this.oldCustomGameNames)) {
SettingsManager.updateSetting("customGameNames", newGameNames);
this.oldCustomGameNames = newGameNames;
this.oldCustomGameNames = structuredClone(newGameNames);
}
});

Expand Down Expand Up @@ -154,7 +154,7 @@ export class SettingsController {
this.dbFiltersSub = dbFilters.subscribe((newFilters) => {
if (JSON.stringify(newFilters) !== JSON.stringify(this.oldDbFilters)) {
SettingsManager.updateSetting("windowSettings.main.filters", newFilters);
this.oldDbFilters = newFilters;
this.oldDbFilters = structuredClone(newFilters);
}
});

Expand Down Expand Up @@ -297,19 +297,19 @@ export class SettingsController {
*/
private loadNicheSettings(): void {
const manualSteamGamesSetting = SettingsManager.getSetting<GameStruct[]>("manualSteamGames");
this.oldManualSteamGames = manualSteamGamesSetting;
this.oldManualSteamGames = structuredClone(manualSteamGamesSetting);
if (manualSteamGamesSetting.length > 0) {
manualSteamGames.set(manualSteamGamesSetting);
LogController.log(`Loaded ${manualSteamGamesSetting.length} manually added games.`);
}

const customGameNamesSetting = SettingsManager.getSetting<Record<string, string>>("customGameNames");
this.oldCustomGameNames = customGameNamesSetting;
this.oldCustomGameNames = structuredClone(customGameNamesSetting);
customGameNames.set(customGameNamesSetting);
LogController.log(`Loaded ${Object.keys(customGameNamesSetting).length} custom game names.`);

const hiddenGameIdsSetting = SettingsManager.getSetting<number[]>("hiddenGameIds");
this.oldHiddenGameIds = hiddenGameIdsSetting;
this.oldHiddenGameIds = structuredClone(hiddenGameIdsSetting);
hiddenGameIds.set(hiddenGameIdsSetting);
}

Expand All @@ -326,7 +326,7 @@ export class SettingsController {
showHidden.set(showHiddenGamesSetting);

const dbFiltersSetting = SettingsManager.getSetting<DBFilters>("windowSettings.main.filters");
this.oldDbFilters = dbFiltersSetting;
this.oldDbFilters = structuredClone(dbFiltersSetting);
dbFilters.set(dbFiltersSetting);

const gridTypeSetting = SettingsManager.getSetting<string>("windowSettings.main.type") as GridTypes;
Expand Down

0 comments on commit 9c69322

Please sign in to comment.