diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index bb1bf9f8..710d6bb2 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -65,28 +65,6 @@ export class DownloadManager { ); } - if (progress === 1 && !isCheckingFiles) { - const userPreferences = await userPreferencesRepository.findOneBy({ - id: 1, - }); - - if (userPreferences?.seedAfterDownloadComplete) { - gameRepository.update( - { id: gameId }, - { status: "seeding", shouldSeed: true } - ); - } else { - gameRepository.update( - { id: gameId }, - { status: "complete", shouldSeed: false } - ); - - this.pauseSeeding(gameId); - } - - this.downloadingGameId = -1; - } - return { numPeers, numSeeds, @@ -112,6 +90,9 @@ export class DownloadManager { const game = await gameRepository.findOne({ where: { id: gameId, isDeleted: false }, }); + const userPreferences = await userPreferencesRepository.findOneBy({ + id: 1, + }); if (WindowManager.mainWindow && game) { WindowManager.mainWindow.setProgressBar(progress === 1 ? -1 : progress); @@ -127,6 +108,24 @@ export class DownloadManager { } if (progress === 1 && game) { publishDownloadCompleteNotification(game); + + if ( + userPreferences?.seedAfterDownloadComplete && + game.downloader === Downloader.Torrent + ) { + gameRepository.update( + { id: gameId }, + { status: "seeding", shouldSeed: true } + ); + } else { + gameRepository.update( + { id: gameId }, + { status: "complete", shouldSeed: false } + ); + + this.pauseSeeding(gameId); + } + await downloadQueueRepository.delete({ game }); const [nextQueueItem] = await downloadQueueRepository.find({ order: { @@ -138,20 +137,24 @@ export class DownloadManager { }); if (nextQueueItem) { this.resumeDownload(nextQueueItem.game); + } else { + this.downloadingGameId = -1; } } } } public static async getSeedStatus() { - const seedStatus = await PythonRPC.rpc - .get("/seed-status") - .then((results) => { - if (results === null) return []; - return results.data; - }); + const seedStatus = await PythonRPC.rpc.get( + "/seed-status" + ); - console.log(seedStatus); + if (!seedStatus.data.length) return; + + WindowManager.mainWindow?.webContents.send( + "on-seeding-status", + JSON.parse(JSON.stringify(seedStatus.data)) + ); // const gamesToSeed = await gameRepository.find({ // where: { shouldSeed: true, isDeleted: false }, @@ -209,8 +212,13 @@ export class DownloadManager { // ); } - static async pauseSeeding(_gameId: number) { - // await TorrentDownloader.pauseSeeding(gameId); + static async pauseSeeding(gameId: number) { + await PythonRPC.rpc + .post("/action", { + action: "pause", + game_id: gameId, + } as PauseDownloadPayload) + .catch(() => { }); } static async resumeSeeding( @@ -227,7 +235,7 @@ export class DownloadManager { action: "pause", game_id: this.downloadingGameId, } as PauseDownloadPayload) - .catch(() => {}); + .catch(() => { }); WindowManager.mainWindow?.setProgressBar(-1); diff --git a/src/main/services/seed.ts b/src/main/services/seed.ts index a9d093f4..d751db2a 100644 --- a/src/main/services/seed.ts +++ b/src/main/services/seed.ts @@ -1,7 +1,7 @@ import { gameRepository } from "@main/repository"; import { DownloadManager } from "./download/download-manager"; import { sleep } from "@main/helpers"; - + export const startSeedProcess = async () => { const seedList = await gameRepository.find({ where: { @@ -21,4 +21,3 @@ export const startSeedProcess = async () => { await sleep(100); }); }; -