refactor(notification): reorder sound playback checks for better flow

Move the audio service mute check earlier in the notification sound
playback logic to prevent unnecessary processing when the system
is muted. Also reposition the rate limiting check to occur after
the initial availability and setting checks.
This commit is contained in:
Ahmet Çetinkaya
2025-12-09 10:44:47 +03:00
parent 73c0a9b550
commit 2ca71c285e
+10 -18
View File
@@ -209,26 +209,16 @@ Singleton {
playNotificationSound(data.urgency, notification.appName);
}
// Function to play notification sound using existing SoundService
function playNotificationSound(urgency, appName) {
// Rate limiting - prevent sound spam
const now = Date.now();
if (now - lastSoundTime < minSoundInterval) {
return;
}
lastSoundTime = now;
// Check if QtMultimedia is available
if (!SoundService.multimediaAvailable) {
return;
}
// Check if notification sounds are enabled
if (!Settings.data.notifications?.sounds?.enabled) {
return;
}
// Check if this app should be excluded
if (AudioService.muted) {
return;
}
if (appName) {
const excludedApps = Settings.data.notifications.sounds.excludedApps || "";
if (excludedApps.trim() !== "") {
@@ -242,11 +232,6 @@ Singleton {
}
}
// Check if system is muted
if (AudioService.muted) {
return;
}
// Get the sound file for this urgency level
const soundFile = getNotificationSoundFile(urgency);
if (!soundFile || soundFile.trim() === "") {
@@ -255,6 +240,13 @@ Singleton {
return;
}
// Rate limiting - prevent sound spam
const now = Date.now();
if (now - lastSoundTime < minSoundInterval) {
return;
}
lastSoundTime = now;
// Play sound using existing SoundService
const volume = Settings.data.notifications?.sounds?.volume ?? 0.5;
SoundService.playSound(soundFile, {