parent
a146ce865b
commit
93a36c8572
@ -31,6 +31,7 @@ from qutebrowser.api import (cmdutils, hook, config, message, downloads,
|
|||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('misc')
|
logger = logging.getLogger('misc')
|
||||||
|
_host_blocker = None
|
||||||
|
|
||||||
|
|
||||||
def _guess_zip_filename(zf):
|
def _guess_zip_filename(zf):
|
||||||
@ -170,13 +171,8 @@ class HostBlocker:
|
|||||||
config.val.content.host_blocking.enabled):
|
config.val.content.host_blocking.enabled):
|
||||||
message.info("Run :adblock-update to get adblock lists.")
|
message.info("Run :adblock-update to get adblock lists.")
|
||||||
|
|
||||||
@cmdutils.register(instance='host-blocker')
|
|
||||||
def adblock_update(self):
|
def adblock_update(self):
|
||||||
"""Update the adblock block lists.
|
"""Update the adblock block lists."""
|
||||||
|
|
||||||
This updates `~/.local/share/qutebrowser/blocked-hosts` with downloaded
|
|
||||||
host lists and re-reads `~/.config/qutebrowser/blocked-hosts`.
|
|
||||||
"""
|
|
||||||
self._read_hosts_file(self._config_hosts_file,
|
self._read_hosts_file(self._config_hosts_file,
|
||||||
self._config_blocked_hosts)
|
self._config_blocked_hosts)
|
||||||
self._blocked_hosts = set()
|
self._blocked_hosts = set()
|
||||||
@ -329,12 +325,25 @@ class HostBlocker:
|
|||||||
logger.exception("Failed to write host block list!")
|
logger.exception("Failed to write host block list!")
|
||||||
|
|
||||||
|
|
||||||
|
@cmdutils.register()
|
||||||
|
def adblock_update():
|
||||||
|
"""Update the adblock block lists.
|
||||||
|
|
||||||
|
This updates `~/.local/share/qutebrowser/blocked-hosts` with downloaded
|
||||||
|
host lists and re-reads `~/.config/qutebrowser/blocked-hosts`.
|
||||||
|
"""
|
||||||
|
# FIXME: As soon as we can register instances again, we should move this
|
||||||
|
# back to the class.
|
||||||
|
_host_blocker.adblock_update()
|
||||||
|
|
||||||
|
|
||||||
@hook.init()
|
@hook.init()
|
||||||
def init(context):
|
def init(context):
|
||||||
host_blocker = HostBlocker(data_dir=context.data_dir,
|
global _host_blocker
|
||||||
|
_host_blocker = HostBlocker(data_dir=context.data_dir,
|
||||||
config_dir=context.config_dir,
|
config_dir=context.config_dir,
|
||||||
args=context.args)
|
args=context.args)
|
||||||
host_blocker.read_hosts()
|
_host_blocker.read_hosts()
|
||||||
|
|
||||||
context.signals.config_changed.connect(host_blocker.update_files)
|
context.signals.config_changed.connect(_host_blocker.update_files)
|
||||||
requests.register_filter(host_blocker.filter_request)
|
requests.register_filter(_host_blocker.filter_request)
|
||||||
|
Loading…
Reference in New Issue
Block a user