Expose a config_changed signal to extensions
This commit is contained in:
parent
42790e7623
commit
1b1872e464
@ -165,6 +165,7 @@ def init(args, crash_handler):
|
|||||||
qApp.setQuitOnLastWindowClosed(False)
|
qApp.setQuitOnLastWindowClosed(False)
|
||||||
_init_icon()
|
_init_icon()
|
||||||
|
|
||||||
|
loader.init()
|
||||||
loader.load_components()
|
loader.load_components()
|
||||||
try:
|
try:
|
||||||
_init_modules(args, crash_handler)
|
_init_modules(args, crash_handler)
|
||||||
|
@ -104,12 +104,10 @@ class HostBlocker:
|
|||||||
self._done_count = 0
|
self._done_count = 0
|
||||||
|
|
||||||
self._local_hosts_file = str(data_dir / 'blocked-hosts')
|
self._local_hosts_file = str(data_dir / 'blocked-hosts')
|
||||||
self._update_files()
|
self.update_files()
|
||||||
|
|
||||||
self._config_hosts_file = str(config_dir / 'blocked-hosts')
|
self._config_hosts_file = str(config_dir / 'blocked-hosts')
|
||||||
|
|
||||||
config.instance.changed.connect(self._update_files)
|
|
||||||
|
|
||||||
def is_blocked(self, url, first_party_url=None):
|
def is_blocked(self, url, first_party_url=None):
|
||||||
"""Check if the given URL (as QUrl) is blocked."""
|
"""Check if the given URL (as QUrl) is blocked."""
|
||||||
if first_party_url is not None and not first_party_url.isValid():
|
if first_party_url is not None and not first_party_url.isValid():
|
||||||
@ -296,7 +294,7 @@ class HostBlocker:
|
|||||||
len(self._blocked_hosts), self._done_count))
|
len(self._blocked_hosts), self._done_count))
|
||||||
|
|
||||||
@config.change_filter('content.host_blocking.lists')
|
@config.change_filter('content.host_blocking.lists')
|
||||||
def _update_files(self):
|
def update_files(self):
|
||||||
"""Update files when the config changed."""
|
"""Update files when the config changed."""
|
||||||
if not config.val.content.host_blocking.lists:
|
if not config.val.content.host_blocking.lists:
|
||||||
try:
|
try:
|
||||||
@ -331,4 +329,5 @@ def init(context):
|
|||||||
host_blocker = HostBlocker(data_dir=context.data_dir,
|
host_blocker = HostBlocker(data_dir=context.data_dir,
|
||||||
config_dir=context.config_dir,
|
config_dir=context.config_dir,
|
||||||
args=context.args)
|
args=context.args)
|
||||||
|
context.signals.config_changed.connect(host_blocker.update_files)
|
||||||
host_blocker.read_hosts()
|
host_blocker.read_hosts()
|
||||||
|
@ -28,7 +28,10 @@ import pathlib
|
|||||||
|
|
||||||
import attr
|
import attr
|
||||||
|
|
||||||
|
from PyQt5.QtCore import pyqtSignal, QObject
|
||||||
|
|
||||||
from qutebrowser import components
|
from qutebrowser import components
|
||||||
|
from qutebrowser.config import config
|
||||||
from qutebrowser.utils import log, standarddir, objreg
|
from qutebrowser.utils import log, standarddir, objreg
|
||||||
|
|
||||||
|
|
||||||
@ -40,6 +43,14 @@ class InitContext:
|
|||||||
data_dir = attr.ib() # type: pathlib.Path
|
data_dir = attr.ib() # type: pathlib.Path
|
||||||
config_dir = attr.ib() # type: pathlib.Path
|
config_dir = attr.ib() # type: pathlib.Path
|
||||||
args = attr.ib() # type: argparse.Namespace
|
args = attr.ib() # type: argparse.Namespace
|
||||||
|
signals = attr.ib() # type: ExtensionSignals
|
||||||
|
|
||||||
|
|
||||||
|
class ExtensionSignals(QObject):
|
||||||
|
|
||||||
|
"""Signals exposed to an extension."""
|
||||||
|
|
||||||
|
config_changed = pyqtSignal(str)
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
@ -61,6 +72,12 @@ class ExtensionInfo:
|
|||||||
name = attr.ib() # type: str
|
name = attr.ib() # type: str
|
||||||
|
|
||||||
|
|
||||||
|
# Global extension signals, shared between all extensions.
|
||||||
|
# At some point we might want to make this per-extension, but then we'll need
|
||||||
|
# to find out what to set as its Qt parent so it's kept alive.
|
||||||
|
_extension_signals = ExtensionSignals()
|
||||||
|
|
||||||
|
|
||||||
def add_module_info(module: types.ModuleType) -> ModuleInfo:
|
def add_module_info(module: types.ModuleType) -> ModuleInfo:
|
||||||
"""Add ModuleInfo to a module (if not added yet)."""
|
"""Add ModuleInfo to a module (if not added yet)."""
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
@ -121,7 +138,8 @@ def _get_init_context() -> InitContext:
|
|||||||
"""Get an InitContext object."""
|
"""Get an InitContext object."""
|
||||||
return InitContext(data_dir=pathlib.Path(standarddir.data()),
|
return InitContext(data_dir=pathlib.Path(standarddir.data()),
|
||||||
config_dir=pathlib.Path(standarddir.config()),
|
config_dir=pathlib.Path(standarddir.config()),
|
||||||
args=objreg.get('args'))
|
args=objreg.get('args'),
|
||||||
|
signals=_extension_signals)
|
||||||
|
|
||||||
|
|
||||||
def _load_component(info: ExtensionInfo) -> types.ModuleType:
|
def _load_component(info: ExtensionInfo) -> types.ModuleType:
|
||||||
@ -136,3 +154,7 @@ def _load_component(info: ExtensionInfo) -> types.ModuleType:
|
|||||||
mod_info.init_hook(_get_init_context())
|
mod_info.init_hook(_get_init_context())
|
||||||
|
|
||||||
return mod
|
return mod
|
||||||
|
|
||||||
|
|
||||||
|
def init() -> None:
|
||||||
|
config.instance.changed.connect(_extension_signals.config_changed)
|
||||||
|
Loading…
Reference in New Issue
Block a user