From 4dd3c9de76e0765a3b001c01577bbf2cf56d7a33 Mon Sep 17 00:00:00 2001 From: Moyasee Date: Thu, 30 Oct 2025 23:26:22 +0200 Subject: [PATCH] fix: formatting --- .../downloadSourcesCheckTimestamp.ts | 6 +- src/main/main.ts | 2 +- src/main/services/download-sources-checker.ts | 106 ++++++++++++------ src/main/services/hydra-api.ts | 35 +++--- .../components/sidebar/sidebar-game-item.tsx | 4 +- .../src/components/sidebar/sidebar.scss | 2 +- src/renderer/src/features/library-slice.ts | 6 +- .../hooks/use-download-options-listener.ts | 2 +- 8 files changed, 108 insertions(+), 55 deletions(-) diff --git a/src/main/level/sublevels/downloadSourcesCheckTimestamp.ts b/src/main/level/sublevels/downloadSourcesCheckTimestamp.ts index 13dbf682..f7071932 100644 --- a/src/main/level/sublevels/downloadSourcesCheckTimestamp.ts +++ b/src/main/level/sublevels/downloadSourcesCheckTimestamp.ts @@ -11,6 +11,8 @@ export const getLastDownloadSourcesCheck = async (): Promise => { } }; -export const updateLastDownloadSourcesCheck = async (timestamp: string): Promise => { +export const updateLastDownloadSourcesCheck = async ( + timestamp: string +): Promise => { await db.put(levelKeys.lastDownloadSourcesCheck, timestamp); -}; \ No newline at end of file +}; diff --git a/src/main/main.ts b/src/main/main.ts index 8e1264d7..50173390 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -57,7 +57,7 @@ export const loadState = async () => { const { syncDownloadSourcesFromApi } = await import("./services/user"); void syncDownloadSourcesFromApi(); - + // Check for new download options on startup void DownloadSourcesChecker.checkForChanges(); // WSClient.connect(); diff --git a/src/main/services/download-sources-checker.ts b/src/main/services/download-sources-checker.ts index f22f12fc..d2ccb531 100644 --- a/src/main/services/download-sources-checker.ts +++ b/src/main/services/download-sources-checker.ts @@ -1,5 +1,10 @@ import { HydraApi } from "./hydra-api"; -import { gamesSublevel, getLastDownloadSourcesCheck, updateLastDownloadSourcesCheck, downloadSourcesSublevel } from "@main/level"; +import { + gamesSublevel, + getLastDownloadSourcesCheck, + updateLastDownloadSourcesCheck, + downloadSourcesSublevel, +} from "@main/level"; import { logger } from "./logger"; import { WindowManager } from "./window-manager"; import type { Game } from "@types"; @@ -14,62 +19,85 @@ interface DownloadSourcesChangeResponse { export class DownloadSourcesChecker { static async checkForChanges(): Promise { logger.info("DownloadSourcesChecker.checkForChanges() called"); - + try { // Get all installed games (excluding custom games) const installedGames = await gamesSublevel.values().all(); - const nonCustomGames = installedGames.filter((game: Game) => game.shop !== 'custom'); - logger.info(`Found ${installedGames.length} total games, ${nonCustomGames.length} non-custom games`); - + const nonCustomGames = installedGames.filter( + (game: Game) => game.shop !== "custom" + ); + logger.info( + `Found ${installedGames.length} total games, ${nonCustomGames.length} non-custom games` + ); + if (nonCustomGames.length === 0) { - logger.info("No non-custom games found, skipping download sources check"); + logger.info( + "No non-custom games found, skipping download sources check" + ); return; } // Get download sources const downloadSources = await downloadSourcesSublevel.values().all(); - const downloadSourceIds = downloadSources.map(source => source.id); - logger.info(`Found ${downloadSourceIds.length} download sources: ${downloadSourceIds.join(', ')}`); + const downloadSourceIds = downloadSources.map((source) => source.id); + logger.info( + `Found ${downloadSourceIds.length} download sources: ${downloadSourceIds.join(", ")}` + ); if (downloadSourceIds.length === 0) { - logger.info("No download sources found, skipping download sources check"); + logger.info( + "No download sources found, skipping download sources check" + ); return; } // Get last check timestamp or use a default (24 hours ago) const lastCheck = await getLastDownloadSourcesCheck(); - const since = lastCheck || new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(); + const since = + lastCheck || new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(); logger.info(`Last check: ${lastCheck}, using since: ${since}`); // Clear any previously stored new download option counts so badges don't persist across restarts const previouslyFlaggedGames = nonCustomGames.filter( - (game: Game) => (game as Game).newDownloadOptionsCount && (game as Game).newDownloadOptionsCount! > 0 + (game: Game) => + (game as Game).newDownloadOptionsCount && + (game as Game).newDownloadOptionsCount! > 0 ); const clearedPayload: { gameId: string; count: number }[] = []; if (previouslyFlaggedGames.length > 0) { - logger.info(`Clearing stale newDownloadOptionsCount for ${previouslyFlaggedGames.length} games`); + logger.info( + `Clearing stale newDownloadOptionsCount for ${previouslyFlaggedGames.length} games` + ); for (const game of previouslyFlaggedGames) { await gamesSublevel.put(`${game.shop}:${game.objectId}`, { ...game, newDownloadOptionsCount: undefined, }); - clearedPayload.push({ gameId: `${game.shop}:${game.objectId}`, count: 0 }); + clearedPayload.push({ + gameId: `${game.shop}:${game.objectId}`, + count: 0, + }); } } // Prepare games array for API call (excluding custom games) const games = nonCustomGames.map((game: Game) => ({ shop: game.shop, - objectId: game.objectId + objectId: game.objectId, })); - logger.info(`Checking download sources changes for ${games.length} non-custom games since ${since}`); - logger.info(`Making API call to HydraApi.checkDownloadSourcesChanges with:`, { - downloadSourceIds, - gamesCount: games.length, - since - }); + logger.info( + `Checking download sources changes for ${games.length} non-custom games since ${since}` + ); + logger.info( + `Making API call to HydraApi.checkDownloadSourcesChanges with:`, + { + downloadSourceIds, + gamesCount: games.length, + since, + } + ); // Call the API const response = await HydraApi.checkDownloadSourcesChanges( @@ -77,7 +105,7 @@ export class DownloadSourcesChecker { games, since ); - + logger.info("API call completed, response:", response); // Update the last check timestamp @@ -86,37 +114,45 @@ export class DownloadSourcesChecker { // Process the response and store newDownloadOptionsCount for games with new options if (response && Array.isArray(response)) { const gamesWithNewOptions: { gameId: string; count: number }[] = []; - + for (const gameUpdate of response as DownloadSourcesChangeResponse[]) { if (gameUpdate.newDownloadOptionsCount > 0) { - const game = nonCustomGames.find(g => - g.shop === gameUpdate.shop && g.objectId === gameUpdate.objectId + const game = nonCustomGames.find( + (g) => + g.shop === gameUpdate.shop && g.objectId === gameUpdate.objectId ); - + if (game) { // Store the new download options count in the game data await gamesSublevel.put(`${game.shop}:${game.objectId}`, { ...game, - newDownloadOptionsCount: gameUpdate.newDownloadOptionsCount + newDownloadOptionsCount: gameUpdate.newDownloadOptionsCount, }); - + gamesWithNewOptions.push({ gameId: `${game.shop}:${game.objectId}`, - count: gameUpdate.newDownloadOptionsCount + count: gameUpdate.newDownloadOptionsCount, }); - - logger.info(`Game ${game.title} has ${gameUpdate.newDownloadOptionsCount} new download options`); + + logger.info( + `Game ${game.title} has ${gameUpdate.newDownloadOptionsCount} new download options` + ); } } } - + // Send IPC event to renderer to clear stale badges and set fresh counts from response const eventPayload = [...clearedPayload, ...gamesWithNewOptions]; if (eventPayload.length > 0 && WindowManager.mainWindow) { - WindowManager.mainWindow.webContents.send("on-new-download-options", eventPayload); + WindowManager.mainWindow.webContents.send( + "on-new-download-options", + eventPayload + ); } - - logger.info(`Found new download options for ${gamesWithNewOptions.length} games`); + + logger.info( + `Found new download options for ${gamesWithNewOptions.length} games` + ); } logger.info("Download sources check completed successfully"); @@ -124,4 +160,4 @@ export class DownloadSourcesChecker { logger.error("Failed to check download sources changes:", error); } } -} \ No newline at end of file +} diff --git a/src/main/services/hydra-api.ts b/src/main/services/hydra-api.ts index 4f7091db..e7e93268 100644 --- a/src/main/services/hydra-api.ts +++ b/src/main/services/hydra-api.ts @@ -409,22 +409,31 @@ export class HydraApi { downloadSourceIds, gamesCount: games.length, since, - isLoggedIn: this.isLoggedIn() + isLoggedIn: this.isLoggedIn(), }); try { - const result = await this.post>("/download-sources/changes", { - downloadSourceIds, - games, - since, - }, { needsAuth: true }); - - logger.info("HydraApi.checkDownloadSourcesChanges completed successfully:", result); + const result = await this.post< + Array<{ + shop: string; + objectId: string; + newDownloadOptionsCount: number; + downloadSourceIds: string[]; + }> + >( + "/download-sources/changes", + { + downloadSourceIds, + games, + since, + }, + { needsAuth: true } + ); + + logger.info( + "HydraApi.checkDownloadSourcesChanges completed successfully:", + result + ); return result; } catch (error) { logger.error("HydraApi.checkDownloadSourcesChanges failed:", error); diff --git a/src/renderer/src/components/sidebar/sidebar-game-item.tsx b/src/renderer/src/components/sidebar/sidebar-game-item.tsx index add7e081..59698935 100644 --- a/src/renderer/src/components/sidebar/sidebar-game-item.tsx +++ b/src/renderer/src/components/sidebar/sidebar-game-item.tsx @@ -84,7 +84,9 @@ export function SidebarGameItem({ {game.newDownloadOptionsCount && game.newDownloadOptionsCount > 0 && (
+
-
{game.newDownloadOptionsCount}
+
+ {game.newDownloadOptionsCount} +
)} diff --git a/src/renderer/src/components/sidebar/sidebar.scss b/src/renderer/src/components/sidebar/sidebar.scss index 9068e2b5..fdb3872e 100644 --- a/src/renderer/src/components/sidebar/sidebar.scss +++ b/src/renderer/src/components/sidebar/sidebar.scss @@ -116,7 +116,7 @@ } &__game-badge { - background: rgba(255, 255, 255, 0.1);; + background: rgba(255, 255, 255, 0.1); color: #fff; font-size: 10px; font-weight: bold; diff --git a/src/renderer/src/features/library-slice.ts b/src/renderer/src/features/library-slice.ts index e92e6a25..9c399dbe 100644 --- a/src/renderer/src/features/library-slice.ts +++ b/src/renderer/src/features/library-slice.ts @@ -39,4 +39,8 @@ export const librarySlice = createSlice({ }, }); -export const { setLibrary, updateGameNewDownloadOptions, clearNewDownloadOptions } = librarySlice.actions; +export const { + setLibrary, + updateGameNewDownloadOptions, + clearNewDownloadOptions, +} = librarySlice.actions; diff --git a/src/renderer/src/hooks/use-download-options-listener.ts b/src/renderer/src/hooks/use-download-options-listener.ts index f0268335..34cc7bf7 100644 --- a/src/renderer/src/hooks/use-download-options-listener.ts +++ b/src/renderer/src/hooks/use-download-options-listener.ts @@ -16,4 +16,4 @@ export function useDownloadOptionsListener() { return unsubscribe; }, [dispatch]); -} \ No newline at end of file +}