fix: fixing stale downloads not resetting

This commit is contained in:
Chubby Granny Chaser 2024-05-30 00:40:39 +01:00
parent 84c746ef35
commit 1171e95b87
No known key found for this signature in database
8 changed files with 25 additions and 21 deletions

View file

@ -63,6 +63,7 @@ declare global {
openGame: (gameId: number, executablePath: string) => Promise<void>;
closeGame: (gameId: number) => Promise<boolean>;
removeGameFromLibrary: (gameId: number) => Promise<void>;
removeGame: (gameId: number) => Promise<void>;
deleteGameFolder: (gameId: number) => Promise<unknown>;
getGameByObjectID: (objectID: string) => Promise<Game | null>;
onPlaytime: (cb: (gameId: number) => void) => () => Electron.IpcRenderer;

View file

@ -47,6 +47,18 @@ export function useDownload() {
updateLibrary();
};
const removeGameInstaller = async (gameId: number) => {
dispatch(setGameDeleting(gameId));
try {
await window.electron.deleteGameFolder(gameId);
await window.electron.removeGame(gameId);
updateLibrary();
} finally {
dispatch(removeGameFromDeleting(gameId));
}
};
const removeGameFromLibrary = (gameId: number) =>
window.electron.removeGameFromLibrary(gameId).then(() => {
updateLibrary();
@ -66,16 +78,6 @@ export function useDownload() {
}
};
const deleteGame = async (gameId: number) => {
dispatch(setGameDeleting(gameId));
try {
await window.electron.deleteGameFolder(gameId);
} finally {
dispatch(removeGameFromDeleting(gameId));
}
};
const isGameDeleting = (gameId: number) => {
return gamesWithDeletionInProgress.includes(gameId);
};
@ -90,7 +92,7 @@ export function useDownload() {
resumeDownload,
cancelDownload,
removeGameFromLibrary,
deleteGame,
removeGameInstaller,
isGameDeleting,
clearDownload: () => dispatch(clearDownload()),
setLastPacket: (packet: DownloadProgress) =>

View file

@ -41,7 +41,7 @@ export function Downloads() {
resumeDownload,
removeGameFromLibrary,
cancelDownload,
deleteGame,
removeGameInstaller,
isGameDeleting,
} = useDownload();
@ -224,10 +224,8 @@ export function Downloads() {
};
const handleDeleteGame = async () => {
if (gameToBeDeleted.current) {
await deleteGame(gameToBeDeleted.current);
await removeGameFromLibrary(gameToBeDeleted.current);
}
if (gameToBeDeleted.current)
await removeGameInstaller(gameToBeDeleted.current);
};
return (