summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2017-04-20 20:40:26 +0200
committerKali Kaneko (leap communications) <kali@leap.se>2017-04-20 23:21:05 +0200
commite07af835bf3b773e07d260b2c38bb8b464814cc3 (patch)
treed654d9007848b285e4d43d3ebdfb11d8ecc26241
parent58b57adad38f3a05f7df87e36114d630d99d447f (diff)
[bug] wait a bit in case the authtoken has not being written yet
-rw-r--r--src/leap/bitmask/gui/app.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/leap/bitmask/gui/app.py b/src/leap/bitmask/gui/app.py
index fc61e81..42e1280 100644
--- a/src/leap/bitmask/gui/app.py
+++ b/src/leap/bitmask/gui/app.py
@@ -25,6 +25,7 @@ import os
import platform
import signal
import sys
+import time
import webbrowser
from functools import partial
@@ -73,6 +74,8 @@ class BrowserWindow(QWebView):
bitmaskApp.openSystemBrowser(url) -> opens URL in system browser
bitmaskBrowser.openPixelated() -> opens Pixelated app in a new window.
+ This BrowserWindow assumes that the backend is already running, since it is
+ going to look for the authtoken in the configuration folder.
"""
def __init__(self, *args, **kw):
url = kw.pop('url', None)
@@ -80,6 +83,17 @@ class BrowserWindow(QWebView):
if not url:
url = "http://localhost:7070"
path = os.path.join(get_path_prefix(), 'leap', 'authtoken')
+ waiting = 20
+ while not os.path.isfile(path):
+ if waiting == 0:
+ # If we arrive here, something really messed up happened,
+ # because touching the token file is one of the first
+ # things the backend does, and this BrowserWindow
+ # should be called *right after* launching the backend.
+ raise NoAuthToken(
+ 'No authentication token found!')
+ time.sleep(0.1)
+ waiting -= 1
token = open(path).read().strip()
url += '#' + token
first = True
@@ -191,7 +205,11 @@ def launch_gui():
bitmaskd.start()
qApp = QApplication([])
- browser = BrowserWindow(None)
+ try:
+ browser = BrowserWindow(None)
+ except NoAuthToken as e:
+ print('ERROR: ' + e.message)
+ sys.exit(1)
qApp.setQuitOnLastWindowClosed(True)
qApp.lastWindowClosed.connect(browser.shutdown)
@@ -238,5 +256,9 @@ def start_app():
launch_gui()
+class NoAuthToken(Exception):
+ pass
+
+
if __name__ == "__main__":
start_app()