summaryrefslogtreecommitdiff
path: root/qutebrowser/api
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2018-12-10 12:30:47 +0100
committerFlorian Bruhin <me@the-compiler.org>2018-12-10 12:37:58 +0100
commit5b354164c5c4fbf6af1d58c185c7cd0510aedcbc (patch)
tree0c511e40e00c013e71e70f518a5e919ec0d5ae46 /qutebrowser/api
parentec5a93a80dea06fed31f8779c837800658f8bb59 (diff)
downloadqutebrowser-5b354164c5c4fbf6af1d58c185c7cd0510aedcbc.tar.gz
qutebrowser-5b354164c5c4fbf6af1d58c185c7cd0510aedcbc.zip
Make it possible for extensions to define init hooks
Diffstat (limited to 'qutebrowser/api')
-rw-r--r--qutebrowser/api/apitypes.py1
-rw-r--r--qutebrowser/api/hook.py35
2 files changed, 36 insertions, 0 deletions
diff --git a/qutebrowser/api/apitypes.py b/qutebrowser/api/apitypes.py
index 9fec0a6cb..8fbc1a9a7 100644
--- a/qutebrowser/api/apitypes.py
+++ b/qutebrowser/api/apitypes.py
@@ -24,3 +24,4 @@ from qutebrowser.browser.browsertab import WebTabError, AbstractTab as Tab
from qutebrowser.browser.webelem import (Error as WebElemError,
AbstractWebElement as WebElement)
from qutebrowser.utils.usertypes import ClickTarget, JsWorld
+from qutebrowser.extensions.loader import InitContext
diff --git a/qutebrowser/api/hook.py b/qutebrowser/api/hook.py
new file mode 100644
index 000000000..b468e91f5
--- /dev/null
+++ b/qutebrowser/api/hook.py
@@ -0,0 +1,35 @@
+# Copyright 2018 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
+#
+# This file is part of qutebrowser.
+#
+# qutebrowser is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# qutebrowser is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
+
+"""Hooks for extensions."""
+
+import importlib
+import types
+import typing
+
+
+from qutebrowser.extensions import loader
+
+
+class init: # noqa: N801,N806 pylint: disable=invalid-name
+
+ """Decorator to mark a function to run when initializing."""
+
+ def __call__(self, func: typing.Callable) -> typing.Callable:
+ module = importlib.import_module(func.__module__)
+ info = loader.add_module_info(module)
+ info.init_hook = func