mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: updated pauseGameSeed and resumeGameSeed events
This commit is contained in:
parent
fd5b2e08a5
commit
93ef0c256e
3 changed files with 19 additions and 12 deletions
|
@ -3,23 +3,22 @@ import { registerEvent } from "../register-event";
|
||||||
import { DownloadManager } from "@main/services";
|
import { DownloadManager } from "@main/services";
|
||||||
import { dataSource } from "@main/data-source";
|
import { dataSource } from "@main/data-source";
|
||||||
import { Game } from "@main/entity";
|
import { Game } from "@main/entity";
|
||||||
import { gameRepository } from "@main/repository";
|
|
||||||
|
|
||||||
const pauseGameSeed = async (
|
const pauseGameSeed = async (
|
||||||
_event: Electron.IpcMainInvokeEvent,
|
_event: Electron.IpcMainInvokeEvent,
|
||||||
gameId: number
|
gameId: number
|
||||||
) => {
|
) => {
|
||||||
const game = await gameRepository.findOneBy({ id: gameId });
|
|
||||||
|
|
||||||
if (game?.status !== "seeding") return;
|
|
||||||
|
|
||||||
await dataSource.transaction(async (transactionalEntityManager) => {
|
await dataSource.transaction(async (transactionalEntityManager) => {
|
||||||
await transactionalEntityManager
|
await transactionalEntityManager
|
||||||
.getRepository(Game)
|
.getRepository(Game)
|
||||||
.update({ id: gameId }, { status: "complete", shouldSeed: false });
|
.update(
|
||||||
|
{ id: gameId },
|
||||||
|
{ status: "complete", shouldSeed: false }
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
await DownloadManager.pauseSeeding(gameId);
|
await DownloadManager.cancelDownload(gameId);
|
||||||
};
|
};
|
||||||
|
|
||||||
registerEvent("pauseGameSeed", pauseGameSeed);
|
registerEvent("pauseGameSeed", pauseGameSeed);
|
||||||
|
|
|
@ -13,6 +13,8 @@ const resumeGameSeed = async (
|
||||||
where: {
|
where: {
|
||||||
id: gameId,
|
id: gameId,
|
||||||
isDeleted: false,
|
isDeleted: false,
|
||||||
|
downloader: 1,
|
||||||
|
progress: 1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -21,10 +23,13 @@ const resumeGameSeed = async (
|
||||||
await dataSource.transaction(async (transactionalEntityManager) => {
|
await dataSource.transaction(async (transactionalEntityManager) => {
|
||||||
await transactionalEntityManager
|
await transactionalEntityManager
|
||||||
.getRepository(Game)
|
.getRepository(Game)
|
||||||
.update({ id: gameId }, { status: "seeding", shouldSeed: true });
|
.update(
|
||||||
|
{ id: gameId },
|
||||||
|
{ status: "seeding", shouldSeed: true }
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
await DownloadManager.resumeDownload(game);
|
await DownloadManager.startDownload(game);
|
||||||
};
|
};
|
||||||
|
|
||||||
registerEvent("resumeGameSeed", resumeGameSeed);
|
registerEvent("resumeGameSeed", resumeGameSeed);
|
||||||
|
|
|
@ -122,7 +122,8 @@ export function DownloadGroup({
|
||||||
if (game.progress === 1) {
|
if (game.progress === 1) {
|
||||||
const uploadSpeed = formatBytes(seedingStatus?.uploadSpeed ?? 0);
|
const uploadSpeed = formatBytes(seedingStatus?.uploadSpeed ?? 0);
|
||||||
|
|
||||||
return game.status === "seeding" ? (
|
return game.status === "seeding" &&
|
||||||
|
game.downloader === Downloader.Torrent ? (
|
||||||
<>
|
<>
|
||||||
<p>{t("seeding")}</p>
|
<p>{t("seeding")}</p>
|
||||||
{uploadSpeed && <p>{uploadSpeed}/s</p>}
|
{uploadSpeed && <p>{uploadSpeed}/s</p>}
|
||||||
|
@ -171,13 +172,15 @@ export function DownloadGroup({
|
||||||
{
|
{
|
||||||
label: t("stop_seeding"),
|
label: t("stop_seeding"),
|
||||||
disabled: deleting,
|
disabled: deleting,
|
||||||
show: game.status === "seeding",
|
show:
|
||||||
|
game.status === "seeding" && game.downloader === Downloader.Torrent,
|
||||||
onClick: () => pauseSeeding(game.id),
|
onClick: () => pauseSeeding(game.id),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t("resume_seeding"),
|
label: t("resume_seeding"),
|
||||||
disabled: deleting,
|
disabled: deleting,
|
||||||
show: game.status !== "seeding",
|
show:
|
||||||
|
game.status !== "seeding" && game.downloader === Downloader.Torrent,
|
||||||
onClick: () => resumeSeeding(game.id),
|
onClick: () => resumeSeeding(game.id),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue