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…", "verifying": "Verifying…",
"completed_at": "Completed in {{date}}", "completed_at": "Completed in {{date}}",
"completed": "Completed", "completed": "Completed",
"removed": "Cancelled", "removed": "Not downloaded",
"download_again": "Download again", "download_again": "Download again",
"cancel": "Cancel", "cancel": "Cancel",
"filter": "Filter downloaded games", "filter": "Filter downloaded games",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -47,6 +47,18 @@ export function useDownload() {
updateLibrary(); 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) => const removeGameFromLibrary = (gameId: number) =>
window.electron.removeGameFromLibrary(gameId).then(() => { window.electron.removeGameFromLibrary(gameId).then(() => {
updateLibrary(); 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) => { const isGameDeleting = (gameId: number) => {
return gamesWithDeletionInProgress.includes(gameId); return gamesWithDeletionInProgress.includes(gameId);
}; };
@ -90,7 +92,7 @@ export function useDownload() {
resumeDownload, resumeDownload,
cancelDownload, cancelDownload,
removeGameFromLibrary, removeGameFromLibrary,
deleteGame, removeGameInstaller,
isGameDeleting, isGameDeleting,
clearDownload: () => dispatch(clearDownload()), clearDownload: () => dispatch(clearDownload()),
setLastPacket: (packet: DownloadProgress) => setLastPacket: (packet: DownloadProgress) =>

View File

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