diff --git a/public/notes/message_sound.html b/public/notes/message_sound.html index 2bb1a89fc..3386d1d43 100644 --- a/public/notes/message_sound.html +++ b/public/notes/message_sound.html @@ -20,9 +20,9 @@ public/sounds/message.mp3 - - Plays at 80% volume. - +

+ Plays at 80% volume and only if TavernAI window is unfocused. +

diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index 7c0d24900..00086021a 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -56,12 +56,15 @@ const storage_keys = { sheld_width: "TavernAI_sheld_width" }; +//Updated at the bottom of this script document based on 'focus' and 'blur' events +let browser_has_focus = true; + function playMessageSound() { if (!power_user.play_message_sound) { return; } - if (power_user.play_sound_unfocused) { + if (power_user.play_sound_unfocused && browser_has_focus) { return; } @@ -237,4 +240,12 @@ $(document).ready(() => { power_user.play_sound_unfocused = !!$(this).prop('checked'); saveSettingsDebounced(); }); -}); \ No newline at end of file + + $(window).on('focus', function() { + browser_has_focus = true; + }); + + $(window).on('blur', function() { + browser_has_focus = false; + }); +});