feat: add achievement notifications setting

This commit is contained in:
Zamitto 2024-10-13 22:37:36 -03:00
parent c24f6be1b7
commit 1d29bc3620
8 changed files with 60 additions and 10 deletions

View file

@ -235,7 +235,8 @@
"source_already_exists": "This source has been already added",
"must_be_valid_url": "The source must be a valid URL",
"blocked_users": "Blocked users",
"user_unblocked": "User has been unblocked"
"user_unblocked": "User has been unblocked",
"enable_achievement_notifications": "When an achievement in unlocked"
},
"notifications": {
"download_complete": "Download complete",

View file

@ -234,7 +234,8 @@
"source_already_exists": "Essa fonte já foi adicionada",
"must_be_valid_url": "A fonte deve ser uma URL válida",
"blocked_users": "Usuários bloqueados",
"user_unblocked": "Usuário desbloqueado"
"user_unblocked": "Usuário desbloqueado",
"enable_achievement_notifications": "Quando uma conquista é desbloqueada"
},
"notifications": {
"download_complete": "Download concluído",

View file

@ -26,6 +26,9 @@ export class UserPreferences {
@Column("boolean", { default: false })
repackUpdatesNotificationsEnabled: boolean;
@Column("boolean", { default: true })
achievementNotificationsEnabled: boolean;
@Column("boolean", { default: false })
preferQuitInsteadOfHiding: boolean;

View file

@ -7,6 +7,7 @@ import { EnsureRepackUris } from "./migrations/20240915035339_ensure_repack_uris
import { app } from "electron";
import { FixMissingColumns } from "./migrations/20240918001920_FixMissingColumns";
import { CreateGameAchievement } from "./migrations/20240919030940_create_game_achievement";
import { AddAchievementNotificationPreference } from "./migrations/20241013012900_add_achievement_notification_preference";
export type HydraMigration = Knex.Migration & { name: string };
@ -19,6 +20,7 @@ class MigrationSource implements Knex.MigrationSource<HydraMigration> {
EnsureRepackUris,
FixMissingColumns,
CreateGameAchievement,
AddAchievementNotificationPreference,
]);
}
getMigrationName(migration: HydraMigration): string {

View file

@ -0,0 +1,17 @@
import type { HydraMigration } from "@main/knex-client";
import type { Knex } from "knex";
export const AddAchievementNotificationPreference: HydraMigration = {
name: "AddAchievementNotificationPreference",
up: (knex: Knex) => {
return knex.schema.alterTable("user_preferences", (table) => {
return table.boolean("achievementNotificationsEnabled").defaultTo(true);
});
},
down: (knex: Knex) => {
return knex.schema.alterTable("user_preferences", (table) => {
return table.dropColumn("achievementNotificationsEnabled");
});
},
};

View file

@ -1,4 +1,8 @@
import { gameAchievementRepository, gameRepository } from "@main/repository";
import {
gameAchievementRepository,
gameRepository,
userPreferencesRepository,
} from "@main/repository";
import type { GameShop, UnlockedAchievement } from "@types";
import { WindowManager } from "../window-manager";
import { HydraApi } from "../hydra-api";
@ -38,12 +42,15 @@ export const mergeAchievements = async (
if (!game) return;
const localGameAchievement = await gameAchievementRepository.findOne({
const [localGameAchievement, userPreferences] = await Promise.all([
gameAchievementRepository.findOne({
where: {
objectId,
shop,
},
});
}),
userPreferencesRepository.findOne({ where: { id: 1 } }),
]);
const unlockedAchievements = JSON.parse(
localGameAchievement?.unlockedAchievements || "[]"
@ -64,7 +71,11 @@ export const mergeAchievements = async (
};
});
if (newAchievements.length && publishNotification) {
if (
newAchievements.length &&
publishNotification &&
userPreferences?.achievementNotificationsEnabled
) {
const achievementsInfo = newAchievements
.sort((a, b) => {
return a.unlockTime - b.unlockTime;

View file

@ -30,6 +30,7 @@ export function SettingsGeneral() {
downloadsPath: "",
downloadNotificationsEnabled: false,
repackUpdatesNotificationsEnabled: false,
achievementNotificationsEnabled: false,
language: "",
});
@ -103,6 +104,8 @@ export function SettingsGeneral() {
userPreferences.downloadNotificationsEnabled,
repackUpdatesNotificationsEnabled:
userPreferences.repackUpdatesNotificationsEnabled,
achievementNotificationsEnabled:
userPreferences.achievementNotificationsEnabled,
language: language ?? "en",
}));
}
@ -155,6 +158,17 @@ export function SettingsGeneral() {
})
}
/>
<CheckboxField
label={t("enable_achievement_notifications")}
checked={form.achievementNotificationsEnabled}
onChange={() =>
handleChange({
achievementNotificationsEnabled:
!form.achievementNotificationsEnabled,
})
}
/>
</>
);
}

View file

@ -154,6 +154,7 @@ export interface UserPreferences {
language: string;
downloadNotificationsEnabled: boolean;
repackUpdatesNotificationsEnabled: boolean;
achievementNotificationsEnabled: boolean;
realDebridApiToken: string | null;
preferQuitInsteadOfHiding: boolean;
runAtStartup: boolean;