[Pkg-privacy-commits] [onionshare] 43/66: Closing the GUI window causes any current download to stop immediately (fixes #262)

Ulrike Uhlig u-guest at moszumanska.debian.org
Wed Apr 13 22:17:50 UTC 2016


This is an automated email from the git hooks/post-receive script.

u-guest pushed a commit to branch master
in repository onionshare.

commit 7b8e9e1e6fb49f16a080638f461b0676690ecf2b
Author: Micah Lee <micah at micahflee.com>
Date:   Sun Apr 10 17:43:37 2016 -0700

    Closing the GUI window causes any current download to stop immediately (fixes #262)
---
 onionshare/web.py                | 19 +++++++++++++++++++
 onionshare_gui/onionshare_gui.py |  3 +++
 2 files changed, 22 insertions(+)

diff --git a/onionshare/web.py b/onionshare/web.py
index ef8ee9e..17e6fde 100644
--- a/onionshare/web.py
+++ b/onionshare/web.py
@@ -161,6 +161,10 @@ def index(slug_candidate):
         filesize_human=helpers.human_readable_filesize(zip_filesize)
     )
 
+# If the client closes the OnionShare window while a download is in progress,
+# it should immediately stop serving the file. The client_cancel global is
+# used to tell the download function that the client is canceling the download.
+client_cancel = False
 
 @app.route("/<slug_candidate>/download")
 def download(slug_candidate):
@@ -187,12 +191,21 @@ def download(slug_candidate):
     basename = os.path.basename(zip_filename)
 
     def generate():
+        # The user hasn't canceled the download
+        global client_cancel
+        client_cancel = False
+
         chunk_size = 102400  # 100kb
 
         fp = open(zip_filename, 'rb')
         done = False
         canceled = False
         while not done:
+            # The user has canceled the download, so stop serving the file
+            if client_cancel:
+                add_request(REQUEST_CANCELED, path, {'id': download_id})
+                break;
+
             chunk = fp.read(chunk_size)
             if chunk == b'':
                 done = True
@@ -285,6 +298,12 @@ def stop(port):
     """
     Stop the flask web server by loading /shutdown.
     """
+
+    # If the user cancels the download, let the download function know to stop
+    # serving the file
+    global client_cancel
+    client_cancel = True
+
     # to stop flask, load http://127.0.0.1:<port>/<shutdown_slug>/shutdown
     try:
         if transparent_torification:
diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py
index e0f05f6..5aa54c0 100644
--- a/onionshare_gui/onionshare_gui.py
+++ b/onionshare_gui/onionshare_gui.py
@@ -243,6 +243,9 @@ class OnionShareGui(QtWidgets.QMainWindow):
         """
         self.status_bar.clearMessage()
 
+    def closeEvent(self, e):
+        self.stop_server()
+
 
 def alert(msg, icon=QtWidgets.QMessageBox.NoIcon):
     """

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onionshare.git



More information about the Pkg-privacy-commits mailing list