diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py b/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py index e3d2720..3f49140 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py @@ -7,4 +7,5 @@ from ._version import * from ._webengine import WebEngine from ._settings import create_setting -from ._hotreload import create_hmr_server \ No newline at end of file +from ._hotreload import create_hmr_server +from ._custom_bridge import create_bridge \ No newline at end of file diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_custom_bridge.py b/usr/lib/python3/dist-packages/webengine/gtk3/_custom_bridge.py new file mode 100644 index 0000000..cc06077 --- /dev/null +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_custom_bridge.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +def create_bridge(): + def wrapper(app, extra = None): + app.custom_bridge = extra + + return wrapper \ No newline at end of file diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py b/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py index 10ddd66..2d3b488 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py @@ -73,6 +73,7 @@ class WebEngine(WebKit2.WebView): root = None window = None + custom_bridge = None def __init__(self, window): @@ -200,6 +201,12 @@ class WebEngine(WebKit2.WebView): case 'md5': output = hashlib.md5(str(params.get('value'))).hexdigest() + case _: + if self.custom_bridge is None: + pass + else: + _error, output = self.custom_bridge(event, params) + # 有回调则返回结果 if callback: self.call_js(callback, output, _error)