Skip to content

Commit 81cecfe

Browse files
authored
Merge pull request #1708 from hydralauncher/fix/HYD-828
fix: ensure achievement notification preview has same styles as actual notification [HYD-828]
2 parents 650b02e + 9a0e3bf commit 81cecfe

File tree

12 files changed

+81
-33
lines changed

12 files changed

+81
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hydralauncher",
3-
"version": "3.5.1",
3+
"version": "3.5.2",
44
"description": "Hydra",
55
"main": "./out/main/index.js",
66
"author": "Los Broxas",

src/locales/en/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@
379379
"platinum": "Platinum",
380380
"hidden": "Hidden",
381381
"test_notification": "Test notification",
382-
"notification_preview": "Achievement Notification Preview"
382+
"notification_preview": "Achievement Notification Preview",
383+
"enable_friend_start_game_notifications": "When a friend starts playing a game"
383384
},
384385
"notifications": {
385386
"download_complete": "Download complete",

src/locales/pt-BR/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@
365365
"platinum": "Platina",
366366
"hidden": "Oculta",
367367
"test_notification": "Testar notificação",
368-
"notification_preview": "Prévia da Notificação de Conquistas"
368+
"notification_preview": "Prévia da Notificação de Conquistas",
369+
"enable_friend_start_game_notifications": "Quando um amigo iniciar um jogo"
369370
},
370371
"notifications": {
371372
"download_complete": "Download concluído",

src/main/events/library/open-game-installer-path.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ const openGameInstallerPath = async (
1212
) => {
1313
const download = await downloadsSublevel.get(levelKeys.game(shop, objectId));
1414

15-
if (!download || !download.folderName || !download.downloadPath) return true;
15+
if (!download?.folderName || !download.downloadPath) return;
1616

1717
const gamePath = path.join(
1818
download.downloadPath ?? (await getDownloadsPath()),
19-
download.folderName!
19+
download.folderName
2020
);
2121

2222
shell.showItemInFolder(gamePath);
23-
24-
return true;
2523
};
2624

2725
registerEvent("openGameInstallerPath", openGameInstallerPath);

src/main/services/window-manager.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,16 @@ export class WindowManager {
395395
this.notificationWindow?.webContents.send(
396396
"on-achievement-unlocked",
397397
userPreferences.achievementCustomNotificationPosition ?? "top-left",
398-
[generateAchievementCustomNotificationTest(t, language)]
398+
[
399+
generateAchievementCustomNotificationTest(t, language),
400+
generateAchievementCustomNotificationTest(t, language, {
401+
isRare: true,
402+
isHidden: true,
403+
}),
404+
generateAchievementCustomNotificationTest(t, language, {
405+
isPlatinum: true,
406+
}),
407+
]
399408
);
400409
}
401410

@@ -460,9 +469,8 @@ export class WindowManager {
460469
}
461470
});
462471

463-
editorWindow.webContents.on("before-input-event", (event, input) => {
472+
editorWindow.webContents.on("before-input-event", (_event, input) => {
464473
if (input.key === "F12") {
465-
event.preventDefault();
466474
this.mainWindow?.webContents.toggleDevTools();
467475
}
468476
});

src/main/services/ws/events/friend-game-session.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import type { FriendGameSession } from "@main/generated/envelope";
2+
import { db, levelKeys } from "@main/level";
23
import { HydraApi } from "@main/services/hydra-api";
34
import { publishFriendStartedPlayingGameNotification } from "@main/services/notifications";
4-
import { GameStats } from "@types";
5+
import type { GameStats, UserPreferences, UserProfile } from "@types";
56

67
export const friendGameSessionEvent = async (payload: FriendGameSession) => {
8+
const userPreferences = await db.get<string, UserPreferences | null>(
9+
levelKeys.userPreferences,
10+
{
11+
valueEncoding: "json",
12+
}
13+
);
14+
15+
if (userPreferences?.friendStartGameNotificationsEnabled === false) return;
16+
717
const [friend, gameStats] = await Promise.all([
8-
HydraApi.get(`/users/${payload.friendId}`),
18+
HydraApi.get<UserProfile>(`/users/${payload.friendId}`),
919
HydraApi.get<GameStats>(
1020
`/games/stats?objectId=${payload.objectId}&shop=steam`
1121
),
12-
]);
22+
]).catch(() => [null, null]);
1323

1424
if (friend && gameStats) {
1525
publishFriendStartedPlayingGameNotification(friend, gameStats);

src/renderer/src/components/achievements/notification/achievement-notification.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function AchievementNotificationItem({
3131
[`${baseClassName}--platinum`]: achievement.isPlatinum,
3232
})}
3333
>
34-
{achievement.points && (
34+
{achievement.points !== undefined && (
3535
<div className="achievement-notification__chip">
3636
<HydraIcon className="achievement-notification__chip__icon" />
3737
<span className="achievement-notification__chip__label">

src/renderer/src/declaration.d.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,7 @@ declare global {
139139
verifyExecutablePathInUse: (executablePath: string) => Promise<Game>;
140140
getLibrary: () => Promise<LibraryGame[]>;
141141
openGameInstaller: (shop: GameShop, objectId: string) => Promise<boolean>;
142-
openGameInstallerPath: (
143-
shop: GameShop,
144-
objectId: string
145-
) => Promise<boolean>;
142+
openGameInstallerPath: (shop: GameShop, objectId: string) => Promise<void>;
146143
openGameExecutablePath: (shop: GameShop, objectId: string) => Promise<void>;
147144
openGame: (
148145
shop: GameShop,

src/renderer/src/pages/settings/settings-general.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export function SettingsGeneral() {
3838
downloadNotificationsEnabled: false,
3939
repackUpdatesNotificationsEnabled: false,
4040
friendRequestNotificationsEnabled: false,
41+
friendStartGameNotificationsEnabled: true,
4142
achievementNotificationsEnabled: true,
4243
achievementCustomNotificationsEnabled: true,
4344
achievementCustomNotificationPosition:
@@ -111,6 +112,8 @@ export function SettingsGeneral() {
111112
userPreferences.achievementCustomNotificationPosition ?? "top-left",
112113
friendRequestNotificationsEnabled:
113114
userPreferences.friendRequestNotificationsEnabled ?? false,
115+
friendStartGameNotificationsEnabled:
116+
userPreferences.friendStartGameNotificationsEnabled ?? true,
114117
language: language ?? "en",
115118
}));
116119
}
@@ -248,6 +251,17 @@ export function SettingsGeneral() {
248251
}
249252
/>
250253

254+
<CheckboxField
255+
label={t("enable_friend_start_game_notifications")}
256+
checked={form.friendStartGameNotificationsEnabled}
257+
onChange={() =>
258+
handleChange({
259+
friendStartGameNotificationsEnabled:
260+
!form.friendStartGameNotificationsEnabled,
261+
})
262+
}
263+
/>
264+
251265
<CheckboxField
252266
label={t("enable_achievement_notifications")}
253267
checked={form.achievementNotificationsEnabled}

src/renderer/src/pages/theme-editor/theme-editor.tsx

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { injectCustomCss } from "@renderer/helpers";
1111
import { AchievementNotificationItem } from "@renderer/components/achievements/notification/achievement-notification";
1212
import { generateAchievementCustomNotificationTest } from "@shared";
1313
import { CollapsedMenu } from "@renderer/components/collapsed-menu/collapsed-menu";
14+
import app from "../../app.scss?inline";
15+
import styles from "../../components/achievements/notification/achievement-notification.scss?inline";
16+
import root from "react-shadow";
1417

1518
const notificationVariations = {
1619
default: "default",
@@ -36,14 +39,15 @@ export default function ThemeEditor() {
3639
const [notificationAlignment, setNotificationAlignment] =
3740
useState<AchievementCustomNotificationPosition>("top-left");
3841

42+
const [shadowRootRef, setShadowRootRef] = useState<HTMLElement | null>(null);
43+
3944
const achievementPreview = useMemo(() => {
4045
return {
41-
achievement: {
42-
...generateAchievementCustomNotificationTest(t, i18n.language),
46+
achievement: generateAchievementCustomNotificationTest(t, i18n.language, {
4347
isRare: notificationVariation === "rare",
4448
isHidden: notificationVariation === "hidden",
4549
isPlatinum: notificationVariation === "platinum",
46-
},
50+
}),
4751
position: notificationAlignment,
4852
};
4953
}, [t, i18n.language, notificationVariation, notificationAlignment]);
@@ -58,22 +62,28 @@ export default function ThemeEditor() {
5862
if (loadedTheme) {
5963
setTheme(loadedTheme);
6064
setCode(loadedTheme.code);
65+
if (shadowRootRef) {
66+
injectCustomCss(loadedTheme.code, shadowRootRef);
67+
}
6168
}
6269
});
6370
}
64-
}, [themeId]);
71+
}, [themeId, shadowRootRef]);
6572

6673
const handleSave = useCallback(async () => {
6774
if (theme) {
6875
await window.electron.updateCustomTheme(theme.id, code);
6976
setHasUnsavedChanges(false);
7077
setIsClosingNotifications(true);
7178
setTimeout(() => {
72-
injectCustomCss(code);
79+
if (shadowRootRef) {
80+
injectCustomCss(code, shadowRootRef);
81+
}
82+
7383
setIsClosingNotifications(false);
7484
}, 450);
7585
}
76-
}, [code, theme]);
86+
}, [code, theme, shadowRootRef]);
7787

7888
useEffect(() => {
7989
const handleKeyDown = (event: KeyboardEvent) => {
@@ -185,11 +195,18 @@ export default function ThemeEditor() {
185195
/>
186196

187197
<div className="theme-editor__notification-preview-wrapper">
188-
<AchievementNotificationItem
189-
position={achievementPreview.position}
190-
achievement={achievementPreview.achievement}
191-
isClosing={isClosingNotifications}
192-
/>
198+
<root.div>
199+
<style type="text/css">
200+
{app} {styles}
201+
</style>
202+
<section ref={(ref) => setShadowRootRef(ref)}>
203+
<AchievementNotificationItem
204+
position={achievementPreview.position}
205+
achievement={achievementPreview.achievement}
206+
isClosing={isClosingNotifications}
207+
/>
208+
</section>
209+
</root.div>
193210
</div>
194211
</div>
195212
</CollapsedMenu>

0 commit comments

Comments
 (0)