Skip to content

Commit

Permalink
Merge pull request SillyTavern#47 from paniphons/main
Browse files Browse the repository at this point in the history
Make sound only play if browser is not focused
  • Loading branch information
Cohee1207 authored Apr 10, 2023
2 parents 66f7d55 + 93e1d4b commit b78c74a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions public/scripts/power-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ 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) {
if (!power_user.play_message_sound || browser_has_focus) {
return;
}

Expand Down Expand Up @@ -226,4 +229,11 @@ $(document).ready(() => {
power_user.play_message_sound = !!$(this).prop('checked');
saveSettingsDebounced();
});
});

$(window).on('focus', function() {
browser_has_focus = true;
});
$(window).on('blur', function() {
browser_has_focus = false;
});
});

0 comments on commit b78c74a

Please sign in to comment.