fix: removed unused function

This commit is contained in:
Moyasee
2025-11-07 17:50:47 +02:00
parent a6cbaf6dc1
commit 154b6271a1
11 changed files with 95 additions and 52 deletions

View File

@@ -37,4 +37,3 @@ const copyThemeAchievementSound = async (
};
registerEvent("copyThemeAchievementSound", copyThemeAchievementSound);

View File

@@ -9,4 +9,3 @@ const getThemeSoundPathEvent = async (
};
registerEvent("getThemeSoundPath", getThemeSoundPathEvent);

View File

@@ -22,7 +22,7 @@ const importThemeSoundFromStore = async (
for (const format of formats) {
try {
const soundUrl = `${storeUrl}/themes/${themeName.toLowerCase()}/achievement.${format}`;
const response = await axios.get(soundUrl, {
responseType: "arraybuffer",
timeout: 10000,
@@ -54,4 +54,3 @@ const importThemeSoundFromStore = async (
};
registerEvent("importThemeSoundFromStore", importThemeSoundFromStore);

View File

@@ -36,4 +36,3 @@ const removeThemeAchievementSound = async (
};
registerEvent("removeThemeAchievementSound", removeThemeAchievementSound);

View File

@@ -5,7 +5,7 @@ import fs from "node:fs";
import axios from "axios";
import path from "node:path";
import sound from "sound-play";
import { achievementSoundPath, DEFAULT_ACHIEVEMENT_SOUND_VOLUME } from "@main/constants";
import { achievementSoundPath } from "@main/constants";
import icon from "@resources/icon.png?asset";
import { NotificationOptions, toXmlString } from "./xml";
import { logger } from "../logger";
@@ -59,22 +59,6 @@ async function getAchievementSoundPath(): Promise<string> {
return achievementSoundPath;
}
async function getAchievementSoundVolume(): Promise<number> {
try {
const userPreferences = await db.get<string, UserPreferences>(
levelKeys.userPreferences,
{
valueEncoding: "json",
}
);
return userPreferences?.achievementSoundVolume ?? DEFAULT_ACHIEVEMENT_SOUND_VOLUME;
} catch (error) {
logger.error("Failed to get achievement sound volume", error);
return DEFAULT_ACHIEVEMENT_SOUND_VOLUME;
}
}
export const publishDownloadCompleteNotification = async (game: Game) => {
const userPreferences = await db.get<string, UserPreferences>(
levelKeys.userPreferences,

View File

@@ -577,8 +577,17 @@ contextBridge.exposeInMainWorld("electron", {
ipcRenderer.invoke("removeThemeAchievementSound", themeId),
getThemeSoundPath: (themeId: string) =>
ipcRenderer.invoke("getThemeSoundPath", themeId),
importThemeSoundFromStore: (themeId: string, themeName: string, storeUrl: string) =>
ipcRenderer.invoke("importThemeSoundFromStore", themeId, themeName, storeUrl),
importThemeSoundFromStore: (
themeId: string,
themeName: string,
storeUrl: string
) =>
ipcRenderer.invoke(
"importThemeSoundFromStore",
themeId,
themeName,
storeUrl
),
/* Editor */
openEditorWindow: (themeId: string) =>

View File

@@ -24,7 +24,12 @@ import { UserFriendModal } from "./pages/shared-modals/user-friend-modal";
import { useSubscription } from "./hooks/use-subscription";
import { HydraCloudModal } from "./pages/shared-modals/hydra-cloud/hydra-cloud-modal";
import { injectCustomCss, removeCustomCss, getAchievementSoundUrl, getAchievementSoundVolume } from "./helpers";
import {
injectCustomCss,
removeCustomCss,
getAchievementSoundUrl,
getAchievementSoundVolume,
} from "./helpers";
import "./app.scss";
export interface AppProps {

View File

@@ -123,11 +123,12 @@ export const generateUUID = (): string => {
};
export const getAchievementSoundUrl = async (): Promise<string> => {
const defaultSound = (await import("@renderer/assets/audio/achievement.wav")).default;
const defaultSound = (await import("@renderer/assets/audio/achievement.wav"))
.default;
try {
const activeTheme = await window.electron.getActiveCustomTheme();
if (activeTheme?.hasCustomSound) {
const soundPath = await window.electron.getThemeSoundPath(activeTheme.id);
if (soundPath) {
@@ -137,7 +138,7 @@ export const getAchievementSoundUrl = async (): Promise<string> => {
} catch (error) {
console.error("Failed to get theme sound", error);
}
return defaultSound;
};

View File

@@ -4,7 +4,12 @@ import {
AchievementCustomNotificationPosition,
AchievementNotificationInfo,
} from "@types";
import { injectCustomCss, removeCustomCss, getAchievementSoundUrl, getAchievementSoundVolume } from "@renderer/helpers";
import {
injectCustomCss,
removeCustomCss,
getAchievementSoundUrl,
getAchievementSoundVolume,
} from "@renderer/helpers";
import { AchievementNotificationItem } from "@renderer/components/achievements/notification/achievement-notification";
import app from "../../../app.scss?inline";
import styles from "../../../components/achievements/notification/achievement-notification.scss?inline";

View File

@@ -1,4 +1,11 @@
import { useContext, useEffect, useMemo, useState, useCallback, useRef } from "react";
import {
useContext,
useEffect,
useMemo,
useState,
useCallback,
useRef,
} from "react";
import {
TextField,
Button,
@@ -51,7 +58,7 @@ export function SettingsGeneral() {
const [languageOptions, setLanguageOptions] = useState<LanguageOption[]>([]);
const [defaultDownloadsPath, setDefaultDownloadsPath] = useState("");
const volumeUpdateTimeoutRef = useRef<NodeJS.Timeout>();
useEffect(() => {
@@ -116,7 +123,9 @@ export function SettingsGeneral() {
userPreferences.achievementCustomNotificationsEnabled ?? true,
achievementCustomNotificationPosition:
userPreferences.achievementCustomNotificationPosition ?? "top-left",
achievementSoundVolume: Math.round((userPreferences.achievementSoundVolume ?? 0.15) * 100),
achievementSoundVolume: Math.round(
(userPreferences.achievementSoundVolume ?? 0.15) * 100
),
friendRequestNotificationsEnabled:
userPreferences.friendRequestNotificationsEnabled ?? false,
friendStartGameNotificationsEnabled:
@@ -155,17 +164,20 @@ export function SettingsGeneral() {
await updateUserPreferences(values);
};
const handleVolumeChange = useCallback((newVolume: number) => {
setForm((prev) => ({ ...prev, achievementSoundVolume: newVolume }));
if (volumeUpdateTimeoutRef.current) {
clearTimeout(volumeUpdateTimeoutRef.current);
}
volumeUpdateTimeoutRef.current = setTimeout(() => {
updateUserPreferences({ achievementSoundVolume: newVolume / 100 });
}, 300);
}, [updateUserPreferences]);
const handleVolumeChange = useCallback(
(newVolume: number) => {
setForm((prev) => ({ ...prev, achievementSoundVolume: newVolume }));
if (volumeUpdateTimeoutRef.current) {
clearTimeout(volumeUpdateTimeoutRef.current);
}
volumeUpdateTimeoutRef.current = setTimeout(() => {
updateUserPreferences({ achievementSoundVolume: newVolume / 100 });
}, 300);
},
[updateUserPreferences]
);
const handleChangeAchievementCustomNotificationPosition = async (
event: React.ChangeEvent<HTMLSelectElement>
@@ -347,13 +359,19 @@ export function SettingsGeneral() {
handleVolumeChange(0);
return;
}
const volumePercent = Math.min(100, Math.max(0, parseInt(value, 10)));
const volumePercent = Math.min(
100,
Math.max(0, parseInt(value, 10))
);
if (!isNaN(volumePercent)) {
handleVolumeChange(volumePercent);
}
}}
onBlur={(e) => {
if (e.target.value === "" || isNaN(parseInt(e.target.value, 10))) {
if (
e.target.value === "" ||
isNaN(parseInt(e.target.value, 10))
) {
handleVolumeChange(0);
}
}}
@@ -365,11 +383,19 @@ export function SettingsGeneral() {
type="button"
onClick={(e) => {
e.preventDefault();
const newVolume = Math.min(100, form.achievementSoundVolume + 1);
const newVolume = Math.min(
100,
form.achievementSoundVolume + 1
);
handleVolumeChange(newVolume);
}}
>
<svg width="12" height="12" viewBox="0 0 12 12" fill="currentColor">
<svg
width="12"
height="12"
viewBox="0 0 12 12"
fill="currentColor"
>
<path d="M6 4l4 4H2l4-4z" />
</svg>
</button>
@@ -377,11 +403,19 @@ export function SettingsGeneral() {
type="button"
onClick={(e) => {
e.preventDefault();
const newVolume = Math.max(0, form.achievementSoundVolume - 1);
const newVolume = Math.max(
0,
form.achievementSoundVolume - 1
);
handleVolumeChange(newVolume);
}}
>
<svg width="12" height="12" viewBox="0 0 12 12" fill="currentColor">
<svg
width="12"
height="12"
viewBox="0 0 12 12"
fill="currentColor"
>
<path d="M6 8L2 4h8L6 8z" />
</svg>
</button>

View File

@@ -4,10 +4,19 @@ import Editor from "@monaco-editor/react";
import { AchievementCustomNotificationPosition, Theme } from "@types";
import { useSearchParams } from "react-router-dom";
import { Button, SelectField } from "@renderer/components";
import { CheckIcon, UploadIcon, TrashIcon, PlayIcon } from "@primer/octicons-react";
import {
CheckIcon,
UploadIcon,
TrashIcon,
PlayIcon,
} from "@primer/octicons-react";
import { useTranslation } from "react-i18next";
import cn from "classnames";
import { injectCustomCss, getAchievementSoundUrl, getAchievementSoundVolume } from "@renderer/helpers";
import {
injectCustomCss,
getAchievementSoundUrl,
getAchievementSoundVolume,
} 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";