-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
49 lines (36 loc) · 1.17 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from cefpython3 import cefpython as cef
import threading
import sys
import os
from core.server import app
import settings
class LoadHandler(object):
def OnLoadingStateChange(self, browser, is_loading, **_):
if not is_loading:
pass
class Backend(object):
def __init__(self, port):
self.port = port
self.thread = threading.Thread(target=app,
args=(port, settings.UI_PATH, settings.UI_PATH)
)
def run(self):
self.thread.start()
def message(self, value, js_callback=None):
if js_callback:
js_callback.Call(value)
return value
def main():
sys.excepthook = cef.ExceptHook
cef.Initialize(settings.cef_settings, switches=settings.cef_switches)
backend = Backend(8123)
bindings = cef.JavascriptBindings(bindToFrames=False, bindToPopups=False)
bindings.SetFunction("message", backend.message)
browser = cef.CreateBrowserSync(url="http://localhost:8123", window_title="BikeLab")
browser.SetJavascriptBindings(bindings)
browser.SetClientHandler(LoadHandler())
backend.run()
cef.MessageLoop()
cef.Shutdown()
if __name__ == '__main__':
main()