mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-15 04:32:13 +00:00
refactor: streamline download completion handling
This commit is contained in:
parent
5714c23073
commit
4b8569bd5e
2 changed files with 41 additions and 34 deletions
|
@ -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 {
|
return {
|
||||||
numPeers,
|
numPeers,
|
||||||
numSeeds,
|
numSeeds,
|
||||||
|
@ -112,6 +90,9 @@ export class DownloadManager {
|
||||||
const game = await gameRepository.findOne({
|
const game = await gameRepository.findOne({
|
||||||
where: { id: gameId, isDeleted: false },
|
where: { id: gameId, isDeleted: false },
|
||||||
});
|
});
|
||||||
|
const userPreferences = await userPreferencesRepository.findOneBy({
|
||||||
|
id: 1,
|
||||||
|
});
|
||||||
|
|
||||||
if (WindowManager.mainWindow && game) {
|
if (WindowManager.mainWindow && game) {
|
||||||
WindowManager.mainWindow.setProgressBar(progress === 1 ? -1 : progress);
|
WindowManager.mainWindow.setProgressBar(progress === 1 ? -1 : progress);
|
||||||
|
@ -127,6 +108,24 @@ export class DownloadManager {
|
||||||
}
|
}
|
||||||
if (progress === 1 && game) {
|
if (progress === 1 && game) {
|
||||||
publishDownloadCompleteNotification(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 });
|
await downloadQueueRepository.delete({ game });
|
||||||
const [nextQueueItem] = await downloadQueueRepository.find({
|
const [nextQueueItem] = await downloadQueueRepository.find({
|
||||||
order: {
|
order: {
|
||||||
|
@ -138,20 +137,24 @@ export class DownloadManager {
|
||||||
});
|
});
|
||||||
if (nextQueueItem) {
|
if (nextQueueItem) {
|
||||||
this.resumeDownload(nextQueueItem.game);
|
this.resumeDownload(nextQueueItem.game);
|
||||||
|
} else {
|
||||||
|
this.downloadingGameId = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getSeedStatus() {
|
public static async getSeedStatus() {
|
||||||
const seedStatus = await PythonRPC.rpc
|
const seedStatus = await PythonRPC.rpc.get<LibtorrentPayload[] | []>(
|
||||||
.get<LibtorrentPayload[] | null>("/seed-status")
|
"/seed-status"
|
||||||
.then((results) => {
|
);
|
||||||
if (results === null) return [];
|
|
||||||
return results.data;
|
|
||||||
});
|
|
||||||
|
|
||||||
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({
|
// const gamesToSeed = await gameRepository.find({
|
||||||
// where: { shouldSeed: true, isDeleted: false },
|
// where: { shouldSeed: true, isDeleted: false },
|
||||||
|
@ -209,8 +212,13 @@ export class DownloadManager {
|
||||||
// );
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
static async pauseSeeding(_gameId: number) {
|
static async pauseSeeding(gameId: number) {
|
||||||
// await TorrentDownloader.pauseSeeding(gameId);
|
await PythonRPC.rpc
|
||||||
|
.post("/action", {
|
||||||
|
action: "pause",
|
||||||
|
game_id: gameId,
|
||||||
|
} as PauseDownloadPayload)
|
||||||
|
.catch(() => { });
|
||||||
}
|
}
|
||||||
|
|
||||||
static async resumeSeeding(
|
static async resumeSeeding(
|
||||||
|
@ -227,7 +235,7 @@ export class DownloadManager {
|
||||||
action: "pause",
|
action: "pause",
|
||||||
game_id: this.downloadingGameId,
|
game_id: this.downloadingGameId,
|
||||||
} as PauseDownloadPayload)
|
} as PauseDownloadPayload)
|
||||||
.catch(() => {});
|
.catch(() => { });
|
||||||
|
|
||||||
WindowManager.mainWindow?.setProgressBar(-1);
|
WindowManager.mainWindow?.setProgressBar(-1);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { gameRepository } from "@main/repository";
|
import { gameRepository } from "@main/repository";
|
||||||
import { DownloadManager } from "./download/download-manager";
|
import { DownloadManager } from "./download/download-manager";
|
||||||
import { sleep } from "@main/helpers";
|
import { sleep } from "@main/helpers";
|
||||||
|
|
||||||
export const startSeedProcess = async () => {
|
export const startSeedProcess = async () => {
|
||||||
const seedList = await gameRepository.find({
|
const seedList = await gameRepository.find({
|
||||||
where: {
|
where: {
|
||||||
|
@ -21,4 +21,3 @@ export const startSeedProcess = async () => {
|
||||||
await sleep(100);
|
await sleep(100);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue