mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-10 04:12:15 +03:00
Don't start handlers before main window created
This commit is contained in:
parent
7f643976dc
commit
d8b2cb361b
@ -70,8 +70,8 @@ class AppWindow:
|
|||||||
|
|
||||||
def __init__(self, master):
|
def __init__(self, master):
|
||||||
|
|
||||||
# Start a protocol handler to handle cAPI registration
|
# Start a protocol handler to handle cAPI registration. Requires main window to exist.
|
||||||
protocolhandler.setmaster(master)
|
protocolhandler.start(master)
|
||||||
|
|
||||||
self.holdofftime = config.getint('querytime') + companion.holdoff
|
self.holdofftime = config.getint('querytime') + companion.holdoff
|
||||||
|
|
||||||
|
40
protocol.py
40
protocol.py
@ -15,7 +15,7 @@ class GenericProtocolHandler:
|
|||||||
self.master = None
|
self.master = None
|
||||||
self.lastpayload = None
|
self.lastpayload = None
|
||||||
|
|
||||||
def setmaster(self, master):
|
def start(self, master):
|
||||||
self.master = master
|
self.master = master
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
@ -39,10 +39,10 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False):
|
|||||||
|
|
||||||
POLL = 100 # ms
|
POLL = 100 # ms
|
||||||
|
|
||||||
def __init__(self):
|
def start(self, master):
|
||||||
GenericProtocolHandler.__init__(self)
|
GenericProtocolHandler.start(self, master)
|
||||||
self.eventhandler = EventHandler.alloc().init()
|
|
||||||
self.lasturl = None
|
self.lasturl = None
|
||||||
|
self.eventhandler = EventHandler.alloc().init()
|
||||||
|
|
||||||
def poll(self):
|
def poll(self):
|
||||||
# No way of signalling to Tkinter from within the callback handler block that doesn't cause Python to crash, so poll.
|
# No way of signalling to Tkinter from within the callback handler block that doesn't cause Python to crash, so poll.
|
||||||
@ -139,6 +139,10 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
GenericProtocolHandler.__init__(self)
|
GenericProtocolHandler.__init__(self)
|
||||||
|
self.thread = None
|
||||||
|
|
||||||
|
def start(self, master):
|
||||||
|
GenericProtocolHandler.start(self, master)
|
||||||
self.thread = threading.Thread(target=self.worker, name='DDE worker')
|
self.thread = threading.Thread(target=self.worker, name='DDE worker')
|
||||||
self.thread.daemon = True
|
self.thread.daemon = True
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
@ -204,7 +208,11 @@ else: # Linux / Run from source
|
|||||||
GenericProtocolHandler.__init__(self)
|
GenericProtocolHandler.__init__(self)
|
||||||
self.httpd = HTTPServer(('localhost', 0), HTTPRequestHandler)
|
self.httpd = HTTPServer(('localhost', 0), HTTPRequestHandler)
|
||||||
self.redirect = 'http://localhost:%d/auth' % self.httpd.server_port
|
self.redirect = 'http://localhost:%d/auth' % self.httpd.server_port
|
||||||
self.thread = threading.Thread(target=self.worker, name='DDE worker')
|
self.thread = None
|
||||||
|
|
||||||
|
def start(self, master):
|
||||||
|
GenericProtocolHandler.start(self, master)
|
||||||
|
self.thread = threading.Thread(target=self.worker, name='OAuth worker')
|
||||||
self.thread.daemon = True
|
self.thread.daemon = True
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
@ -212,7 +220,8 @@ else: # Linux / Run from source
|
|||||||
thread = self.thread
|
thread = self.thread
|
||||||
if thread:
|
if thread:
|
||||||
self.thread = None
|
self.thread = None
|
||||||
self.httpd.shutdown()
|
if self.httpd:
|
||||||
|
self.httpd.shutdown()
|
||||||
thread.join() # Wait for it to quit
|
thread.join() # Wait for it to quit
|
||||||
|
|
||||||
def worker(self):
|
def worker(self):
|
||||||
@ -220,18 +229,29 @@ else: # Linux / Run from source
|
|||||||
|
|
||||||
class HTTPRequestHandler(BaseHTTPRequestHandler):
|
class HTTPRequestHandler(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
def do_HEAD(self):
|
def parse(self):
|
||||||
self.do_GET()
|
|
||||||
|
|
||||||
def do_GET(self):
|
|
||||||
url = urllib2.unquote(self.path)
|
url = urllib2.unquote(self.path)
|
||||||
if url.startswith('/auth'):
|
if url.startswith('/auth'):
|
||||||
protocolhandler.event(url)
|
protocolhandler.event(url)
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
self.send_response(404) # Not found
|
self.send_response(404) # Not found
|
||||||
|
return False
|
||||||
|
|
||||||
|
def do_HEAD(self):
|
||||||
|
self.parse()
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
|
||||||
|
def do_GET(self):
|
||||||
|
if self.parse():
|
||||||
|
self.send_header('Content-Type', 'text/html')
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write('<html><head><title>%s</title></head>' % _('Authentication successful').encode('utf-8'))
|
||||||
|
self.wfile.write('<body><p>%s</p></body>' % _('Authentication successful').encode('utf-8'))
|
||||||
|
else:
|
||||||
|
self.end_headers()
|
||||||
|
|
||||||
def log_request(self, code, size=None):
|
def log_request(self, code, size=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user