From eb431c28a9e7df0cc8c2a701b9d0f053739dcbb4 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 2 Jan 2018 17:09:02 +0100 Subject: [refactor] factor out common functions used from both entrypoints for linux and mac apps. --- src/leap/bitmask/gui/app2.py | 44 ++++++-------------------------------------- 1 file changed, 6 insertions(+), 38 deletions(-) (limited to 'src/leap/bitmask/gui/app2.py') diff --git a/src/leap/bitmask/gui/app2.py b/src/leap/bitmask/gui/app2.py index 8690f88f..649d5deb 100644 --- a/src/leap/bitmask/gui/app2.py +++ b/src/leap/bitmask/gui/app2.py @@ -43,6 +43,8 @@ from leap.bitmask.core.launcher import run_bitmaskd, pid from leap.common.config import get_path_prefix from leap.bitmask.gui.systray import WithTrayIcon +from leap.bitmask.gui.housekeeping import cleanup, terminate, reset_authtoken +from leap.bitmask.gui.housekeeping import get_authenticated_url DEBUG = os.environ.get("DEBUG", False) @@ -94,24 +96,8 @@ class BrowserWindow(object): def __init__(self, *args, **kw): url = kw.pop('url', None) - first = False 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 + url = get_authenticated_url() self.url = url self.closing = False @@ -128,22 +114,10 @@ class BrowserWindow(object): return self.closing = True bitmaskd.join() - if os.path.isfile(pid): - with open(pid) as f: - pidno = int(f.read()) - print('[bitmask] terminating bitmaskd') - os.kill(pidno, signal.SIGTERM) - self.cleanup() + terminate(pid) + cleanup() print('[bitmask] shutting down gui') - def cleanup(self): - print('[bitmask] cleaning up files') - base = os.path.join(get_path_prefix(), 'leap') - token = os.path.join(base, 'authtoken') - pid = os.path.join(base, 'bitmaskd.pid') - for _f in [token, pid]: - if os.path.isfile(_f): - os.unlink(_f) def launch_gui(): @@ -184,7 +158,6 @@ def launch_gui(): def start_app(): from leap.bitmask.util import STANDALONE - mypid = os.getpid() # Kill a previously-running process @@ -203,12 +176,7 @@ def start_app(): from leap.bitmask.cli import bitmask_cli return bitmask_cli.main() - prev_auth = os.path.join(get_path_prefix(), 'leap', 'authtoken') - try: - os.remove(prev_auth) - except OSError: - pass - + reset_authtoken() launch_gui() -- cgit v1.2.3