Don't touch mute status after the user changed it
This commit is contained in:
parent
6be4ee2ff3
commit
18ed790c88
@ -673,16 +673,22 @@ class AbstractAudio(QObject):
|
|||||||
self._widget = None
|
self._widget = None
|
||||||
self._tab = tab
|
self._tab = tab
|
||||||
|
|
||||||
def set_muted(self, muted: bool):
|
def set_muted(self, muted: bool, override: bool = False):
|
||||||
"""Set this tab as muted or not."""
|
"""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
|
raise NotImplementedError
|
||||||
|
|
||||||
def is_muted(self):
|
def is_muted(self):
|
||||||
"""Whether this tab is muted."""
|
"""Whether this tab is muted."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def toggle_muted(self):
|
def toggle_muted(self, *, override: bool = False):
|
||||||
self.set_muted(not self.is_muted())
|
self.set_muted(not self.is_muted(), override=override)
|
||||||
|
|
||||||
def is_recently_audible(self):
|
def is_recently_audible(self):
|
||||||
"""Whether this tab has had audio playing recently."""
|
"""Whether this tab has had audio playing recently."""
|
||||||
|
@ -2237,6 +2237,6 @@ class CommandDispatcher:
|
|||||||
if tab is None:
|
if tab is None:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
tab.audio.toggle_muted()
|
tab.audio.toggle_muted(override=True)
|
||||||
except browsertab.WebTabError as e:
|
except browsertab.WebTabError as e:
|
||||||
raise cmdexc.CommandError(e)
|
raise cmdexc.CommandError(e)
|
||||||
|
@ -637,7 +637,16 @@ class WebEngineElements(browsertab.AbstractElements):
|
|||||||
|
|
||||||
class WebEngineAudio(browsertab.AbstractAudio):
|
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):
|
def _connect_signals(self):
|
||||||
page = self._widget.page()
|
page = self._widget.page()
|
||||||
@ -645,7 +654,8 @@ class WebEngineAudio(browsertab.AbstractAudio):
|
|||||||
page.recentlyAudibleChanged.connect(self.recently_audible_changed)
|
page.recentlyAudibleChanged.connect(self.recently_audible_changed)
|
||||||
self._tab.url_changed.connect(self._on_url_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 = self._widget.page()
|
||||||
page.setAudioMuted(muted)
|
page.setAudioMuted(muted)
|
||||||
|
|
||||||
@ -659,6 +669,8 @@ class WebEngineAudio(browsertab.AbstractAudio):
|
|||||||
|
|
||||||
@pyqtSlot(QUrl)
|
@pyqtSlot(QUrl)
|
||||||
def _on_url_changed(self, url):
|
def _on_url_changed(self, url):
|
||||||
|
if self._overridden:
|
||||||
|
return
|
||||||
mute = config.instance.get('content.mute', url=url)
|
mute = config.instance.get('content.mute', url=url)
|
||||||
self.set_muted(mute)
|
self.set_muted(mute)
|
||||||
|
|
||||||
|
@ -637,7 +637,7 @@ class WebKitAudio(browsertab.AbstractAudio):
|
|||||||
|
|
||||||
"""Dummy handling of audio status for QtWebKit."""
|
"""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!')
|
raise browsertab.WebTabError('Muting is not supported on QtWebKit!')
|
||||||
|
|
||||||
def is_muted(self):
|
def is_muted(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user