feat: refactor test notiication event

This commit is contained in:
Zamitto
2025-05-17 19:06:01 -03:00
parent 914942d328
commit ee916b998a
9 changed files with 38 additions and 27 deletions

View File

@@ -365,12 +365,12 @@
"show_download_speed_in_megabytes": "Show download speed in megabytes per second",
"extract_files_by_default": "Extract files by default after download",
"achievement_custom_notification_position": "Achievement custom notification position",
"top_left": "Top left",
"top_center": "Top center",
"top_right": "Top right",
"bottom_left": "Bottom left",
"bottom_center": "Bottom center",
"bottom_right": "Bottom right",
"top-left": "Top left",
"top-center": "Top center",
"top-right": "Top right",
"bottom-left": "Bottom left",
"bottom-center": "Bottom center",
"bottom-right": "Bottom right",
"enable_achievement_custom_notifications": "Enable achievement custom notifications",
"alignment": "Alignment",
"variation": "Variation",

View File

@@ -351,12 +351,12 @@
"show_download_speed_in_megabytes": "Exibir taxas de download em megabytes por segundo",
"extract_files_by_default": "Extrair arquivos automaticamente após o download",
"enable_achievement_custom_notifications": "Habilitar notificações customizadas de conquistas",
"top_left": "Superior esquerdo",
"top_center": "Superior central",
"top_right": "Superior direito",
"bottom_left": "Inferior esquerdo",
"bottom_right": "Inferior direito",
"bottom_center": "Inferior central",
"top-left": "Superior esquerdo",
"top-center": "Superior central",
"top-right": "Superior direito",
"bottom-left": "Inferior esquerdo",
"bottom-right": "Inferior direito",
"bottom-center": "Inferior central",
"achievement_custom_notification_position": "Posição das notificações customizadas de conquista",
"alignment": "Alinhamento",
"variation": "Variação",

View File

@@ -88,6 +88,7 @@ import "./cloud-save/delete-game-artifact";
import "./cloud-save/select-game-backup-path";
import "./notifications/publish-new-repacks-notification";
import "./notifications/update-achievement-notification-window";
import "./notifications/show-achievement-test-notification";
import "./themes/add-custom-theme";
import "./themes/delete-custom-theme";
import "./themes/get-all-custom-themes";

View File

@@ -0,0 +1,15 @@
import { registerEvent } from "../register-event";
import { WindowManager } from "@main/services";
const showAchievementTestNotification = async (
_event: Electron.IpcMainInvokeEvent
) => {
setTimeout(() => {
WindowManager.showAchievementTestNotification();
}, 1000);
};
registerEvent(
"showAchievementTestNotification",
showAchievementTestNotification
);

View File

@@ -19,7 +19,7 @@ const updateAchievementCustomNotificationWindow = async (
userPreferences.achievementNotificationsEnabled &&
userPreferences.achievementCustomNotificationsEnabled !== false
) {
WindowManager.createNotificationWindow(true);
WindowManager.createNotificationWindow();
}
};

View File

@@ -330,7 +330,9 @@ export class WindowManager {
};
}
public static async createNotificationWindow(showTestNotification = false) {
public static async createNotificationWindow() {
if (this.notificationWindow) return;
const userPreferences = await db.get<string, UserPreferences>(
levelKeys.userPreferences,
{
@@ -364,17 +366,9 @@ export class WindowManager {
// });
this.notificationWindow.setAlwaysOnTop(true, "screen-saver", 1);
this.loadNotificationWindowURL();
this.notificationWindow.once("ready-to-show", () => {
if (showTestNotification) {
setTimeout(() => {
this.showTestNotification();
}, 1000);
}
});
}
public static async showTestNotification() {
public static async showAchievementTestNotification() {
const userPreferences = await db.get<string, UserPreferences>(
levelKeys.userPreferences,
{
@@ -386,7 +380,7 @@ export class WindowManager {
this.notificationWindow?.webContents.send(
"on-achievement-unlocked",
userPreferences.achievementCustomNotificationPosition ?? "top_left",
userPreferences.achievementCustomNotificationPosition ?? "top-left",
[generateAchievementCustomNotificationTest(t, language)]
);
}

View File

@@ -442,6 +442,8 @@ contextBridge.exposeInMainWorld("electron", {
},
updateAchievementCustomNotificationWindow: () =>
ipcRenderer.invoke("updateAchievementCustomNotificationWindow"),
showAchievementTestNotification: () =>
ipcRenderer.invoke("showAchievementTestNotification"),
/* Themes */
addCustomTheme: (theme: Theme) => ipcRenderer.invoke("addCustomTheme", theme),

View File

@@ -338,6 +338,7 @@ declare global {
) => void
) => () => Electron.IpcRenderer;
updateAchievementCustomNotificationWindow: () => Promise<void>;
showAchievementTestNotification: () => Promise<void>;
/* Themes */
addCustomTheme: (theme: Theme) => Promise<void>;

View File

@@ -288,9 +288,7 @@ export function SettingsGeneral() {
<Button
className="settings-general__test-achievement-notification-button"
onClick={() =>
window.electron.updateAchievementCustomNotificationWindow()
}
onClick={() => window.electron.showAchievementTestNotification()}
>
Test Notification
</Button>