From 433c7c754e4c1a44dba4678cfbc635cdcf53c84e Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 7 Dec 2017 16:10:52 +1100 Subject: [PATCH 01/19] cleanup the ephemeral hidden service when GUI server is stopped, but don't disconnect from Tor --- onionshare/onion.py | 39 +++++++++++++++++--------------- onionshare_gui/onionshare_gui.py | 2 ++ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/onionshare/onion.py b/onionshare/onion.py index 2f79719b..219ee175 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -415,7 +415,7 @@ class Onion(object): return onion_host - def cleanup(self): + def cleanup(self, stop_tor=True): """ Stop onion services that were created earlier. If there's a tor subprocess running, kill it. """ @@ -429,25 +429,28 @@ class Onion(object): pass self.service_id = None - # Stop tor process - if self.tor_proc: - self.tor_proc.terminate() - time.sleep(0.2) - if not self.tor_proc.poll(): - self.tor_proc.kill() - self.tor_proc = None + if stop_tor: + # Stop tor process + if self.tor_proc: + self.tor_proc.terminate() + time.sleep(0.2) + if not self.tor_proc.poll(): + try: + self.tor_proc.kill() + except: + pass + self.tor_proc = None - # Reset other Onion settings - self.connected_to_tor = False - self.stealth = False - self.service_id = None + # Reset other Onion settings + self.connected_to_tor = False + self.stealth = False - try: - # Delete the temporary tor data directory - self.tor_data_directory.cleanup() - except AttributeError: - # Skip if cleanup was somehow run before connect - pass + try: + # Delete the temporary tor data directory + self.tor_data_directory.cleanup() + except AttributeError: + # Skip if cleanup was somehow run before connect + pass def get_tor_socks_port(self): """ diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 3ed30db7..4e4a6c0e 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -354,6 +354,8 @@ class OnionShareGui(QtWidgets.QMainWindow): # Probably we had no port to begin with (Onion service didn't start) pass self.app.cleanup() + # Remove ephemeral service, but don't disconnect from Tor + self.onion.cleanup(stop_tor=False) self.filesize_warning.hide() self.stop_server_finished.emit() From 1f9ee70efe43d75d3ddc5fe4f070d7b90f8af4f2 Mon Sep 17 00:00:00 2001 From: wondratsch Date: Thu, 7 Dec 2017 11:51:32 +0100 Subject: [PATCH 02/19] add FreeBSD Support --- onionshare/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onionshare/common.py b/onionshare/common.py index 26b949ff..066753a4 100644 --- a/onionshare/common.py +++ b/onionshare/common.py @@ -104,7 +104,7 @@ def get_tor_paths(): tor_path = os.path.join(base_path, 'Resources', 'Tor', 'tor') tor_geo_ip_file_path = os.path.join(base_path, 'Resources', 'Tor', 'geoip') tor_geo_ipv6_file_path = os.path.join(base_path, 'Resources', 'Tor', 'geoip6') - elif p == 'OpenBSD': + elif p == 'OpenBSD' or p == 'FreeBSD': tor_path = '/usr/local/bin/tor' tor_geo_ip_file_path = '/usr/local/share/tor/geoip' tor_geo_ipv6_file_path = '/usr/local/share/tor/geoip6' From 1b610fa224ab124775e50939fad43eeddd55be41 Mon Sep 17 00:00:00 2001 From: Lazlo Westerhof Date: Fri, 8 Dec 2017 21:53:51 +0100 Subject: [PATCH 03/19] Update Dutch translation. --- share/locale/nl.json | 56 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/share/locale/nl.json b/share/locale/nl.json index 90a84ca6..79a35195 100644 --- a/share/locale/nl.json +++ b/share/locale/nl.json @@ -9,18 +9,31 @@ "give_this_url_stealth": "Geef deze URL en de HidServAuth regel aan de persoon aan wie je dit bestand verzend:", "ctrlc_to_stop": "Druk Ctrl-C om de server te stoppen", "not_a_file": "{0:s} is geen bestand.", + "not_a_readable_file": "{0:s} is geen leesbaar bestand.", + "no_available_port": "Kan de Onion service niet starten, er zijn geen poorten beschikbaar.", "download_page_loaded": "Downloadpagina geladen", "other_page_loaded": "URL geladen", - "closing_automatically": "Sluit nu automatisch omdat download gereed is", + "close_on_timeout": "Sluit automatisch omdat timeout bereikt is", + "closing_automatically": "Sluit automatisch omdat download gereed is", + "timeout_download_still_running": "Wachten totdat download gereed is voor automatisch sluiten", "large_filesize": "Waarschuwing: Versturen van grote bestanden kan uren duren", "error_tails_invalid_port": "Ongeldige waarde, poort moet een integer zijn", "error_tails_unknown_root": "Onbekende fout met het Tails root proces", + "systray_menu_exit": "Afsluiten", + "systray_download_started_title": "OnionShare download gestart", + "systray_download_started_message": "Een gebruiker is begonnen met downloaden van je bestanden", + "systray_download_completed_title": "OnionShare download gereed", + "systray_download_completed_message": "De gebruiker is klaar met downloaden", + "systray_download_canceled_title": "OnionShare download afgebroken", + "systray_download_canceled_message": "De gebruiker heeft de download afgebroken", "help_local_only": "Maak geen gebruik van Tor, alleen voor ontwikkeling", "help_stay_open": "Laat verborgen service draaien nadat download gereed is", + "help_shutdown_timeout": "Sluit de Onion service na N seconden", "help_transparent_torification": "Mijn systeem gebruikt Tor als proxyserver", - "help_stealth": "Maak geheime onion service (geavanceerd)", + "help_stealth": "Maak stealth Onion service (geavanceerd)", "help_debug": "Log fouten naar harde schijf", "help_filename": "Lijst van bestanden of mappen om te delen", + "help_config": "Pad naar een JSON configuratie bestand (optioneel)", "gui_drag_and_drop": "Sleep en zet\nbestanden hier neer", "gui_add": "Toevoegen", "gui_delete": "Verwijder", @@ -50,25 +63,39 @@ "zip_progress_bar_format": "Bestanden verwerken: %p%", "error_stealth_not_supported": "Om een geheime onion service te maken heb je minstens Tor 0.2.9.1-alpha (of Tor Browser 6.5) en minstens python3-stem 1.5.0 nodig.", "error_ephemeral_not_supported": "OnionShare vereist minstens Tor 0.2.7.1 en minstens python3-stem 1.4.0.", - "gui_menu_file_menu": "&Bestand", - "gui_menu_settings_action": "&Instellingen", - "gui_menu_quit_action": "&Afsluiten", "gui_settings_window_title": "Instellingen", + "gui_settings_window_title": "Instellingen", + "gui_settings_stealth_label": "Stealth (geavanceerd)", + "gui_settings_stealth_option": "Maak stealth onion services", + "gui_settings_stealth_option_details": "Dit maakt OnionShare veiliger, maar ook lastiger voor de ontvanger om te verbinden.
Meer informatie.", + "gui_settings_autoupdate_label": "Controleer voor updates", + "gui_settings_autoupdate_option": "Notificeer me als er updates beschikbaar zijn", + "gui_settings_autoupdate_timestamp": "Laatste controle: {}", + "gui_settings_autoupdate_timestamp_never": "Nooit", + "gui_settings_autoupdate_check_button": "Controleer voor update", + "gui_settings_sharing_label": "Deel opties", + "gui_settings_close_after_first_download_option": "Stop delen na eerste download", + "gui_settings_systray_notifications": "Laat desktop notificaties zien", "gui_settings_connection_type_label": "Hoe moet OnionShare verbinden met Tor?", + "gui_settings_connection_type_bundled_option": "Gebruik Tor die is meegeleverd met OnionShare", "gui_settings_connection_type_automatic_option": "Probeer automatische configuratie met Tor Browser", "gui_settings_connection_type_control_port_option": "Verbinden via controle poort", "gui_settings_connection_type_socket_file_option": "Verbinden via socket bestand", + "gui_settings_connection_type_test_button": "Test Tor instellingen", "gui_settings_control_port_label": "Controle poort", "gui_settings_socket_file_label": "Socket bestand", + "gui_settings_socks_label": "SOCKS poort", "gui_settings_authenticate_label": "Tor authenticatie opties", "gui_settings_authenticate_no_auth_option": "Geen authenticatie of cookie authenticatie", "gui_settings_authenticate_password_option": "Wachtwoord", "gui_settings_authenticate_cookie_option": "Cookie", "gui_settings_password_label": "Wachtwoord", "gui_settings_cookie_label": "Cookie pad", - "gui_settings_button_test": "Test Instellingen", "gui_settings_button_save": "Opslaan", "gui_settings_button_cancel": "Annuleren", + "gui_settings_button_help": "Help", + "gui_settings_shutdown_timeout_choice": "Auto-stop timer instellen?", + "gui_settings_shutdown_timeout": "Stop delen om:", "settings_saved": "Instellingen opgeslagen in {}", "settings_error_unknown": "Kan geen verbinding maken met de Tor controller omdat de instellingen niet kloppen.", "settings_error_automatic": "Kan geen verbinding maken met de Tor controller. Draait Tor Browser in de achtergrond? Deze kan je verkrijgen via https://www.torproject.org/.", @@ -77,6 +104,23 @@ "settings_error_auth": "Verbonden met {}:{}, maar kan niet authenticeren. Misschien is het geen Tor controller?", "settings_error_missing_password": "Verbonden met Tor controller, maar het heeft een wachtwoord nodig voor authenticatie.", "settings_error_unreadable_cookie_file": "Verbonden met Tor controller, maar kan niet authenticeren omdat wachtwoord onjuist is en gebruiker heeft niet de permissies om cookie bestand te lezen.", + "settings_error_bundled_tor_not_supported": "Meegeleverde Tor is niet onersteunt wanneer je niet de ontwikkelaarsmodus gebruikt in Windows or macOS.", + "settings_error_bundled_tor_timeout": "Verbinden met Tor duurt te lang. Misschien is je computer offline, of je klok is niet accuraat.", + "settings_error_bundled_tor_canceled": "Het Tor is afgesloten voordat het kon verbinden.", + "settings_error_bundled_tor_broken": "OnionShare kan niet verbinden met Tor op de achtergrond:\n{}", "settings_test_success": "Gefeliciteerd, OnionShare kan verbinden met de Tor controller.\n\nTor version: {}\nOndersteunt kortstondige onion services: {}\nOndersteunt geheime onion services: {}", "error_tor_protocol_error": "Fout bij praten met de Tor controller.\nAls je Whonix gebruikt, kijk dan hier https://www.whonix.org/wiki/onionshare om OnionShare werkend te krijgen." + "connecting_to_tor": "Verbinden met het Tor network", + "update_available": "Er is een OnionShare update beschikbaar. Klik hier om te downloaden.

Geinstalleerde versie: {}
Laatste versie: {}", + "update_error_check_error": "Fout bij controleren voor updates: Misschien ben je niet verbonden met Tor, of misschien is de OnionShare website down.", + "update_error_invalid_latest_version": "Fout bij controleren voor updates: De OnionShare website zegt dat de laatste versie '{}' is, maar dat lijkt geen valide versie te zijn.", + "update_not_available": "Je draait de laatste versie van OnionShare.", + "gui_tor_connection_ask": "Wil je de OnionShare instellingen openen om het verbindingsprobleem met Tor op te lossen?", + "gui_tor_connection_ask_open_settings": "Open Instellingen", + "gui_tor_connection_ask_quit": "Afsluiten", + "gui_tor_connection_error_settings": "Probeer de instellingen hoe OnionShare verbind met het Tor network aan te passen in Instellingen.", + "gui_tor_connection_canceled": "OnionShare kan niet verbinden met Tor.\n\nControleer of je verbonden bent met het internet, herstart OnionShare om de Tor verbinding te configureren.", + "gui_server_started_after_timeout": "De server startte na de gekozen auto-timeout.\nDeel opnieuw.", + "gui_server_timeout_expired": "De gekozen timeout is al verlopen.\nKies nieuwe timeout deel opnieuw.", + "share_via_onionshare": "Deel via OnionShare" } From cbf173580d0f9e90bd21bba7296a56c3e560d8a9 Mon Sep 17 00:00:00 2001 From: Lazlo Westerhof Date: Fri, 8 Dec 2017 21:56:09 +0100 Subject: [PATCH 04/19] Add missing comma. --- share/locale/nl.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/locale/nl.json b/share/locale/nl.json index 79a35195..1203f2ee 100644 --- a/share/locale/nl.json +++ b/share/locale/nl.json @@ -109,7 +109,7 @@ "settings_error_bundled_tor_canceled": "Het Tor is afgesloten voordat het kon verbinden.", "settings_error_bundled_tor_broken": "OnionShare kan niet verbinden met Tor op de achtergrond:\n{}", "settings_test_success": "Gefeliciteerd, OnionShare kan verbinden met de Tor controller.\n\nTor version: {}\nOndersteunt kortstondige onion services: {}\nOndersteunt geheime onion services: {}", - "error_tor_protocol_error": "Fout bij praten met de Tor controller.\nAls je Whonix gebruikt, kijk dan hier https://www.whonix.org/wiki/onionshare om OnionShare werkend te krijgen." + "error_tor_protocol_error": "Fout bij praten met de Tor controller.\nAls je Whonix gebruikt, kijk dan hier https://www.whonix.org/wiki/onionshare om OnionShare werkend te krijgen.", "connecting_to_tor": "Verbinden met het Tor network", "update_available": "Er is een OnionShare update beschikbaar. Klik hier om te downloaden.

Geinstalleerde versie: {}
Laatste versie: {}", "update_error_check_error": "Fout bij controleren voor updates: Misschien ben je niet verbonden met Tor, of misschien is de OnionShare website down.", From e06f4f72303ff40959ecb5e72f6bf8ced3929c28 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Tue, 12 Dec 2017 17:02:11 +1100 Subject: [PATCH 05/19] Catch OSError when preparing the zip file during server start. Fixes #453 --- onionshare_gui/onionshare_gui.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 3ed30db7..f06355d8 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -287,12 +287,16 @@ class OnionShareGui(QtWidgets.QMainWindow): def _set_processed_size(x): if self._zip_progress_bar != None: self._zip_progress_bar.update_processed_size_signal.emit(x) - web.set_file_info(self.file_selection.file_list.filenames, processed_size_callback=_set_processed_size) - self.app.cleanup_filenames.append(web.zip_filename) - self.starting_server_step3.emit() + try: + web.set_file_info(self.file_selection.file_list.filenames, processed_size_callback=_set_processed_size) + self.app.cleanup_filenames.append(web.zip_filename) + self.starting_server_step3.emit() - # done - self.start_server_finished.emit() + # done + self.start_server_finished.emit() + except OSError as e: + self.starting_server_error.emit(e.strerror) + return #self.status_bar.showMessage(strings._('gui_starting_server2', True)) t = threading.Thread(target=finish_starting_server, kwargs={'self': self}) @@ -339,6 +343,9 @@ class OnionShareGui(QtWidgets.QMainWindow): Alert(error, QtWidgets.QMessageBox.Warning) self.server_status.stop_server() + if self._zip_progress_bar is not None: + self.status_bar.removeWidget(self._zip_progress_bar) + self._zip_progress_bar = None self.status_bar.clearMessage() def stop_server(self): From da5946b4d452cf70cecf629d081a44f3ddc65265 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 20 Dec 2017 07:39:55 +1100 Subject: [PATCH 06/19] Clear the status bar messages earlier when starting a new share --- onionshare_gui/onionshare_gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 3ed30db7..4eb5bc9e 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -238,6 +238,7 @@ class OnionShareGui(QtWidgets.QMainWindow): # Hide and reset the downloads if we have previously shared self.downloads_container.hide() self.downloads.reset_downloads() + self.status_bar.clearMessage() # Reset web counters web.download_count = 0 @@ -278,7 +279,6 @@ class OnionShareGui(QtWidgets.QMainWindow): self._zip_progress_bar = ZipProgressBar(0) self._zip_progress_bar.total_files_size = OnionShareGui._compute_total_size( self.file_selection.file_list.filenames) - self.status_bar.clearMessage() self.status_bar.insertWidget(0, self._zip_progress_bar) # prepare the files for sending in a new thread From 6e64f08f08076ce6b84977d662a9415ec8daf21c Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 21 Dec 2017 09:22:53 +1100 Subject: [PATCH 07/19] #493, #500 - detect if the Tor connection (bundled, TorBrowser or otherwise) has been lost while the app is open. Stop a running share if so --- onionshare/onion.py | 6 +++++ onionshare_gui/onionshare_gui.py | 17 ++++++++++++++ onionshare_gui/settings_dialog.py | 39 +++++++++++++++++-------------- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/onionshare/onion.py b/onionshare/onion.py index 2f79719b..adfb4dbf 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -375,6 +375,12 @@ class Onion(object): # ephemeral stealth onion services are not supported self.supports_stealth = False + def is_authenticated(self): + """ + Returns True if the Tor connection is still working, or False otherwise. + """ + return self.c.is_authenticated() + def start_onion_service(self, port): """ Start a onion service on port 80, pointing to the given port, and diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 3ed30db7..f6ebf6be 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -219,6 +219,11 @@ class OnionShareGui(QtWidgets.QMainWindow): def reload_settings(): common.log('OnionShareGui', 'open_settings', 'settings have changed, reloading') self.settings.load() + # We might've stopped the main requests timer if a Tor connection failed. + # If we've reloaded settings, we probably succeeded in obtaining a new + # connection. If so, restart the timer. + if not self.timer.isActive(): + self.timer.start() d = SettingsDialog(self.onion, self.qtapp, self.config) d.settings_saved.connect(reload_settings) @@ -389,6 +394,18 @@ class OnionShareGui(QtWidgets.QMainWindow): """ self.update() + # Have we lost connection to Tor somehow? + try: + # Tor Browser may not even have been open when we started OnionShare, + # in which case onion.is_authenticated() throws a NoneType error + self.onion + if not self.onion.is_authenticated(): + self.timer.stop() + self.start_server_error(strings._('error_tor_protocol_error')) + self._tor_connection_canceled() + except: + pass + # scroll to the bottom of the dl progress bar log pane # if a new download has been added if self.new_download: diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index df806a06..7ead3f1b 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -459,26 +459,31 @@ class SettingsDialog(QtWidgets.QDialog): # If Tor isn't connected, or if Tor settings have changed, Reinitialize # the Onion object reboot_onion = False - if self.onion.connected_to_tor: - def changed(s1, s2, keys): - """ - Compare the Settings objects s1 and s2 and return true if any values - have changed for the given keys. - """ - for key in keys: - if s1.get(key) != s2.get(key): - return True - return False + try: + self.onion + if self.onion.is_authenticated(): + def changed(s1, s2, keys): + """ + Compare the Settings objects s1 and s2 and return true if any values + have changed for the given keys. + """ + for key in keys: + if s1.get(key) != s2.get(key): + return True + return False - if changed(settings, self.old_settings, [ - 'connection_type', 'control_port_address', - 'control_port_port', 'socks_address', 'socks_port', - 'socket_file_path', 'auth_type', 'auth_password']): + if changed(settings, self.old_settings, [ + 'connection_type', 'control_port_address', + 'control_port_port', 'socks_address', 'socks_port', + 'socket_file_path', 'auth_type', 'auth_password']): + reboot_onion = True + + else: + # Tor isn't connected, so try connecting reboot_onion = True - - else: - # Tor isn't connected, so try connecting + except: + # We definitely aren't connected, as the onion object had no attribute is_authenticated() reboot_onion = True # Do we need to reinitialize Tor? From 2b36938d5321afaca4daed4cbbcb6d8e095cd953 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 21 Dec 2017 12:15:17 +1100 Subject: [PATCH 08/19] Ensure we don't consider the Tor connection 'lost' if we're still in the connection dialog process (wait for that thread to finish). Also various implementations of onion.is_authenticated() for a more robust check than onion.connected_to_tor, which seemed to help some corner cases --- onionshare/onion.py | 7 +++- onionshare_gui/onionshare_gui.py | 24 +++++-------- onionshare_gui/settings_dialog.py | 45 +++++++++++-------------- onionshare_gui/tor_connection_dialog.py | 14 ++++---- 4 files changed, 42 insertions(+), 48 deletions(-) diff --git a/onionshare/onion.py b/onionshare/onion.py index adfb4dbf..364bcb89 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -375,11 +375,16 @@ class Onion(object): # ephemeral stealth onion services are not supported self.supports_stealth = False + def is_authenticated(self): """ Returns True if the Tor connection is still working, or False otherwise. """ - return self.c.is_authenticated() + if self.c: + return self.c.is_authenticated() + else: + return False + def start_onion_service(self, port): """ diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index f6ebf6be..b7783738 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -142,10 +142,10 @@ class OnionShareGui(QtWidgets.QMainWindow): self.set_server_active(False) # Start the "Connecting to Tor" dialog, which calls onion.connect() - tor_con = TorConnectionDialog(self.qtapp, self.settings, self.onion) - tor_con.canceled.connect(self._tor_connection_canceled) - tor_con.open_settings.connect(self._tor_connection_open_settings) - tor_con.start() + self.tor_con = TorConnectionDialog(self.qtapp, self.settings, self.onion) + self.tor_con.canceled.connect(self._tor_connection_canceled) + self.tor_con.open_settings.connect(self._tor_connection_open_settings) + self.tor_con.start() # After connecting to Tor, check for updates self.check_for_updates() @@ -394,17 +394,11 @@ class OnionShareGui(QtWidgets.QMainWindow): """ self.update() - # Have we lost connection to Tor somehow? - try: - # Tor Browser may not even have been open when we started OnionShare, - # in which case onion.is_authenticated() throws a NoneType error - self.onion - if not self.onion.is_authenticated(): - self.timer.stop() - self.start_server_error(strings._('error_tor_protocol_error')) - self._tor_connection_canceled() - except: - pass + # Has the Tor Connection dialog finished, but we've since lost connection to Tor somehow? + if not self.onion.is_authenticated() and self.tor_con.t.isFinished(): + self.timer.stop() + self.start_server_error(strings._('error_tor_protocol_error')) + self._tor_connection_canceled() # scroll to the bottom of the dl progress bar log pane # if a new download has been added diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index 7ead3f1b..15d8f634 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -459,31 +459,26 @@ class SettingsDialog(QtWidgets.QDialog): # If Tor isn't connected, or if Tor settings have changed, Reinitialize # the Onion object reboot_onion = False - try: - self.onion - if self.onion.is_authenticated(): - def changed(s1, s2, keys): - """ - Compare the Settings objects s1 and s2 and return true if any values - have changed for the given keys. - """ - for key in keys: - if s1.get(key) != s2.get(key): - return True - return False + if self.onion.is_authenticated(): + def changed(s1, s2, keys): + """ + Compare the Settings objects s1 and s2 and return true if any values + have changed for the given keys. + """ + for key in keys: + if s1.get(key) != s2.get(key): + return True + return False - if changed(settings, self.old_settings, [ - 'connection_type', 'control_port_address', - 'control_port_port', 'socks_address', 'socks_port', - 'socket_file_path', 'auth_type', 'auth_password']): + if changed(settings, self.old_settings, [ + 'connection_type', 'control_port_address', + 'control_port_port', 'socks_address', 'socks_port', + 'socket_file_path', 'auth_type', 'auth_password']): - reboot_onion = True - - else: - # Tor isn't connected, so try connecting reboot_onion = True - except: - # We definitely aren't connected, as the onion object had no attribute is_authenticated() + + else: + # Tor isn't connected, so try connecting reboot_onion = True # Do we need to reinitialize Tor? @@ -497,7 +492,7 @@ class SettingsDialog(QtWidgets.QDialog): common.log('SettingsDialog', 'save_clicked', 'Onion done rebooting, connected to Tor: {}'.format(self.onion.connected_to_tor)) - if self.onion.connected_to_tor and not tor_con.wasCanceled(): + if self.onion.is_authenticated() and not tor_con.wasCanceled(): self.settings_saved.emit() self.close() @@ -510,7 +505,7 @@ class SettingsDialog(QtWidgets.QDialog): Cancel button clicked. """ common.log('SettingsDialog', 'cancel_clicked') - if not self.onion.connected_to_tor: + if not self.onion.is_authenticated(): Alert(strings._('gui_tor_connection_canceled', True), QtWidgets.QMessageBox.Warning) sys.exit() else: @@ -565,7 +560,7 @@ class SettingsDialog(QtWidgets.QDialog): common.log('SettingsDialog', 'closeEvent') # On close, if Tor isn't connected, then quit OnionShare altogether - if not self.onion.connected_to_tor: + if not self.onion.is_authenticated(): common.log('SettingsDialog', 'closeEvent', 'Closing while not connected to Tor') # Wait 1ms for the event loop to finish, then quit diff --git a/onionshare_gui/tor_connection_dialog.py b/onionshare_gui/tor_connection_dialog.py index fa4c7860..1785f391 100644 --- a/onionshare_gui/tor_connection_dialog.py +++ b/onionshare_gui/tor_connection_dialog.py @@ -57,12 +57,12 @@ class TorConnectionDialog(QtWidgets.QProgressDialog): def start(self): common.log('TorConnectionDialog', 'start') - t = TorConnectionThread(self, self.settings, self.onion) - t.tor_status_update.connect(self._tor_status_update) - t.connected_to_tor.connect(self._connected_to_tor) - t.canceled_connecting_to_tor.connect(self._canceled_connecting_to_tor) - t.error_connecting_to_tor.connect(self._error_connecting_to_tor) - t.start() + self.t = TorConnectionThread(self, self.settings, self.onion) + self.t.tor_status_update.connect(self._tor_status_update) + self.t.connected_to_tor.connect(self._connected_to_tor) + self.t.canceled_connecting_to_tor.connect(self._canceled_connecting_to_tor) + self.t.error_connecting_to_tor.connect(self._error_connecting_to_tor) + self.t.start() # The main thread needs to remain active, and checkign for Qt events, # until the thread is finished. Otherwise it won't be able to handle @@ -126,7 +126,7 @@ class TorConnectionThread(QtCore.QThread): # Connect to the Onion try: self.onion.connect(self.settings, False, self._tor_status_update) - if self.onion.connected_to_tor: + if self.onion.is_authenticated(): self.connected_to_tor.emit() else: self.canceled_connecting_to_tor.emit() From c3c50c095516149475e8d141b66c98361eccddb9 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 21 Dec 2017 14:08:13 +1100 Subject: [PATCH 09/19] Fixes for the edge case where Tor connection dialog is canceled, but the Tor process remains open in the background, which was causing onion.is_authenticated() to True. Remove excessive alerts --- onionshare/onion.py | 2 +- onionshare_gui/onionshare_gui.py | 14 +++++++++----- onionshare_gui/settings_dialog.py | 2 ++ onionshare_gui/tor_connection_dialog.py | 3 ++- share/locale/en.json | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/onionshare/onion.py b/onionshare/onion.py index 364bcb89..6b50a00d 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -380,7 +380,7 @@ class Onion(object): """ Returns True if the Tor connection is still working, or False otherwise. """ - if self.c: + if self.c is not None: return self.c.is_authenticated() else: return False diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index b7783738..a5efa743 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -176,6 +176,7 @@ class OnionShareGui(QtWidgets.QMainWindow): quit, or open settings. """ common.log('OnionShareGui', '_tor_connection_canceled') + self.timer.stop() def ask(): a = Alert(strings._('gui_tor_connection_ask', True), QtWidgets.QMessageBox.Question, buttons=QtWidgets.QMessageBox.NoButton, autostart=False) @@ -394,11 +395,14 @@ class OnionShareGui(QtWidgets.QMainWindow): """ self.update() - # Has the Tor Connection dialog finished, but we've since lost connection to Tor somehow? - if not self.onion.is_authenticated() and self.tor_con.t.isFinished(): - self.timer.stop() - self.start_server_error(strings._('error_tor_protocol_error')) - self._tor_connection_canceled() + # Have we lost connection to Tor somehow? + if self.tor_con.t.isFinished(): + if not self.onion.is_authenticated(): + self.timer.stop() + if self.server_status.status != self.server_status.STATUS_STOPPED: + self.server_status.stop_server() + self.status_bar.clearMessage() + self._tor_connection_canceled() # scroll to the bottom of the dl progress bar log pane # if a new download has been added diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index 15d8f634..b4c7363a 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -460,6 +460,7 @@ class SettingsDialog(QtWidgets.QDialog): # the Onion object reboot_onion = False if self.onion.is_authenticated(): + common.log('SettingsDialog', 'save_clicked', 'Connected to Tor') def changed(s1, s2, keys): """ Compare the Settings objects s1 and s2 and return true if any values @@ -478,6 +479,7 @@ class SettingsDialog(QtWidgets.QDialog): reboot_onion = True else: + common.log('SettingsDialog', 'save_clicked', 'Not connected to Tor') # Tor isn't connected, so try connecting reboot_onion = True diff --git a/onionshare_gui/tor_connection_dialog.py b/onionshare_gui/tor_connection_dialog.py index 1785f391..ab797171 100644 --- a/onionshare_gui/tor_connection_dialog.py +++ b/onionshare_gui/tor_connection_dialog.py @@ -86,6 +86,7 @@ class TorConnectionDialog(QtWidgets.QProgressDialog): def _canceled_connecting_to_tor(self): common.log('TorConnectionDialog', '_canceled_connecting_to_tor') self.active = False + self.onion.cleanup() # Cancel connecting to Tor QtCore.QTimer.singleShot(1, self.cancel) @@ -126,7 +127,7 @@ class TorConnectionThread(QtCore.QThread): # Connect to the Onion try: self.onion.connect(self.settings, False, self._tor_status_update) - if self.onion.is_authenticated(): + if self.onion.connected_to_tor: self.connected_to_tor.emit() else: self.canceled_connecting_to_tor.emit() diff --git a/share/locale/en.json b/share/locale/en.json index 0756843e..344736fc 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -114,7 +114,7 @@ "update_error_check_error": "Error checking for updates: Maybe you're not connected to Tor, or maybe the OnionShare website is down.", "update_error_invalid_latest_version": "Error checking for updates: The OnionShare website responded saying the latest version is '{}', but that doesn't appear to be a valid version string.", "update_not_available": "You are running the latest version of OnionShare.", - "gui_tor_connection_ask": "Would you like to open OnionShare settings to troubleshoot connecting to Tor?", + "gui_tor_connection_ask": "Tor isn't running.\n\nWould you like to open OnionShare settings to troubleshoot connecting to Tor?", "gui_tor_connection_ask_open_settings": "Open Settings", "gui_tor_connection_ask_quit": "Quit", "gui_tor_connection_error_settings": "Try adjusting how OnionShare connects to the Tor network in Settings.", From 5faecdb3c6b9389111a329037c2d7428bb9f8482 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sat, 23 Dec 2017 16:43:58 +1100 Subject: [PATCH 10/19] Don't show alert dialogs when Tor disconnects - just display in statusbar and stop any active share. --- onionshare_gui/onionshare_gui.py | 10 +++++----- share/locale/en.json | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index a5efa743..7c44b769 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -176,7 +176,6 @@ class OnionShareGui(QtWidgets.QMainWindow): quit, or open settings. """ common.log('OnionShareGui', '_tor_connection_canceled') - self.timer.stop() def ask(): a = Alert(strings._('gui_tor_connection_ask', True), QtWidgets.QMessageBox.Question, buttons=QtWidgets.QMessageBox.NoButton, autostart=False) @@ -223,8 +222,10 @@ class OnionShareGui(QtWidgets.QMainWindow): # We might've stopped the main requests timer if a Tor connection failed. # If we've reloaded settings, we probably succeeded in obtaining a new # connection. If so, restart the timer. - if not self.timer.isActive(): - self.timer.start() + if self.onion.is_authenticated(): + if not self.timer.isActive(): + self.timer.start() + self.status_bar.clearMessage() d = SettingsDialog(self.onion, self.qtapp, self.config) d.settings_saved.connect(reload_settings) @@ -401,8 +402,7 @@ class OnionShareGui(QtWidgets.QMainWindow): self.timer.stop() if self.server_status.status != self.server_status.STATUS_STOPPED: self.server_status.stop_server() - self.status_bar.clearMessage() - self._tor_connection_canceled() + self.status_bar.showMessage(strings._('gui_tor_connection_lost', True)) # scroll to the bottom of the dl progress bar log pane # if a new download has been added diff --git a/share/locale/en.json b/share/locale/en.json index 344736fc..abd734c9 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -114,11 +114,12 @@ "update_error_check_error": "Error checking for updates: Maybe you're not connected to Tor, or maybe the OnionShare website is down.", "update_error_invalid_latest_version": "Error checking for updates: The OnionShare website responded saying the latest version is '{}', but that doesn't appear to be a valid version string.", "update_not_available": "You are running the latest version of OnionShare.", - "gui_tor_connection_ask": "Tor isn't running.\n\nWould you like to open OnionShare settings to troubleshoot connecting to Tor?", + "gui_tor_connection_ask": "Would you like to open OnionShare settings to troubleshoot connecting to Tor?", "gui_tor_connection_ask_open_settings": "Open Settings", "gui_tor_connection_ask_quit": "Quit", "gui_tor_connection_error_settings": "Try adjusting how OnionShare connects to the Tor network in Settings.", "gui_tor_connection_canceled": "OnionShare cannot connect to Tor.\n\nMake sure you're connected to the internet, then re-open OnionShare to configure the Tor connection.", + "gui_tor_connection_lost": "Disconnected from Tor.", "gui_server_started_after_timeout": "The server started after your chosen auto-timeout.\nPlease start a new share.", "gui_server_timeout_expired": "The chosen timeout has already expired.\nPlease update the timeout and then you may start sharing.", "share_via_onionshare": "Share via OnionShare" From 0834580f02f5a0f9ae01505c5cf73ed1001ec5ac Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sun, 24 Dec 2017 14:07:20 +1100 Subject: [PATCH 11/19] Disable the 'Start Sharing' button if the connection to Tor has been lost. Re-enable it if we've subsequently reconnected to Tor via Settings dialog --- onionshare_gui/onionshare_gui.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 7c44b769..4fbebf9c 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -225,7 +225,11 @@ class OnionShareGui(QtWidgets.QMainWindow): if self.onion.is_authenticated(): if not self.timer.isActive(): self.timer.start() - self.status_bar.clearMessage() + # If there were some files listed for sharing, we should be ok to + # re-enable the 'Start Sharing' button now. + if self.server_status.file_selection.get_num_files() > 0: + self.server_status.server_button.setEnabled(True) + self.status_bar.clearMessage() d = SettingsDialog(self.onion, self.qtapp, self.config) d.settings_saved.connect(reload_settings) @@ -402,6 +406,7 @@ class OnionShareGui(QtWidgets.QMainWindow): self.timer.stop() if self.server_status.status != self.server_status.STATUS_STOPPED: self.server_status.stop_server() + self.server_status.server_button.setEnabled(False) self.status_bar.showMessage(strings._('gui_tor_connection_lost', True)) # scroll to the bottom of the dl progress bar log pane From 47e0ef4f83a23ccb8ab8793c1c572c6dd36b1c4f Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 27 Dec 2017 09:29:45 +1100 Subject: [PATCH 12/19] Add systray notification when Tor connection is lost, thanks @Baccount --- onionshare_gui/onionshare_gui.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 4fbebf9c..b720a04b 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -408,6 +408,8 @@ class OnionShareGui(QtWidgets.QMainWindow): self.server_status.stop_server() self.server_status.server_button.setEnabled(False) self.status_bar.showMessage(strings._('gui_tor_connection_lost', True)) + if self.systemTray.supportsMessages() and self.settings.get('systray_notifications'): + self.systemTray.showMessage(strings._('gui_tor_connection_lost', True), strings._('gui_tor_connection_error_settings', True)) # scroll to the bottom of the dl progress bar log pane # if a new download has been added From 4d0ef50face4b76e0ebd07a8cfc2e8e1ba02d6b0 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 27 Dec 2017 11:37:06 +1100 Subject: [PATCH 13/19] Emit the files_updated signal when deleting files. This will ensure that the share button gets disabled when there are no files in the list --- onionshare_gui/file_selection.py | 1 + 1 file changed, 1 insertion(+) diff --git a/onionshare_gui/file_selection.py b/onionshare_gui/file_selection.py index 54321370..da03d24d 100644 --- a/onionshare_gui/file_selection.py +++ b/onionshare_gui/file_selection.py @@ -229,6 +229,7 @@ class FileSelection(QtWidgets.QVBoxLayout): itemrow = self.file_list.row(item) self.file_list.filenames.pop(itemrow) self.file_list.takeItem(itemrow) + self.file_list.files_updated.emit() self.update() def server_started(self): From f96ff3328f86143a79290da65de3c9012085e3ce Mon Sep 17 00:00:00 2001 From: Baccount Date: Tue, 26 Dec 2017 22:53:44 -0800 Subject: [PATCH 14/19] Update onion.py --- onionshare/onion.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/onionshare/onion.py b/onionshare/onion.py index 2f79719b..160dbfcb 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -254,8 +254,8 @@ class Onion(object): break time.sleep(0.2) - # Timeout after 45 seconds - if time.time() - start_ts > 45: + # Timeout after 90 seconds + if time.time() - start_ts > 90: print("") self.tor_proc.terminate() raise BundledTorTimeout(strings._('settings_error_bundled_tor_timeout')) From 40eeb2cfd3255a1c06b6988df807b2643790cb06 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 27 Dec 2017 20:08:38 +1100 Subject: [PATCH 15/19] #520 trigger browser action properly in QLabel hyperlink --- onionshare_gui/settings_dialog.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index df806a06..b9534511 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -72,6 +72,8 @@ class SettingsDialog(QtWidgets.QDialog): # Stealth stealth_details = QtWidgets.QLabel(strings._("gui_settings_stealth_option_details", True)) stealth_details.setWordWrap(True) + stealth_details.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction) + stealth_details.setOpenExternalLinks(True) self.stealth_checkbox = QtWidgets.QCheckBox() self.stealth_checkbox.setCheckState(QtCore.Qt.Unchecked) self.stealth_checkbox.setText(strings._("gui_settings_stealth_option", True)) From ffa7f97905b61d88ca29c6c884289266430b83d0 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Tue, 2 Jan 2018 14:31:50 +1100 Subject: [PATCH 16/19] catch error in start_onion_service in case we somehow failed to parse a service_id in Stem controller response --- onionshare/onion.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/onionshare/onion.py b/onionshare/onion.py index 2f79719b..e577c769 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -413,7 +413,10 @@ class Onion(object): auth_cookie = res.content()[2][2].split('=')[1].split(':')[1] self.auth_string = 'HidServAuth {} {}'.format(onion_host, auth_cookie) - return onion_host + if onion_host is not None: + return onion_host + else: + raise TorErrorProtocolError(strings._('error_tor_protocol_error')) def cleanup(self): """ From ac29bdb5df0c7459748954e9bb496204bfcb4b58 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sat, 13 Jan 2018 19:18:33 -0800 Subject: [PATCH 17/19] Better way to get the onion service_id --- onionshare/onion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onionshare/onion.py b/onionshare/onion.py index 2c2d86bb..02f062fb 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -406,7 +406,7 @@ class Onion(object): except ProtocolError: raise TorErrorProtocolError(strings._('error_tor_protocol_error')) - self.service_id = res.content()[0][2].split('=')[1] + self.service_id = res.service_id onion_host = self.service_id + '.onion' if self.stealth: From 2dd2052c6931d44afc5dad2786c51175fe127e72 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sat, 13 Jan 2018 22:42:27 -0800 Subject: [PATCH 18/19] Don't start the check_for_requests timer until after connected to Tor, and remove OnionShareGui.tor_con and TorConnectionDialog.t as class variables, making them local variables instead --- onionshare_gui/onionshare_gui.py | 35 ++++++++++++------------- onionshare_gui/tor_connection_dialog.py | 14 +++++----- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index f1feadd7..c6e2dcc2 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -130,11 +130,6 @@ class OnionShareGui(QtWidgets.QMainWindow): self.setCentralWidget(central_widget) self.show() - # Check for requests frequently - self.timer = QtCore.QTimer() - self.timer.timeout.connect(self.check_for_requests) - self.timer.start(500) - # Always start with focus on file selection self.file_selection.setFocus() @@ -142,10 +137,15 @@ class OnionShareGui(QtWidgets.QMainWindow): self.set_server_active(False) # Start the "Connecting to Tor" dialog, which calls onion.connect() - self.tor_con = TorConnectionDialog(self.qtapp, self.settings, self.onion) - self.tor_con.canceled.connect(self._tor_connection_canceled) - self.tor_con.open_settings.connect(self._tor_connection_open_settings) - self.tor_con.start() + tor_con = TorConnectionDialog(self.qtapp, self.settings, self.onion) + tor_con.canceled.connect(self._tor_connection_canceled) + tor_con.open_settings.connect(self._tor_connection_open_settings) + tor_con.start() + + # Check for requests frequently + self.timer = QtCore.QTimer() + self.timer.timeout.connect(self.check_for_requests) + self.timer.start(500) # After connecting to Tor, check for updates self.check_for_updates() @@ -410,15 +410,14 @@ class OnionShareGui(QtWidgets.QMainWindow): self.update() # Have we lost connection to Tor somehow? - if self.tor_con.t.isFinished(): - if not self.onion.is_authenticated(): - self.timer.stop() - if self.server_status.status != self.server_status.STATUS_STOPPED: - self.server_status.stop_server() - self.server_status.server_button.setEnabled(False) - self.status_bar.showMessage(strings._('gui_tor_connection_lost', True)) - if self.systemTray.supportsMessages() and self.settings.get('systray_notifications'): - self.systemTray.showMessage(strings._('gui_tor_connection_lost', True), strings._('gui_tor_connection_error_settings', True)) + if not self.onion.is_authenticated(): + self.timer.stop() + if self.server_status.status != self.server_status.STATUS_STOPPED: + self.server_status.stop_server() + self.server_status.server_button.setEnabled(False) + self.status_bar.showMessage(strings._('gui_tor_connection_lost', True)) + if self.systemTray.supportsMessages() and self.settings.get('systray_notifications'): + self.systemTray.showMessage(strings._('gui_tor_connection_lost', True), strings._('gui_tor_connection_error_settings', True)) # scroll to the bottom of the dl progress bar log pane # if a new download has been added diff --git a/onionshare_gui/tor_connection_dialog.py b/onionshare_gui/tor_connection_dialog.py index ab797171..dc472725 100644 --- a/onionshare_gui/tor_connection_dialog.py +++ b/onionshare_gui/tor_connection_dialog.py @@ -57,14 +57,14 @@ class TorConnectionDialog(QtWidgets.QProgressDialog): def start(self): common.log('TorConnectionDialog', 'start') - self.t = TorConnectionThread(self, self.settings, self.onion) - self.t.tor_status_update.connect(self._tor_status_update) - self.t.connected_to_tor.connect(self._connected_to_tor) - self.t.canceled_connecting_to_tor.connect(self._canceled_connecting_to_tor) - self.t.error_connecting_to_tor.connect(self._error_connecting_to_tor) - self.t.start() + t = TorConnectionThread(self, self.settings, self.onion) + t.tor_status_update.connect(self._tor_status_update) + t.connected_to_tor.connect(self._connected_to_tor) + t.canceled_connecting_to_tor.connect(self._canceled_connecting_to_tor) + t.error_connecting_to_tor.connect(self._error_connecting_to_tor) + t.start() - # The main thread needs to remain active, and checkign for Qt events, + # The main thread needs to remain active, and checking for Qt events, # until the thread is finished. Otherwise it won't be able to handle # accepting signals. self.active = True From a34cae0b1768652b314b9895cc76ff5b34f3c849 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sat, 13 Jan 2018 22:46:57 -0800 Subject: [PATCH 19/19] Create the timer before the TorConnectionDialog dialog, but start it after. This way if you cancel the dialog, then click save in the settings, OnionShareGui.timer will already exist, even though though TorConnectionDialog hasn't closed yet --- onionshare_gui/onionshare_gui.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index c6e2dcc2..c056a32d 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -136,15 +136,17 @@ class OnionShareGui(QtWidgets.QMainWindow): # The server isn't active yet self.set_server_active(False) + # Create the timer + self.timer = QtCore.QTimer() + self.timer.timeout.connect(self.check_for_requests) + # Start the "Connecting to Tor" dialog, which calls onion.connect() tor_con = TorConnectionDialog(self.qtapp, self.settings, self.onion) tor_con.canceled.connect(self._tor_connection_canceled) tor_con.open_settings.connect(self._tor_connection_open_settings) tor_con.start() - # Check for requests frequently - self.timer = QtCore.QTimer() - self.timer.timeout.connect(self.check_for_requests) + # Start the timer self.timer.start(500) # After connecting to Tor, check for updates @@ -224,7 +226,7 @@ class OnionShareGui(QtWidgets.QMainWindow): # connection. If so, restart the timer. if self.onion.is_authenticated(): if not self.timer.isActive(): - self.timer.start() + self.timer.start(500) # If there were some files listed for sharing, we should be ok to # re-enable the 'Start Sharing' button now. if self.server_status.file_selection.get_num_files() > 0: