Better fix for preventing timeout firing if a download is not yet done (works for CLI as well as GUI)

This commit is contained in:
Miguel Jacq 2017-12-04 15:03:28 +11:00
parent 2eb7bca242
commit 91a0c60189
No known key found for this signature in database
GPG key ID: EEA4341C6D97A0B6
3 changed files with 6 additions and 12 deletions

View file

@ -134,7 +134,7 @@ def main(cwd=None):
while t.is_alive():
if app.shutdown_timeout > 0:
# if the shutdown timer was set and has run out, stop the server
if not app.shutdown_timer.is_alive():
if not app.shutdown_timer.is_alive() and web.done:
print(strings._("close_on_timeout"))
web.stop(app.port)
break

View file

@ -187,6 +187,7 @@ def check_slug_candidate(slug_candidate, slug_compare=None):
# one download at a time.
download_in_progress = False
done = False
@app.route("/<slug_candidate>")
def index(slug_candidate):
@ -236,7 +237,7 @@ def download(slug_candidate):
# Deny new downloads if "Stop After First Download" is checked and there is
# currently a download
global stay_open, download_in_progress
global stay_open, download_in_progress, done
deny_download = not stay_open and download_in_progress
if deny_download:
r = make_response(render_template_string(open(common.get_resource_path('html/denied.html')).read()))
@ -267,7 +268,7 @@ def download(slug_candidate):
client_cancel = False
# Starting a new download
global stay_open, download_in_progress
global stay_open, download_in_progress, done
if not stay_open:
download_in_progress = True

View file

@ -384,11 +384,6 @@ class OnionShareGui(QtWidgets.QMainWindow):
Check for messages communicated from the web app, and update the GUI accordingly.
"""
self.update()
global download_in_progress
try:
download_in_progress
except NameError:
download_in_progress = False
# scroll to the bottom of the dl progress bar log pane
# if a new download has been added
@ -423,23 +418,21 @@ class OnionShareGui(QtWidgets.QMainWindow):
elif event["type"] == web.REQUEST_PROGRESS:
self.downloads.update_download(event["data"]["id"], event["data"]["bytes"])
download_in_progress = True
# is the download complete?
if event["data"]["bytes"] == web.zip_filesize:
download_in_progress = False
if self.systemTray.supportsMessages() and self.settings.get('systray_notifications'):
self.systemTray.showMessage(strings._('systray_download_completed_title', True), strings._('systray_download_completed_message', True))
# close on finish?
if not web.get_stay_open():
self.server_status.stop_server()
self.server_status.shutdown_timeout_reset()
self.status_bar.showMessage(strings._('closing_automatically',True))
else:
if self.server_status.status == self.server_status.STATUS_STOPPED:
self.downloads.cancel_download(event["data"]["id"])
elif event["type"] == web.REQUEST_CANCELED:
download_in_progress = False
self.downloads.cancel_download(event["data"]["id"])
if self.systemTray.supportsMessages() and self.settings.get('systray_notifications'):
self.systemTray.showMessage(strings._('systray_download_canceled_title', True), strings._('systray_download_canceled_message', True))
@ -452,7 +445,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
if self.app.shutdown_timer and self.server_status.timer_enabled:
if self.timeout > 0:
if not self.app.shutdown_timer.is_alive():
if not download_in_progress:
if web.done:
self.server_status.stop_server()
self.status_bar.showMessage(strings._('close_on_timeout',True))
self.server_status.shutdown_timeout_reset()