feat: add option to disable friend starting game notification

This commit is contained in:
Zamitto
2025-05-19 07:23:46 -03:00
parent 73de69b5a6
commit e85d08422e
8 changed files with 36 additions and 14 deletions

View File

@@ -379,7 +379,8 @@
"platinum": "Platinum", "platinum": "Platinum",
"hidden": "Hidden", "hidden": "Hidden",
"test_notification": "Test notification", "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": { "notifications": {
"download_complete": "Download complete", "download_complete": "Download complete",

View File

@@ -365,7 +365,8 @@
"platinum": "Platina", "platinum": "Platina",
"hidden": "Oculta", "hidden": "Oculta",
"test_notification": "Testar notificação", "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": { "notifications": {
"download_complete": "Download concluído", "download_complete": "Download concluído",

View File

@@ -12,16 +12,14 @@ const openGameInstallerPath = async (
) => { ) => {
const download = await downloadsSublevel.get(levelKeys.game(shop, objectId)); 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( const gamePath = path.join(
download.downloadPath ?? (await getDownloadsPath()), download.downloadPath ?? (await getDownloadsPath()),
download.folderName! download.folderName
); );
shell.showItemInFolder(gamePath); shell.showItemInFolder(gamePath);
return true;
}; };
registerEvent("openGameInstallerPath", openGameInstallerPath); registerEvent("openGameInstallerPath", openGameInstallerPath);

View File

@@ -1,15 +1,25 @@
import type { FriendGameSession } from "@main/generated/envelope"; import type { FriendGameSession } from "@main/generated/envelope";
import { db, levelKeys } from "@main/level";
import { HydraApi } from "@main/services/hydra-api"; import { HydraApi } from "@main/services/hydra-api";
import { publishFriendStartedPlayingGameNotification } from "@main/services/notifications"; import { publishFriendStartedPlayingGameNotification } from "@main/services/notifications";
import { GameStats } from "@types"; import type { GameStats, UserPreferences, UserProfile } from "@types";
export const friendGameSessionEvent = async (payload: FriendGameSession) => { export const friendGameSessionEvent = async (payload: FriendGameSession) => {
const userPreferences = await db.get<string, UserPreferences | null>(
levelKeys.userPreferences,
{
valueEncoding: "json",
}
);
if (userPreferences?.friendStartGameNotificationsEnabled === false) return;
const [friend, gameStats] = await Promise.all([ const [friend, gameStats] = await Promise.all([
HydraApi.get(`/users/${payload.friendId}`), HydraApi.get<UserProfile>(`/users/${payload.friendId}`),
HydraApi.get<GameStats>( HydraApi.get<GameStats>(
`/games/stats?objectId=${payload.objectId}&shop=steam` `/games/stats?objectId=${payload.objectId}&shop=steam`
), ),
]); ]).catch(() => [null, null]);
if (friend && gameStats) { if (friend && gameStats) {
publishFriendStartedPlayingGameNotification(friend, gameStats); publishFriendStartedPlayingGameNotification(friend, gameStats);

View File

@@ -31,7 +31,7 @@ export function AchievementNotificationItem({
[`${baseClassName}--platinum`]: achievement.isPlatinum, [`${baseClassName}--platinum`]: achievement.isPlatinum,
})} })}
> >
{achievement.points && ( {achievement.points !== undefined && (
<div className="achievement-notification__chip"> <div className="achievement-notification__chip">
<HydraIcon className="achievement-notification__chip__icon" /> <HydraIcon className="achievement-notification__chip__icon" />
<span className="achievement-notification__chip__label"> <span className="achievement-notification__chip__label">

View File

@@ -139,10 +139,7 @@ declare global {
verifyExecutablePathInUse: (executablePath: string) => Promise<Game>; verifyExecutablePathInUse: (executablePath: string) => Promise<Game>;
getLibrary: () => Promise<LibraryGame[]>; getLibrary: () => Promise<LibraryGame[]>;
openGameInstaller: (shop: GameShop, objectId: string) => Promise<boolean>; openGameInstaller: (shop: GameShop, objectId: string) => Promise<boolean>;
openGameInstallerPath: ( openGameInstallerPath: (shop: GameShop, objectId: string) => Promise<void>;
shop: GameShop,
objectId: string
) => Promise<boolean>;
openGameExecutablePath: (shop: GameShop, objectId: string) => Promise<void>; openGameExecutablePath: (shop: GameShop, objectId: string) => Promise<void>;
openGame: ( openGame: (
shop: GameShop, shop: GameShop,

View File

@@ -38,6 +38,7 @@ export function SettingsGeneral() {
downloadNotificationsEnabled: false, downloadNotificationsEnabled: false,
repackUpdatesNotificationsEnabled: false, repackUpdatesNotificationsEnabled: false,
friendRequestNotificationsEnabled: false, friendRequestNotificationsEnabled: false,
friendStartGameNotificationsEnabled: true,
achievementNotificationsEnabled: true, achievementNotificationsEnabled: true,
achievementCustomNotificationsEnabled: true, achievementCustomNotificationsEnabled: true,
achievementCustomNotificationPosition: achievementCustomNotificationPosition:
@@ -111,6 +112,8 @@ export function SettingsGeneral() {
userPreferences.achievementCustomNotificationPosition ?? "top-left", userPreferences.achievementCustomNotificationPosition ?? "top-left",
friendRequestNotificationsEnabled: friendRequestNotificationsEnabled:
userPreferences.friendRequestNotificationsEnabled ?? false, userPreferences.friendRequestNotificationsEnabled ?? false,
friendStartGameNotificationsEnabled:
userPreferences.friendStartGameNotificationsEnabled ?? true,
language: language ?? "en", language: language ?? "en",
})); }));
} }
@@ -248,6 +251,17 @@ export function SettingsGeneral() {
} }
/> />
<CheckboxField
label={t("enable_friend_start_game_notifications")}
checked={form.friendStartGameNotificationsEnabled}
onChange={() =>
handleChange({
friendStartGameNotificationsEnabled:
!form.friendStartGameNotificationsEnabled,
})
}
/>
<CheckboxField <CheckboxField
label={t("enable_achievement_notifications")} label={t("enable_achievement_notifications")}
checked={form.achievementNotificationsEnabled} checked={form.achievementNotificationsEnabled}

View File

@@ -97,6 +97,7 @@ export interface UserPreferences {
achievementCustomNotificationsEnabled?: boolean; achievementCustomNotificationsEnabled?: boolean;
achievementCustomNotificationPosition?: AchievementCustomNotificationPosition; achievementCustomNotificationPosition?: AchievementCustomNotificationPosition;
friendRequestNotificationsEnabled?: boolean; friendRequestNotificationsEnabled?: boolean;
friendStartGameNotificationsEnabled?: boolean;
showDownloadSpeedInMegabytes?: boolean; showDownloadSpeedInMegabytes?: boolean;
extractFilesByDefault?: boolean; extractFilesByDefault?: boolean;
} }