summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/gui/app2.py
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2017-12-08 16:08:08 +0100
committerKali Kaneko <kali@leap.se>2017-12-08 18:11:47 +0100
commite9ad0c8234be705b42d6dd7eb3865919392835a2 (patch)
tree8162999fefa443248aa5c08ea72231b1e5aff4b5 /src/leap/bitmask/gui/app2.py
parent3fae5a6fdaad3e06770797e6cf8c21d1804ddc22 (diff)
[feat] osx systray with pyqt5
Diffstat (limited to 'src/leap/bitmask/gui/app2.py')
-rw-r--r--src/leap/bitmask/gui/app2.py57
1 files changed, 52 insertions, 5 deletions
diff --git a/src/leap/bitmask/gui/app2.py b/src/leap/bitmask/gui/app2.py
index e540f492..0e445026 100644
--- a/src/leap/bitmask/gui/app2.py
+++ b/src/leap/bitmask/gui/app2.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# app.py
-# Copyright (C) 2016 LEAP Encryption Acess Project
+# app2.py
+# Copyright (C) 2016-2017 LEAP Encryption Acess Project
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,9 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
-Main entrypoint for the Bitmask Qt GUI.
-It just launches a webview browser that runs the local web-ui served by
-bitmaskd when the web service is running.
+This is an alternative entrypoint for Bitmask, based on pywebview.
"""
import os
@@ -34,9 +32,13 @@ from multiprocessing import Process
import webview
import psutil
+from PyQt5.QtWidgets import QApplication
+
from leap.bitmask.core.launcher import run_bitmaskd, pid
from leap.common.config import get_path_prefix
+from leap.bitmask.gui.systray import WithTrayIcon
+
DEBUG = os.environ.get("DEBUG", False)
@@ -50,6 +52,40 @@ bitmaskd = None
browser = None
+class Systray(WithTrayIcon):
+
+ def closeFromSystray(self):
+ print "SYSTRAY CLOSE"
+ global browser
+ print "browser is", browser
+ self.user_closed = True
+ if browser:
+ print 'closing browser window'
+ browser.shutdown()
+ self.close()
+ self.close()
+
+ def closeEvent(self, event):
+ print "CLOSE EVENT"
+ global browser
+ print "browser is", browser
+ if self.user_closed:
+ print "bye!"
+ sys.exit()
+ else:
+ event.ignore()
+
+
+
+def launch_systray():
+ global qApp
+ qApp = QApplication([])
+ qApp.setQuitOnLastWindowClosed(True)
+
+ systray = Systray()
+ systray.setupSysTray()
+
+
class BrowserWindow(object):
"""
A browser window using pywebview.
@@ -81,13 +117,17 @@ class BrowserWindow(object):
self.closing = False
webview.create_window('Bitmask', self.url)
+
def loadPage(self, web_page):
self.load(url)
def shutdown(self, *args):
+ print "SHUTDOWN from browser window..."
if self.closing:
return
+
+ # TODO -- close only if closed from systray!!
self.closing = True
global bitmaskd
bitmaskd.join()
@@ -98,6 +138,10 @@ class BrowserWindow(object):
os.kill(pidno, signal.SIGTERM)
print('[bitmask] shutting down gui...')
+ def cleanup(self):
+ # TODO get path!!!!!!! -----------
+ os.remove('/Users/admin/Library/Preferences/leap/bitmasd.pid')
+
def launch_gui():
global bitmaskd
@@ -107,7 +151,9 @@ def launch_gui():
bitmaskd.start()
try:
+ launch_systray()
browser = BrowserWindow(None)
+ sys.exit(qApp.exec_())
except NoAuthToken as e:
print('ERROR: ' + e.message)
sys.exit(1)
@@ -143,6 +189,7 @@ def start_app():
launch_gui()
+
class NoAuthToken(Exception):
pass