Merge branch 'main' into dev

This commit is contained in:
SillyLossy
2023-04-10 15:07:07 +03:00
2 changed files with 16 additions and 5 deletions

View File

@ -20,9 +20,9 @@
<code> <code>
public/sounds/message.mp3 public/sounds/message.mp3
</code> </code>
<small> <p>
Plays at 80% volume. Plays at 80% volume and only if TavernAI window is <b>unfocused</b>.
</small> </p>
</div> </div>
</div> </div>
</body> </body>

View File

@ -56,12 +56,15 @@ const storage_keys = {
sheld_width: "TavernAI_sheld_width" 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() { function playMessageSound() {
if (!power_user.play_message_sound) { if (!power_user.play_message_sound) {
return; return;
} }
if (power_user.play_sound_unfocused) { if (power_user.play_sound_unfocused && browser_has_focus) {
return; return;
} }
@ -237,4 +240,12 @@ $(document).ready(() => {
power_user.play_sound_unfocused = !!$(this).prop('checked'); power_user.play_sound_unfocused = !!$(this).prop('checked');
saveSettingsDebounced(); saveSettingsDebounced();
}); });
$(window).on('focus', function() {
browser_has_focus = true;
});
$(window).on('blur', function() {
browser_has_focus = false;
});
}); });