feat: adding toast component

This commit is contained in:
Chubby Granny Chaser
2024-05-22 00:12:57 +01:00
parent da607fe741
commit 0162ebd133
13 changed files with 136 additions and 82 deletions

View File

@@ -1,7 +1,11 @@
import { Not } from "typeorm";
import { registerEvent } from "../register-event";
import { gameRepository } from "../../repository";
import { DownloadManager } from "@main/services";
import { dataSource } from "@main/data-source";
import { Game } from "@main/entity";
const resumeGameDownload = async (
_event: Electron.IpcMainInvokeEvent,
@@ -18,11 +22,19 @@ const resumeGameDownload = async (
if (!game) return;
if (game.status === "paused") {
await DownloadManager.pauseDownload();
await dataSource.transaction(async (transactionalEntityManager) => {
await DownloadManager.pauseDownload();
await gameRepository.update({ id: gameId }, { status: "active" });
await transactionalEntityManager
.getRepository(Game)
.update({ status: "active", progress: Not(1) }, { status: "paused" });
await DownloadManager.resumeDownload(gameId);
await DownloadManager.resumeDownload(gameId);
await transactionalEntityManager
.getRepository(Game)
.update({ id: gameId }, { status: "active" });
});
}
};

View File

@@ -44,6 +44,8 @@ const startGameDownload = async (
if (!repack || game?.status === "active") return;
await DownloadManager.pauseDownload();
await gameRepository.update(
{ status: "active", progress: Not(1) },
{ status: "paused" }
@@ -65,9 +67,7 @@ const startGameDownload = async (
await DownloadManager.startDownload(game.id);
game.status = "active";
return game;
return { ...game, stauts: "active" };
} else {
const steamGame = stateManager
.getValue("steamGames")
@@ -98,11 +98,9 @@ const startGameDownload = async (
return result;
});
DownloadManager.startDownload(createdGame.id);
await DownloadManager.startDownload(createdGame.id);
const { repack: _, ...rest } = createdGame;
return rest;
return createdGame;
}
};

View File

@@ -30,7 +30,16 @@ export class DownloadManager {
"aria2c"
);
spawn(binary, ["--enable-rpc", "--rpc-listen-all"], { stdio: "inherit" });
spawn(
binary,
[
"--enable-rpc",
"--rpc-listen-all",
"--file-allocation=none",
"--allow-overwrite=true",
],
{ stdio: "inherit" }
);
await this.aria2.open();
this.attachListener();
@@ -76,6 +85,7 @@ export class DownloadManager {
}
private static async attachListener() {
// eslint-disable-next-line no-constant-condition
while (true) {
try {
if (!this.gid || !this.gameId) {
@@ -205,8 +215,6 @@ export class DownloadManager {
}
static async resumeDownload(gameId: number) {
await this.aria2.call("forcePauseAll");
if (this.downloads.has(gameId)) {
const gid = this.downloads.get(gameId)!;
await this.aria2.call("unpause", gid);
@@ -219,8 +227,6 @@ export class DownloadManager {
}
static async startDownload(gameId: number) {
await this.aria2.call("forcePauseAll");
const game = await this.getGame(gameId)!;
if (game) {