"feat: pause seeding if game folder is deleted"

This commit is contained in:
Hachi-R 2024-11-11 16:24:04 -03:00
parent 1416cd46a3
commit a7b8018ed9
4 changed files with 40 additions and 0 deletions

View file

@ -9,6 +9,8 @@ import type { DownloadProgress } from "@types";
import { GofileApi, QiwiApi } from "../hosters"; import { GofileApi, QiwiApi } from "../hosters";
import { GenericHttpDownloader } from "./generic-http-downloader"; import { GenericHttpDownloader } from "./generic-http-downloader";
import { In, Not } from "typeorm"; import { In, Not } from "typeorm";
import path from "path";
import fs from "fs";
export class DownloadManager { export class DownloadManager {
private static currentDownloader: Downloader | null = null; private static currentDownloader: Downloader | null = null;
@ -85,6 +87,30 @@ export class DownloadManager {
} }
const gameIds = seedStatus.map((status) => status.gameId); const gameIds = seedStatus.map((status) => status.gameId);
for (const gameId of gameIds) {
const game = await gameRepository.findOne({
where: { id: gameId },
});
if (game) {
const isNotDeleted = fs.existsSync(
path.join(game.downloadPath!, game.folderName!)
);
if (!isNotDeleted) {
await this.pauseSeeding(game.id);
await gameRepository.update(game.id, {
status: "complete",
shouldSeed: false,
});
WindowManager.mainWindow?.webContents.send("on-hard-delete");
}
}
}
const updateList = await gameRepository.find({ const updateList = await gameRepository.find({
where: { where: {
id: In(gameIds), id: In(gameIds),

View file

@ -39,6 +39,11 @@ contextBridge.exposeInMainWorld("electron", {
ipcRenderer.on("on-download-progress", listener); ipcRenderer.on("on-download-progress", listener);
return () => ipcRenderer.removeListener("on-download-progress", listener); return () => ipcRenderer.removeListener("on-download-progress", listener);
}, },
onHardDelete: (cb: () => void) => {
const listener = (_event: Electron.IpcRendererEvent) => cb();
ipcRenderer.on("on-hard-delete", listener);
return () => ipcRenderer.removeListener("on-hard-delete", listener);
},
onSeedingStatus: (cb: (value: SeedingStatus[]) => void) => { onSeedingStatus: (cb: (value: SeedingStatus[]) => void) => {
const listener = ( const listener = (
_event: Electron.IpcRendererEvent, _event: Electron.IpcRendererEvent,

View file

@ -109,6 +109,14 @@ export function App() {
}; };
}, [clearDownload, setLastPacket, updateLibrary]); }, [clearDownload, setLastPacket, updateLibrary]);
useEffect(() => {
const unsubscribe = window.electron.onHardDelete(() => {
updateLibrary();
});
return () => unsubscribe();
}, [updateLibrary]);
useEffect(() => { useEffect(() => {
const cachedUserDetails = window.localStorage.getItem("userDetails"); const cachedUserDetails = window.localStorage.getItem("userDetails");

View file

@ -55,6 +55,7 @@ declare global {
onSeedingStatus: ( onSeedingStatus: (
cb: (value: SeedingStatus[]) => void cb: (value: SeedingStatus[]) => void
) => () => Electron.IpcRenderer; ) => () => Electron.IpcRenderer;
onHardDelete: (cb: () => void) => () => Electron.IpcRenderer;
/* Catalogue */ /* Catalogue */
searchGames: (query: string) => Promise<CatalogueEntry[]>; searchGames: (query: string) => Promise<CatalogueEntry[]>;