Don't touch mute status after the user changed it

This commit is contained in:
Florian Bruhin 2018-09-28 16:37:58 +02:00
parent 6be4ee2ff3
commit 18ed790c88
4 changed files with 26 additions and 8 deletions

View File

@ -673,16 +673,22 @@ class AbstractAudio(QObject):
self._widget = None
self._tab = tab
def set_muted(self, muted: bool):
"""Set this tab as muted or not."""
def set_muted(self, muted: bool, override: bool = False):
"""Set this tab as muted or not.
Arguments:
override: If set to True, muting/unmuting was done manually and
overrides future automatic mute/unmute changes based on
the URL.
"""
raise NotImplementedError
def is_muted(self):
"""Whether this tab is muted."""
raise NotImplementedError
def toggle_muted(self):
self.set_muted(not self.is_muted())
def toggle_muted(self, *, override: bool = False):
self.set_muted(not self.is_muted(), override=override)
def is_recently_audible(self):
"""Whether this tab has had audio playing recently."""

View File

@ -2237,6 +2237,6 @@ class CommandDispatcher:
if tab is None:
return
try:
tab.audio.toggle_muted()
tab.audio.toggle_muted(override=True)
except browsertab.WebTabError as e:
raise cmdexc.CommandError(e)

View File

@ -637,7 +637,16 @@ class WebEngineElements(browsertab.AbstractElements):
class WebEngineAudio(browsertab.AbstractAudio):
"""QtWebEngine implemementations related to audio/muting."""
"""QtWebEngine implemementations related to audio/muting.
Attributes:
_overridden: Whether the user toggled muting manually.
If that's the case, we leave it alone.
"""
def __init__(self, tab, parent=None):
super().__init__(tab, parent)
self._overridden = False
def _connect_signals(self):
page = self._widget.page()
@ -645,7 +654,8 @@ class WebEngineAudio(browsertab.AbstractAudio):
page.recentlyAudibleChanged.connect(self.recently_audible_changed)
self._tab.url_changed.connect(self._on_url_changed)
def set_muted(self, muted: bool):
def set_muted(self, muted: bool, override: bool = False):
self._overridden = override
page = self._widget.page()
page.setAudioMuted(muted)
@ -659,6 +669,8 @@ class WebEngineAudio(browsertab.AbstractAudio):
@pyqtSlot(QUrl)
def _on_url_changed(self, url):
if self._overridden:
return
mute = config.instance.get('content.mute', url=url)
self.set_muted(mute)

View File

@ -637,7 +637,7 @@ class WebKitAudio(browsertab.AbstractAudio):
"""Dummy handling of audio status for QtWebKit."""
def set_muted(self, muted: bool):
def set_muted(self, muted: bool, override: bool = False):
raise browsertab.WebTabError('Muting is not supported on QtWebKit!')
def is_muted(self):