mirror of
https://github.com/onionshare/onionshare.git
synced 2025-06-07 14:23:01 -04:00
Closing the GUI window causes any current download to stop immediately (fixes #262)
This commit is contained in:
parent
f5496ba20c
commit
7b8e9e1e6f
2 changed files with 22 additions and 0 deletions
|
@ -161,6 +161,10 @@ def index(slug_candidate):
|
||||||
filesize_human=helpers.human_readable_filesize(zip_filesize)
|
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")
|
@app.route("/<slug_candidate>/download")
|
||||||
def download(slug_candidate):
|
def download(slug_candidate):
|
||||||
|
@ -187,12 +191,21 @@ def download(slug_candidate):
|
||||||
basename = os.path.basename(zip_filename)
|
basename = os.path.basename(zip_filename)
|
||||||
|
|
||||||
def generate():
|
def generate():
|
||||||
|
# The user hasn't canceled the download
|
||||||
|
global client_cancel
|
||||||
|
client_cancel = False
|
||||||
|
|
||||||
chunk_size = 102400 # 100kb
|
chunk_size = 102400 # 100kb
|
||||||
|
|
||||||
fp = open(zip_filename, 'rb')
|
fp = open(zip_filename, 'rb')
|
||||||
done = False
|
done = False
|
||||||
canceled = False
|
canceled = False
|
||||||
while not done:
|
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)
|
chunk = fp.read(chunk_size)
|
||||||
if chunk == b'':
|
if chunk == b'':
|
||||||
done = True
|
done = True
|
||||||
|
@ -285,6 +298,12 @@ def stop(port):
|
||||||
"""
|
"""
|
||||||
Stop the flask web server by loading /shutdown.
|
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
|
# to stop flask, load http://127.0.0.1:<port>/<shutdown_slug>/shutdown
|
||||||
try:
|
try:
|
||||||
if transparent_torification:
|
if transparent_torification:
|
||||||
|
|
|
@ -243,6 +243,9 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||||
"""
|
"""
|
||||||
self.status_bar.clearMessage()
|
self.status_bar.clearMessage()
|
||||||
|
|
||||||
|
def closeEvent(self, e):
|
||||||
|
self.stop_server()
|
||||||
|
|
||||||
|
|
||||||
def alert(msg, icon=QtWidgets.QMessageBox.NoIcon):
|
def alert(msg, icon=QtWidgets.QMessageBox.NoIcon):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue