mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: show notification on launch
This commit is contained in:
parent
9f76ae8c59
commit
d801bad49e
9 changed files with 72 additions and 19 deletions
|
@ -340,6 +340,7 @@
|
|||
"user_achievements": "{{displayName}}'s Achievements",
|
||||
"your_achievements": "Your Achievements",
|
||||
"unlocked_at": "Unlocked at:",
|
||||
"subscription_needed": "A Hydra Cloud subscription is needed to see this content"
|
||||
"subscription_needed": "A Hydra Cloud subscription is needed to see this content",
|
||||
"new_achievements_unlocked": "Unlocked {{achievementCount}} new achievements from {{gameCount}} games"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -342,6 +342,7 @@
|
|||
"your_achievements": "Suas Conquistas",
|
||||
"user_achievements": "Conquistas de {{displayName}}",
|
||||
"unlocked_at": "Desbloqueado em:",
|
||||
"subscription_needed": "Você precisa de uma assinatura Hydra Cloud para visualizar este conteúdo"
|
||||
"subscription_needed": "Você precisa de uma assinatura Hydra Cloud para visualizar este conteúdo",
|
||||
"new_achievements_unlocked": "{{achievementCount}} novas conquistas de {{gameCount}} jogos"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -284,6 +284,7 @@
|
|||
"achievement": {
|
||||
"achievement_unlocked": "Conquista desbloqueada",
|
||||
"unlocked_at": "Desbloqueado em:",
|
||||
"subscription_needed": "Você precisa de uma assinatura Hydra Cloud para visualizar este conteúdo"
|
||||
"subscription_needed": "Você precisa de uma assinatura Hydra Cloud para visualizar este conteúdo",
|
||||
"new_achievements_unlocked": "Encontradas {{achievementCount}} novas conquistas de {{gameCount}} jogos"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import type { AchievementFile, UnlockedAchievement } from "@types";
|
|||
import { achievementsLogger } from "../logger";
|
||||
import { Cracker } from "@shared";
|
||||
import { IsNull, Not } from "typeorm";
|
||||
import { WindowManager } from "../window-manager";
|
||||
|
||||
const fileStats: Map<string, number> = new Map();
|
||||
const fltFiles: Map<string, Set<string>> = new Map();
|
||||
|
@ -136,6 +137,8 @@ const processAchievementFileDiff = async (
|
|||
if (unlockedAchievements.length) {
|
||||
return mergeAchievements(game, unlockedAchievements, true);
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
export class AchievementWatcherManager {
|
||||
|
@ -234,11 +237,16 @@ export class AchievementWatcherManager {
|
|||
};
|
||||
|
||||
public static preSearchAchievements = async () => {
|
||||
if (process.platform === "win32") {
|
||||
await this.preSearchAchievementsWindows();
|
||||
} else {
|
||||
await this.preSearchAchievementsWithWine();
|
||||
}
|
||||
const newAchievementsCount =
|
||||
process.platform === "win32"
|
||||
? await this.preSearchAchievementsWindows()
|
||||
: await this.preSearchAchievementsWithWine();
|
||||
|
||||
WindowManager.notificationWindow?.webContents.send(
|
||||
"on-combined-achievements-unlocked",
|
||||
newAchievementsCount.filter((achievements) => achievements).length,
|
||||
newAchievementsCount.reduce((acc, val) => acc + val, 0)
|
||||
);
|
||||
|
||||
this.hasFinishedMergingWithRemote = true;
|
||||
};
|
||||
|
|
|
@ -201,10 +201,10 @@ const getPathFromCracker = (cracker: Cracker) => {
|
|||
|
||||
if (cracker === Cracker.flt) {
|
||||
return [
|
||||
{
|
||||
folderPath: path.join(appData, "FLT"),
|
||||
fileLocation: ["stats"],
|
||||
},
|
||||
// {
|
||||
// folderPath: path.join(appData, "FLT"),
|
||||
// fileLocation: ["stats"],
|
||||
// },
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -117,7 +117,7 @@ export const mergeAchievements = async (
|
|||
const mergedLocalAchievements = unlockedAchievements.concat(newAchievements);
|
||||
|
||||
if (game.remoteId) {
|
||||
return HydraApi.put(
|
||||
await HydraApi.put(
|
||||
"/profile/games/achievements",
|
||||
{
|
||||
id: game.remoteId,
|
||||
|
@ -141,12 +141,14 @@ export const mergeAchievements = async (
|
|||
publishNotification
|
||||
);
|
||||
});
|
||||
} else {
|
||||
await saveAchievementsOnLocal(
|
||||
game.objectID,
|
||||
game.shop,
|
||||
mergedLocalAchievements,
|
||||
publishNotification
|
||||
);
|
||||
}
|
||||
|
||||
return saveAchievementsOnLocal(
|
||||
game.objectID,
|
||||
game.shop,
|
||||
mergedLocalAchievements,
|
||||
publishNotification
|
||||
);
|
||||
return newAchievements.length;
|
||||
};
|
||||
|
|
|
@ -68,6 +68,18 @@ contextBridge.exposeInMainWorld("electron", {
|
|||
return () =>
|
||||
ipcRenderer.removeListener("on-achievement-unlocked", listener);
|
||||
},
|
||||
onCombinedAchievementsUnlocked: (
|
||||
cb: (gameCount: number, achievementsCount: number) => void
|
||||
) => {
|
||||
const listener = (
|
||||
_event: Electron.IpcRendererEvent,
|
||||
gameCount: number,
|
||||
achievementCount: number
|
||||
) => cb(gameCount, achievementCount);
|
||||
ipcRenderer.on("on-combined-achievements-unlocked", listener);
|
||||
return () =>
|
||||
ipcRenderer.removeListener("on-combined-achievements-unlocked", listener);
|
||||
},
|
||||
onUpdateAchievements: (
|
||||
objectId: string,
|
||||
shop: GameShop,
|
||||
|
|
3
src/renderer/src/declaration.d.ts
vendored
3
src/renderer/src/declaration.d.ts
vendored
|
@ -73,6 +73,9 @@ declare global {
|
|||
achievements?: { displayName: string; iconUrl: string }[]
|
||||
) => void
|
||||
) => () => Electron.IpcRenderer;
|
||||
onCombinedAchievementsUnlocked: (
|
||||
cb: (gameCount: number, achievementCount: number) => void
|
||||
) => () => Electron.IpcRenderer;
|
||||
onUpdateAchievements: (
|
||||
objectId: string,
|
||||
shop: GameShop,
|
||||
|
|
|
@ -31,6 +31,31 @@ export function AchievementNotification() {
|
|||
return audio;
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = window.electron.onCombinedAchievementsUnlocked(
|
||||
(gameCount, achievementCount) => {
|
||||
if (gameCount === 0 || achievementCount === 0) return;
|
||||
|
||||
setAchievements([
|
||||
{
|
||||
displayName: t("new_achievements_unlocked", {
|
||||
gameCount,
|
||||
achievementCount,
|
||||
}),
|
||||
iconUrl:
|
||||
"https://avatars.githubusercontent.com/u/164102380?s=400&u=01a13a7b4f0c642f7e547b8e1d70440ea06fa750&v=4",
|
||||
},
|
||||
]);
|
||||
|
||||
audio.play();
|
||||
}
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}, [audio]);
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = window.electron.onAchievementUnlocked(
|
||||
(_object, _shop, achievements) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue