mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-12 19:22:28 +00:00
feat: implement reset game achievements functionality
This commit is contained in:
parent
47a5f4d327
commit
ac6eb247df
6 changed files with 65 additions and 5 deletions
|
@ -25,6 +25,7 @@ import "./library/verify-executable-path";
|
|||
import "./library/remove-game";
|
||||
import "./library/remove-game-from-library";
|
||||
import "./library/select-game-wine-prefix";
|
||||
import "./library/reset-game-achievements";
|
||||
import "./misc/open-checkout";
|
||||
import "./misc/open-external";
|
||||
import "./misc/show-open-dialog";
|
||||
|
|
52
src/main/events/library/reset-game-achievements.ts
Normal file
52
src/main/events/library/reset-game-achievements.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import { gameAchievementRepository, gameRepository } from "@main/repository";
|
||||
import { registerEvent } from "../register-event";
|
||||
import { findAchievementFiles } from "@main/services/achievements/find-achivement-files";
|
||||
import fs from "fs";
|
||||
import { WindowManager } from "@main/services";
|
||||
import { getUnlockedAchievements } from "../user/get-unlocked-achievements";
|
||||
|
||||
const resetGameAchievements = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
gameId: number
|
||||
) => {
|
||||
const game = await gameRepository.findOne({ where: { id: gameId } });
|
||||
|
||||
if (!game) return;
|
||||
|
||||
const achievementFiles = findAchievementFiles(game);
|
||||
|
||||
if (achievementFiles.length) {
|
||||
try {
|
||||
await Promise.all(
|
||||
achievementFiles.map(async (achievementFile) => {
|
||||
await fs.promises.rm(achievementFile.filePath, { recursive: true });
|
||||
})
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
await gameAchievementRepository.update(
|
||||
{ objectId: game.objectID },
|
||||
{
|
||||
unlockedAchievements: null,
|
||||
achievements: null,
|
||||
}
|
||||
);
|
||||
|
||||
// TODO: remove from db
|
||||
|
||||
const gameAchievements = await getUnlockedAchievements(
|
||||
game.objectID,
|
||||
game.shop,
|
||||
false
|
||||
);
|
||||
|
||||
WindowManager.mainWindow?.webContents.send(
|
||||
`on-update-achievements-${game.objectID}-${game.shop}`,
|
||||
gameAchievements
|
||||
);
|
||||
};
|
||||
|
||||
registerEvent("resetGameAchievements", resetGameAchievements);
|
|
@ -110,6 +110,8 @@ contextBridge.exposeInMainWorld("electron", {
|
|||
ipcRenderer.invoke("deleteGameFolder", gameId),
|
||||
getGameByObjectId: (objectId: string) =>
|
||||
ipcRenderer.invoke("getGameByObjectId", objectId),
|
||||
resetGameAchievements: (gameId: number) =>
|
||||
ipcRenderer.invoke("resetGameAchievements", gameId),
|
||||
onGamesRunning: (
|
||||
cb: (
|
||||
gamesRunning: Pick<GameRunning, "id" | "sessionDurationInMillis">[]
|
||||
|
|
2
src/renderer/src/declaration.d.ts
vendored
2
src/renderer/src/declaration.d.ts
vendored
|
@ -105,7 +105,7 @@ declare global {
|
|||
) => void
|
||||
) => () => Electron.IpcRenderer;
|
||||
onLibraryBatchComplete: (cb: () => void) => () => Electron.IpcRenderer;
|
||||
|
||||
resetGameAchievements: (gameId: number) => Promise<void>;
|
||||
/* User preferences */
|
||||
getUserPreferences: () => Promise<UserPreferences | null>;
|
||||
updateUserPreferences: (
|
||||
|
|
|
@ -122,6 +122,11 @@ export function GameOptionsModal({
|
|||
const shouldShowWinePrefixConfiguration =
|
||||
window.electron.platform === "linux";
|
||||
|
||||
const handleResetAchievements = async () => {
|
||||
await window.electron.resetGameAchievements(game.id);
|
||||
updateGame();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<DeleteGameModal
|
||||
|
@ -140,7 +145,7 @@ export function GameOptionsModal({
|
|||
<ResetAchievementsModal
|
||||
visible={showResetAchievementsModal}
|
||||
onClose={() => setShowResetAchievementsModal(false)}
|
||||
// resetAchievements={handleResetAchievements}
|
||||
resetAchievements={handleResetAchievements}
|
||||
game={game}
|
||||
/>
|
||||
|
||||
|
|
|
@ -7,19 +7,19 @@ interface ResetAchievementsModalProps {
|
|||
visible: boolean;
|
||||
game: Game;
|
||||
onClose: () => void;
|
||||
// resetAchievements: () => Promise<void>;
|
||||
resetAchievements: () => Promise<void>;
|
||||
}
|
||||
|
||||
export function ResetAchievementsModal({
|
||||
onClose,
|
||||
game,
|
||||
visible,
|
||||
// resetAchievements,
|
||||
resetAchievements,
|
||||
}: ResetAchievementsModalProps) {
|
||||
const { t } = useTranslation("game_details");
|
||||
|
||||
const handleResetAchievements = async () => {
|
||||
// await resetAchievements();
|
||||
await resetAchievements();
|
||||
onClose();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue