-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallet.py
53 lines (41 loc) · 1.18 KB
/
wallet.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
50
51
52
53
# -*- coding: utf-8 -*-
import os
import sys
print(sys.stdout.encoding)
sys.path.append(os.getcwd())
import io
import threading
import socket
import bottle
from bottle import request
from bottle_sqlite import SQLitePlugin
from app.config import *
from app.routes import *
bottle.install(SQLitePlugin(dbfile = Config.databasePath))
def randomPort():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("127.0.0.1", 0))
port = s.getsockname()[1]
s.close()
return port
def serverMain(port):
bottle.run(host = "0.0.0.0", port = port)
port = randomPort()
serverThread = threading.Thread(target=serverMain, args=(port,))
serverThread.daemon = True
serverThread.start()
from cefpython3 import cefpython as cef
import platform
import sys
def cefMain(port):
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
cef.Initialize()
url = "http://localhost:%s/" % port
browser = cef.CreateBrowserSync(url = url, window_title = "Wallet")
browser.SetClientHandler(LifespanHandler())
cef.MessageLoop()
cef.Shutdown()
class LifespanHandler(object):
def OnBeforeClose(self, browser):
print("shutdown")
cefMain(port)