feat: adding download queue

This commit is contained in:
Chubby Granny Chaser
2024-06-04 15:33:47 +01:00
parent 0b68ddda78
commit 73b4b2c13c
27 changed files with 615 additions and 458 deletions

View File

@@ -1,6 +1,10 @@
import Aria2, { StatusResponse } from "aria2";
import { gameRepository, userPreferencesRepository } from "@main/repository";
import {
downloadQueueRepository,
gameRepository,
userPreferencesRepository,
} from "@main/repository";
import { WindowManager } from "./window-manager";
import { RealDebridClient } from "./real-debrid";
@@ -194,19 +198,6 @@ export class DownloadManager {
where: { id: this.game.id, isDeleted: false },
});
if (progress === 1 && this.game && !isDownloadingMetadata) {
await this.publishNotification();
/*
Only cancel bittorrent downloads to stop seeding
*/
if (status.bittorrent) {
await this.cancelDownload(this.game.id);
} else {
this.clearCurrentDownload();
}
}
if (WindowManager.mainWindow && game) {
if (!isNaN(progress))
WindowManager.mainWindow.setProgressBar(progress === 1 ? -1 : progress);
@@ -229,6 +220,32 @@ export class DownloadManager {
JSON.parse(JSON.stringify(payload))
);
}
if (progress === 1 && this.game && !isDownloadingMetadata) {
await this.publishNotification();
await downloadQueueRepository.delete({ game: this.game });
/*
Only cancel bittorrent downloads to stop seeding
*/
if (status.bittorrent) {
await this.cancelDownload(this.game.id);
} else {
this.clearCurrentDownload();
}
const [nextQueueItem] = await downloadQueueRepository.find({
order: {
id: "DESC",
},
relations: {
game: true,
},
});
this.resumeDownload(nextQueueItem!.game);
}
}
private static clearCurrentDownload() {