From 73de69b5a68ddf071fa0fdfbd966421713de67e2 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Sun, 18 May 2025 21:28:45 -0300 Subject: [PATCH 1/5] feat: use shadow dom on theme editor for achievement notifications --- src/main/services/window-manager.ts | 11 +++++- .../src/pages/theme-editor/theme-editor.tsx | 39 +++++++++++++------ src/shared/index.ts | 9 +++-- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/main/services/window-manager.ts b/src/main/services/window-manager.ts index 8014c240..2a07e3fe 100644 --- a/src/main/services/window-manager.ts +++ b/src/main/services/window-manager.ts @@ -395,7 +395,16 @@ export class WindowManager { this.notificationWindow?.webContents.send( "on-achievement-unlocked", userPreferences.achievementCustomNotificationPosition ?? "top-left", - [generateAchievementCustomNotificationTest(t, language)] + [ + generateAchievementCustomNotificationTest(t, language), + generateAchievementCustomNotificationTest(t, language, { + isRare: true, + isHidden: true, + }), + generateAchievementCustomNotificationTest(t, language, { + isPlatinum: true, + }), + ] ); } diff --git a/src/renderer/src/pages/theme-editor/theme-editor.tsx b/src/renderer/src/pages/theme-editor/theme-editor.tsx index 94ad2e79..844c9a1c 100644 --- a/src/renderer/src/pages/theme-editor/theme-editor.tsx +++ b/src/renderer/src/pages/theme-editor/theme-editor.tsx @@ -11,6 +11,9 @@ import { injectCustomCss } from "@renderer/helpers"; import { AchievementNotificationItem } from "@renderer/components/achievements/notification/achievement-notification"; import { generateAchievementCustomNotificationTest } from "@shared"; import { CollapsedMenu } from "@renderer/components/collapsed-menu/collapsed-menu"; +import app from "../../app.scss?inline"; +import styles from "../../components/achievements/notification/achievement-notification.scss?inline"; +import root from "react-shadow"; const notificationVariations = { default: "default", @@ -36,14 +39,15 @@ export default function ThemeEditor() { const [notificationAlignment, setNotificationAlignment] = useState("top-left"); + const [shadowRootRef, setShadowRootRef] = useState(null); + const achievementPreview = useMemo(() => { return { - achievement: { - ...generateAchievementCustomNotificationTest(t, i18n.language), + achievement: generateAchievementCustomNotificationTest(t, i18n.language, { isRare: notificationVariation === "rare", isHidden: notificationVariation === "hidden", isPlatinum: notificationVariation === "platinum", - }, + }), position: notificationAlignment, }; }, [t, i18n.language, notificationVariation, notificationAlignment]); @@ -58,10 +62,13 @@ export default function ThemeEditor() { if (loadedTheme) { setTheme(loadedTheme); setCode(loadedTheme.code); + if (shadowRootRef) { + injectCustomCss(loadedTheme.code, shadowRootRef); + } } }); } - }, [themeId]); + }, [themeId, shadowRootRef]); const handleSave = useCallback(async () => { if (theme) { @@ -69,11 +76,14 @@ export default function ThemeEditor() { setHasUnsavedChanges(false); setIsClosingNotifications(true); setTimeout(() => { - injectCustomCss(code); + if (shadowRootRef) { + injectCustomCss(code, shadowRootRef); + } + setIsClosingNotifications(false); }, 450); } - }, [code, theme]); + }, [code, theme, shadowRootRef]); useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { @@ -185,11 +195,18 @@ export default function ThemeEditor() { />
- + + +
setShadowRootRef(ref)}> + +
+
diff --git a/src/shared/index.ts b/src/shared/index.ts index 98b20f10..2f35692f 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -179,7 +179,8 @@ export const formatDate = ( export const generateAchievementCustomNotificationTest = ( t: any, - language?: string + language?: string, + options: { isHidden?: boolean; isRare?: boolean; isPlatinum?: boolean } = {} ): AchievementNotificationInfo => { return { title: t("test_achievement_notification_title", { @@ -192,8 +193,8 @@ export const generateAchievementCustomNotificationTest = ( }), iconUrl: "https://cdn.losbroxas.org/favicon.svg", points: 2440, - isHidden: false, - isRare: false, - isPlatinum: false, + isHidden: options.isHidden ?? false, + isRare: options.isRare ?? false, + isPlatinum: options.isPlatinum ?? false, }; }; From e85d08422ec7282dc8b286a4fb81acfc4db07d4f Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Mon, 19 May 2025 07:23:46 -0300 Subject: [PATCH 2/5] feat: add option to disable friend starting game notification --- src/locales/en/translation.json | 3 ++- src/locales/pt-BR/translation.json | 3 ++- .../events/library/open-game-installer-path.ts | 6 ++---- .../services/ws/events/friend-game-session.ts | 16 +++++++++++++--- .../notification/achievement-notification.tsx | 2 +- src/renderer/src/declaration.d.ts | 5 +---- .../src/pages/settings/settings-general.tsx | 14 ++++++++++++++ src/types/level.types.ts | 1 + 8 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 93e18f17..af371fb7 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -379,7 +379,8 @@ "platinum": "Platinum", "hidden": "Hidden", "test_notification": "Test notification", - "notification_preview": "Achievement Notification Preview" + "notification_preview": "Achievement Notification Preview", + "enable_friend_start_game_notifications": "When a friend starts play a game" }, "notifications": { "download_complete": "Download complete", diff --git a/src/locales/pt-BR/translation.json b/src/locales/pt-BR/translation.json index c99fab6f..6b9546ec 100644 --- a/src/locales/pt-BR/translation.json +++ b/src/locales/pt-BR/translation.json @@ -365,7 +365,8 @@ "platinum": "Platina", "hidden": "Oculta", "test_notification": "Testar notificação", - "notification_preview": "Prévia da Notificação de Conquistas" + "notification_preview": "Prévia da Notificação de Conquistas", + "enable_friend_start_game_notifications": "Quando um amigo iniciar um jogo" }, "notifications": { "download_complete": "Download concluído", diff --git a/src/main/events/library/open-game-installer-path.ts b/src/main/events/library/open-game-installer-path.ts index b61246fa..0bbe96de 100644 --- a/src/main/events/library/open-game-installer-path.ts +++ b/src/main/events/library/open-game-installer-path.ts @@ -12,16 +12,14 @@ const openGameInstallerPath = async ( ) => { const download = await downloadsSublevel.get(levelKeys.game(shop, objectId)); - if (!download || !download.folderName || !download.downloadPath) return true; + if (!download?.folderName || !download.downloadPath) return; const gamePath = path.join( download.downloadPath ?? (await getDownloadsPath()), - download.folderName! + download.folderName ); shell.showItemInFolder(gamePath); - - return true; }; registerEvent("openGameInstallerPath", openGameInstallerPath); diff --git a/src/main/services/ws/events/friend-game-session.ts b/src/main/services/ws/events/friend-game-session.ts index 930b4885..47d8164e 100644 --- a/src/main/services/ws/events/friend-game-session.ts +++ b/src/main/services/ws/events/friend-game-session.ts @@ -1,15 +1,25 @@ import type { FriendGameSession } from "@main/generated/envelope"; +import { db, levelKeys } from "@main/level"; import { HydraApi } from "@main/services/hydra-api"; import { publishFriendStartedPlayingGameNotification } from "@main/services/notifications"; -import { GameStats } from "@types"; +import type { GameStats, UserPreferences, UserProfile } from "@types"; export const friendGameSessionEvent = async (payload: FriendGameSession) => { + const userPreferences = await db.get( + levelKeys.userPreferences, + { + valueEncoding: "json", + } + ); + + if (userPreferences?.friendStartGameNotificationsEnabled === false) return; + const [friend, gameStats] = await Promise.all([ - HydraApi.get(`/users/${payload.friendId}`), + HydraApi.get(`/users/${payload.friendId}`), HydraApi.get( `/games/stats?objectId=${payload.objectId}&shop=steam` ), - ]); + ]).catch(() => [null, null]); if (friend && gameStats) { publishFriendStartedPlayingGameNotification(friend, gameStats); diff --git a/src/renderer/src/components/achievements/notification/achievement-notification.tsx b/src/renderer/src/components/achievements/notification/achievement-notification.tsx index 7bb681fe..bcc22047 100644 --- a/src/renderer/src/components/achievements/notification/achievement-notification.tsx +++ b/src/renderer/src/components/achievements/notification/achievement-notification.tsx @@ -31,7 +31,7 @@ export function AchievementNotificationItem({ [`${baseClassName}--platinum`]: achievement.isPlatinum, })} > - {achievement.points && ( + {achievement.points !== undefined && (
diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index 3290d798..05d0cad0 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -139,10 +139,7 @@ declare global { verifyExecutablePathInUse: (executablePath: string) => Promise; getLibrary: () => Promise; openGameInstaller: (shop: GameShop, objectId: string) => Promise; - openGameInstallerPath: ( - shop: GameShop, - objectId: string - ) => Promise; + openGameInstallerPath: (shop: GameShop, objectId: string) => Promise; openGameExecutablePath: (shop: GameShop, objectId: string) => Promise; openGame: ( shop: GameShop, diff --git a/src/renderer/src/pages/settings/settings-general.tsx b/src/renderer/src/pages/settings/settings-general.tsx index ad4f1b82..c698440d 100644 --- a/src/renderer/src/pages/settings/settings-general.tsx +++ b/src/renderer/src/pages/settings/settings-general.tsx @@ -38,6 +38,7 @@ export function SettingsGeneral() { downloadNotificationsEnabled: false, repackUpdatesNotificationsEnabled: false, friendRequestNotificationsEnabled: false, + friendStartGameNotificationsEnabled: true, achievementNotificationsEnabled: true, achievementCustomNotificationsEnabled: true, achievementCustomNotificationPosition: @@ -111,6 +112,8 @@ export function SettingsGeneral() { userPreferences.achievementCustomNotificationPosition ?? "top-left", friendRequestNotificationsEnabled: userPreferences.friendRequestNotificationsEnabled ?? false, + friendStartGameNotificationsEnabled: + userPreferences.friendStartGameNotificationsEnabled ?? true, language: language ?? "en", })); } @@ -248,6 +251,17 @@ export function SettingsGeneral() { } /> + + handleChange({ + friendStartGameNotificationsEnabled: + !form.friendStartGameNotificationsEnabled, + }) + } + /> + Date: Mon, 19 May 2025 07:28:55 -0300 Subject: [PATCH 3/5] feat: open dev tools for theme editor --- src/main/services/window-manager.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/services/window-manager.ts b/src/main/services/window-manager.ts index 2a07e3fe..3d84d6f3 100644 --- a/src/main/services/window-manager.ts +++ b/src/main/services/window-manager.ts @@ -469,9 +469,8 @@ export class WindowManager { } }); - editorWindow.webContents.on("before-input-event", (event, input) => { + editorWindow.webContents.on("before-input-event", (_event, input) => { if (input.key === "F12") { - event.preventDefault(); this.mainWindow?.webContents.toggleDevTools(); } }); From f7b88b6d313d4bd367a312bd71f168e9173440ca Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Mon, 19 May 2025 10:59:54 -0300 Subject: [PATCH 4/5] chore: bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a802c6d1..27958b3f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hydralauncher", - "version": "3.5.1", + "version": "3.5.2", "description": "Hydra", "main": "./out/main/index.js", "author": "Los Broxas", From 9a0e3bfc6506d2ce116e6e017c784f29b996052c Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Mon, 19 May 2025 11:14:42 -0300 Subject: [PATCH 5/5] Update src/locales/en/translation.json Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- src/locales/en/translation.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index af371fb7..4adc5585 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -380,7 +380,7 @@ "hidden": "Hidden", "test_notification": "Test notification", "notification_preview": "Achievement Notification Preview", - "enable_friend_start_game_notifications": "When a friend starts play a game" + "enable_friend_start_game_notifications": "When a friend starts playing a game" }, "notifications": { "download_complete": "Download complete",