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

@ -123,7 +123,7 @@
"verifying": "Verifying…",
"completed_at": "Completed in {{date}}",
"completed": "Completed",
"removed": "Cancelled",
"removed": "Not downloaded",
"download_again": "Download again",
"cancel": "Cancel",
"filter": "Filter downloaded games",

View File

@ -119,7 +119,7 @@
"verifying": "Verificando…",
"completed_at": "Concluído em {{date}}",
"completed": "Concluído",
"removed": "Cancelado",
"removed": "Não baixado",
"download_again": "Baixar novamente",
"cancel": "Cancelar",
"filter": "Filtrar jogos baixados",

View File

@ -8,10 +8,9 @@ const removeGame = async (
await gameRepository.update(
{
id: gameId,
status: "removed",
},
{
status: null,
status: "removed",
downloadPath: null,
bytesDownloaded: 0,
progress: 0,

View File

@ -18,6 +18,7 @@ const startGameDownload = async (
gameRepository.findOne({
where: {
objectID,
shop,
},
relations: { repack: true },
}),
@ -28,7 +29,7 @@ const startGameDownload = async (
}),
]);
if (!repack || game?.status === "active") return;
if (!repack) return;
await DownloadManager.pauseDownload();
@ -44,6 +45,8 @@ const startGameDownload = async (
},
{
status: "active",
progress: 0,
bytesDownloaded: 0,
downloadPath,
downloader,
repack: { id: repackId },

View File

@ -74,6 +74,7 @@ contextBridge.exposeInMainWorld("electron", {
closeGame: (gameId: number) => ipcRenderer.invoke("closeGame", gameId),
removeGameFromLibrary: (gameId: number) =>
ipcRenderer.invoke("removeGameFromLibrary", gameId),
removeGame: (gameId: number) => ipcRenderer.invoke("removeGame", gameId),
deleteGameFolder: (gameId: number) =>
ipcRenderer.invoke("deleteGameFolder", gameId),
getGameByObjectID: (objectID: string) =>

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 (