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",
|
"user_achievements": "{{displayName}}'s Achievements",
|
||||||
"your_achievements": "Your Achievements",
|
"your_achievements": "Your Achievements",
|
||||||
"unlocked_at": "Unlocked at:",
|
"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",
|
"your_achievements": "Suas Conquistas",
|
||||||
"user_achievements": "Conquistas de {{displayName}}",
|
"user_achievements": "Conquistas de {{displayName}}",
|
||||||
"unlocked_at": "Desbloqueado em:",
|
"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": {
|
||||||
"achievement_unlocked": "Conquista desbloqueada",
|
"achievement_unlocked": "Conquista desbloqueada",
|
||||||
"unlocked_at": "Desbloqueado em:",
|
"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 { achievementsLogger } from "../logger";
|
||||||
import { Cracker } from "@shared";
|
import { Cracker } from "@shared";
|
||||||
import { IsNull, Not } from "typeorm";
|
import { IsNull, Not } from "typeorm";
|
||||||
|
import { WindowManager } from "../window-manager";
|
||||||
|
|
||||||
const fileStats: Map<string, number> = new Map();
|
const fileStats: Map<string, number> = new Map();
|
||||||
const fltFiles: Map<string, Set<string>> = new Map();
|
const fltFiles: Map<string, Set<string>> = new Map();
|
||||||
|
@ -136,6 +137,8 @@ const processAchievementFileDiff = async (
|
||||||
if (unlockedAchievements.length) {
|
if (unlockedAchievements.length) {
|
||||||
return mergeAchievements(game, unlockedAchievements, true);
|
return mergeAchievements(game, unlockedAchievements, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class AchievementWatcherManager {
|
export class AchievementWatcherManager {
|
||||||
|
@ -234,11 +237,16 @@ export class AchievementWatcherManager {
|
||||||
};
|
};
|
||||||
|
|
||||||
public static preSearchAchievements = async () => {
|
public static preSearchAchievements = async () => {
|
||||||
if (process.platform === "win32") {
|
const newAchievementsCount =
|
||||||
await this.preSearchAchievementsWindows();
|
process.platform === "win32"
|
||||||
} else {
|
? await this.preSearchAchievementsWindows()
|
||||||
await this.preSearchAchievementsWithWine();
|
: 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;
|
this.hasFinishedMergingWithRemote = true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -201,10 +201,10 @@ const getPathFromCracker = (cracker: Cracker) => {
|
||||||
|
|
||||||
if (cracker === Cracker.flt) {
|
if (cracker === Cracker.flt) {
|
||||||
return [
|
return [
|
||||||
{
|
// {
|
||||||
folderPath: path.join(appData, "FLT"),
|
// folderPath: path.join(appData, "FLT"),
|
||||||
fileLocation: ["stats"],
|
// fileLocation: ["stats"],
|
||||||
},
|
// },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ export const mergeAchievements = async (
|
||||||
const mergedLocalAchievements = unlockedAchievements.concat(newAchievements);
|
const mergedLocalAchievements = unlockedAchievements.concat(newAchievements);
|
||||||
|
|
||||||
if (game.remoteId) {
|
if (game.remoteId) {
|
||||||
return HydraApi.put(
|
await HydraApi.put(
|
||||||
"/profile/games/achievements",
|
"/profile/games/achievements",
|
||||||
{
|
{
|
||||||
id: game.remoteId,
|
id: game.remoteId,
|
||||||
|
@ -141,12 +141,14 @@ export const mergeAchievements = async (
|
||||||
publishNotification
|
publishNotification
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
await saveAchievementsOnLocal(
|
||||||
|
game.objectID,
|
||||||
|
game.shop,
|
||||||
|
mergedLocalAchievements,
|
||||||
|
publishNotification
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return saveAchievementsOnLocal(
|
return newAchievements.length;
|
||||||
game.objectID,
|
|
||||||
game.shop,
|
|
||||||
mergedLocalAchievements,
|
|
||||||
publishNotification
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -68,6 +68,18 @@ contextBridge.exposeInMainWorld("electron", {
|
||||||
return () =>
|
return () =>
|
||||||
ipcRenderer.removeListener("on-achievement-unlocked", listener);
|
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: (
|
onUpdateAchievements: (
|
||||||
objectId: string,
|
objectId: string,
|
||||||
shop: GameShop,
|
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 }[]
|
achievements?: { displayName: string; iconUrl: string }[]
|
||||||
) => void
|
) => void
|
||||||
) => () => Electron.IpcRenderer;
|
) => () => Electron.IpcRenderer;
|
||||||
|
onCombinedAchievementsUnlocked: (
|
||||||
|
cb: (gameCount: number, achievementCount: number) => void
|
||||||
|
) => () => Electron.IpcRenderer;
|
||||||
onUpdateAchievements: (
|
onUpdateAchievements: (
|
||||||
objectId: string,
|
objectId: string,
|
||||||
shop: GameShop,
|
shop: GameShop,
|
||||||
|
|
|
@ -31,6 +31,31 @@ export function AchievementNotification() {
|
||||||
return audio;
|
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(() => {
|
useEffect(() => {
|
||||||
const unsubscribe = window.electron.onAchievementUnlocked(
|
const unsubscribe = window.electron.onAchievementUnlocked(
|
||||||
(_object, _shop, achievements) => {
|
(_object, _shop, achievements) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue