diff --git a/src/main/events/torrenting/pause-game-download.ts b/src/main/events/torrenting/pause-game-download.ts index 27b21943..6c621e90 100644 --- a/src/main/events/torrenting/pause-game-download.ts +++ b/src/main/events/torrenting/pause-game-download.ts @@ -19,6 +19,7 @@ const pauseGameDownload = async ( await downloadsSublevel.put(gameKey, { ...download, status: "paused", + queued: false, }); } }; diff --git a/src/main/events/torrenting/resume-game-download.ts b/src/main/events/torrenting/resume-game-download.ts index c27aea84..48bb1c12 100644 --- a/src/main/events/torrenting/resume-game-download.ts +++ b/src/main/events/torrenting/resume-game-download.ts @@ -31,6 +31,7 @@ const resumeGameDownload = async ( ...download, status: "active", timestamp: Date.now(), + queued: true, }); } }; diff --git a/src/main/events/torrenting/start-game-download.ts b/src/main/events/torrenting/start-game-download.ts index 6d818d55..fddda3f3 100644 --- a/src/main/events/torrenting/start-game-download.ts +++ b/src/main/events/torrenting/start-game-download.ts @@ -72,6 +72,7 @@ const startGameDownload = async ( fileSize: null, shouldSeed: false, timestamp: Date.now(), + queued: true, }; await downloadsSublevel.put(gameKey, download); diff --git a/src/main/main.ts b/src/main/main.ts index 5ebcc723..5140e426 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -1,4 +1,10 @@ -import { DownloadManager, logger, Ludusavi, startMainLoop } from "./services"; +import { + Crypto, + DownloadManager, + logger, + Ludusavi, + startMainLoop, +} from "./services"; import { RealDebridClient } from "./services/download/real-debrid"; import { HydraApi } from "./services/hydra-api"; import { uploadGamesBatch } from "./services/library-sync"; @@ -34,7 +40,11 @@ const loadState = async (userPreferences: UserPreferences | null) => { .values() .all() .then((games) => { - return sortBy(games, "timestamp", "DESC"); + return sortBy( + games.filter((game) => game.queued), + "timestamp", + "DESC" + ); }); const [nextItemOnQueue] = downloads; @@ -137,8 +147,8 @@ const migrateFromSqlite = async () => { await db.put( levelKeys.auth, { - accessToken: users[0].accessToken, - refreshToken: users[0].refreshToken, + accessToken: Crypto.encrypt(users[0].accessToken), + refreshToken: Crypto.encrypt(users[0].refreshToken), tokenExpirationTimestamp: users[0].tokenExpirationTimestamp, }, { diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index 5b94f246..a32263b6 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -137,12 +137,14 @@ export class DownloadManager { ...download, status: "seeding", shouldSeed: true, + queued: false, }); } else { downloadsSublevel.put(gameId, { ...download, status: "complete", shouldSeed: false, + queued: false, }); this.cancelDownload(gameId); @@ -153,9 +155,7 @@ export class DownloadManager { .all() .then((games) => { return sortBy( - games.filter( - (game) => !["complete", "seeding"].includes(game.status!) - ), + games.filter((game) => game.status === "paused" && game.queued), "timestamp", "DESC" ); diff --git a/src/renderer/src/components/sidebar/sidebar.tsx b/src/renderer/src/components/sidebar/sidebar.tsx index d0348bb7..aa0dea8e 100644 --- a/src/renderer/src/components/sidebar/sidebar.tsx +++ b/src/renderer/src/components/sidebar/sidebar.tsx @@ -125,12 +125,11 @@ export function Sidebar() { }); } + if (game.download?.queued) return t("queued", { title: game.title }); + if (game.download?.status === "paused") return t("paused", { title: game.title }); - if (game.download?.status === "active") - return t("queued", { title: game.title }); - return game.title; }; diff --git a/src/renderer/src/pages/downloads/download-group.tsx b/src/renderer/src/pages/downloads/download-group.tsx index d629aa8f..36d3395b 100644 --- a/src/renderer/src/pages/downloads/download-group.tsx +++ b/src/renderer/src/pages/downloads/download-group.tsx @@ -150,7 +150,7 @@ export function DownloadGroup({ return ( <>

{formatDownloadProgress(download.progress)}

- {/*

{t(game.downloadQueue && lastPacket ? "queued" : "paused")}

*/} +

{t(download.queued ? "queued" : "paused")}

); } diff --git a/src/renderer/src/pages/downloads/downloads.tsx b/src/renderer/src/pages/downloads/downloads.tsx index 10efee44..c9a2a9e5 100644 --- a/src/renderer/src/pages/downloads/downloads.tsx +++ b/src/renderer/src/pages/downloads/downloads.tsx @@ -68,7 +68,7 @@ export default function Downloads() { return { ...prev, downloading: [...prev.downloading, next] }; /* Is either queued or paused */ - if (next.download?.status === "paused") + if (next.download.queued || next.download?.status === "paused") return { ...prev, queued: [...prev.queued, next] }; return { ...prev, complete: [...prev.complete, next] }; diff --git a/src/types/level.types.ts b/src/types/level.types.ts index bfa9e46f..7246d053 100644 --- a/src/types/level.types.ts +++ b/src/types/level.types.ts @@ -56,6 +56,7 @@ export interface Download { fileSize: number | null; shouldSeed: boolean; status: DownloadStatus | null; + queued: boolean; timestamp: number; }