From 91a0c6018978bf234fe1675d8c99cd385444853f Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Mon, 4 Dec 2017 15:03:28 +1100 Subject: [PATCH] Better fix for preventing timeout firing if a download is not yet done (works for CLI as well as GUI) --- onionshare/__init__.py | 2 +- onionshare/web.py | 5 +++-- onionshare_gui/onionshare_gui.py | 11 ++--------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/onionshare/__init__.py b/onionshare/__init__.py index 6ab030ef..4b7b47b0 100644 --- a/onionshare/__init__.py +++ b/onionshare/__init__.py @@ -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 diff --git a/onionshare/web.py b/onionshare/web.py index 4ae10221..03da8fd7 100644 --- a/onionshare/web.py +++ b/onionshare/web.py @@ -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("/") 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 diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 2a3b3468..a9f800be 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -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()