mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
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:
@@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user