mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
"feat: pause seeding if game folder is deleted"
This commit is contained in:
parent
1416cd46a3
commit
a7b8018ed9
4 changed files with 40 additions and 0 deletions
|
@ -9,6 +9,8 @@ import type { DownloadProgress } from "@types";
|
|||
import { GofileApi, QiwiApi } from "../hosters";
|
||||
import { GenericHttpDownloader } from "./generic-http-downloader";
|
||||
import { In, Not } from "typeorm";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
export class DownloadManager {
|
||||
private static currentDownloader: Downloader | null = null;
|
||||
|
@ -85,6 +87,30 @@ export class DownloadManager {
|
|||
}
|
||||
|
||||
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({
|
||||
where: {
|
||||
id: In(gameIds),
|
||||
|
|
|
@ -39,6 +39,11 @@ contextBridge.exposeInMainWorld("electron", {
|
|||
ipcRenderer.on("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) => {
|
||||
const listener = (
|
||||
_event: Electron.IpcRendererEvent,
|
||||
|
|
|
@ -109,6 +109,14 @@ export function App() {
|
|||
};
|
||||
}, [clearDownload, setLastPacket, updateLibrary]);
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = window.electron.onHardDelete(() => {
|
||||
updateLibrary();
|
||||
});
|
||||
|
||||
return () => unsubscribe();
|
||||
}, [updateLibrary]);
|
||||
|
||||
useEffect(() => {
|
||||
const cachedUserDetails = window.localStorage.getItem("userDetails");
|
||||
|
||||
|
|
1
src/renderer/src/declaration.d.ts
vendored
1
src/renderer/src/declaration.d.ts
vendored
|
@ -55,6 +55,7 @@ declare global {
|
|||
onSeedingStatus: (
|
||||
cb: (value: SeedingStatus[]) => void
|
||||
) => () => Electron.IpcRenderer;
|
||||
onHardDelete: (cb: () => void) => () => Electron.IpcRenderer;
|
||||
|
||||
/* Catalogue */
|
||||
searchGames: (query: string) => Promise<CatalogueEntry[]>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue