From 96f1cd6d95de3226ce9ef24c8927993d5d2a7f22 Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Wed, 19 Apr 2017 19:23:13 +0200 Subject: [feature] expose gui shutdown to js - Resolves: #8837 --- src/leap/bitmask/gui/app.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/leap/bitmask/gui') diff --git a/src/leap/bitmask/gui/app.py b/src/leap/bitmask/gui/app.py index 52598cbf..0f98fa75 100644 --- a/src/leap/bitmask/gui/app.py +++ b/src/leap/bitmask/gui/app.py @@ -61,9 +61,18 @@ DEBUG = os.environ.get("DEBUG", False) qApp = None bitmaskd = None +browser = None class BrowserWindow(QWebView): + """ + This qt-webkit window exposes a couple of callable objects through the + python-js bridge: + + bitmaskApp.shutdown() -> shut downs the backend and frontend. + bitmaskBrowser.openPixelated() -> opens Pixelated app in a new window. + + """ def __init__(self, *args, **kw): url = kw.pop('url', None) first = False @@ -80,6 +89,10 @@ class BrowserWindow(QWebView): self.bitmask_browser = NewPageConnector(self) if first else None self.loadPage(self.url) + self.proxy = AppProxy(self) if first else None + self.frame.addToJavaScriptWindowObject( + "bitmaskApp", self.proxy) + def loadPage(self, web_page): self.settings().setAttribute( QWebSettings.DeveloperExtrasEnabled, True) @@ -125,6 +138,16 @@ class BrowserWindow(QWebView): sys.exit(1) +class AppProxy(QObject): + + @pyqtSlot() + def shutdown(self): + """To be exposed from the js bridge""" + global browser + if browser: + browser.close() + + pixbrowser = None @@ -149,6 +172,7 @@ def _handle_kill(*args, **kw): def launch_gui(): global qApp global bitmaskd + global browser if IS_WIN: freeze_support() -- cgit v1.2.3