From eaa37206e54b112012e3470480d883480df4a7b9 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Tue, 5 Dec 2017 11:18:26 +1100 Subject: [PATCH] Let the timer stop the share if there were no downloads, or all downloads are done --- onionshare/__init__.py | 10 ++++++---- onionshare_gui/onionshare_gui.py | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/onionshare/__init__.py b/onionshare/__init__.py index 4b7b47b0..99beb0e0 100644 --- a/onionshare/__init__.py +++ b/onionshare/__init__.py @@ -134,10 +134,12 @@ 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() and web.done: - print(strings._("close_on_timeout")) - web.stop(app.port) - break + if not app.shutdown_timer.is_alive(): + # If there were no attempts to download the share, or all downloads are done, we can stop + if web.download_count == 0 or web.done: + print(strings._("close_on_timeout")) + web.stop(app.port) + break # Allow KeyboardInterrupt exception to be handled with threads # https://stackoverflow.com/questions/3788208/python-threading-ignores-keyboardinterrupt-exception time.sleep(0.2) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index a9f800be..fd278394 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -427,7 +427,7 @@ class OnionShareGui(QtWidgets.QMainWindow): 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)) + 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"]) @@ -445,10 +445,12 @@ 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 web.done: + # If there were no attempts to download the share, or all downloads are done, we can stop + if web.download_count == 0 or web.done: self.server_status.stop_server() - self.status_bar.showMessage(strings._('close_on_timeout',True)) + self.status_bar.showMessage(strings._('close_on_timeout', True)) self.server_status.shutdown_timeout_reset() + # A download is probably still running - hold off on stopping the share else: self.status_bar.showMessage(strings._('timeout_download_still_running', True))