完成自定义桥接功能
parent
1ba77b4cce
commit
fe56af2292
|
@ -7,4 +7,5 @@ from ._version import *
|
||||||
|
|
||||||
from ._webengine import WebEngine
|
from ._webengine import WebEngine
|
||||||
from ._settings import create_setting
|
from ._settings import create_setting
|
||||||
from ._hotreload import create_hmr_server
|
from ._hotreload import create_hmr_server
|
||||||
|
from ._custom_bridge import create_bridge
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
def create_bridge():
|
||||||
|
def wrapper(app, extra = None):
|
||||||
|
app.custom_bridge = extra
|
||||||
|
|
||||||
|
return wrapper
|
|
@ -73,6 +73,7 @@ class WebEngine(WebKit2.WebView):
|
||||||
|
|
||||||
root = None
|
root = None
|
||||||
window = None
|
window = None
|
||||||
|
custom_bridge = None
|
||||||
|
|
||||||
def __init__(self, window):
|
def __init__(self, window):
|
||||||
|
|
||||||
|
@ -200,6 +201,12 @@ class WebEngine(WebKit2.WebView):
|
||||||
case 'md5':
|
case 'md5':
|
||||||
output = hashlib.md5(str(params.get('value'))).hexdigest()
|
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:
|
if callback:
|
||||||
self.call_js(callback, output, _error)
|
self.call_js(callback, output, _error)
|
||||||
|
|
Loading…
Reference in New Issue