diff --git a/onionshare/common.py b/onionshare/common.py index 08c67899..b74534ff 100644 --- a/onionshare/common.py +++ b/onionshare/common.py @@ -28,6 +28,7 @@ import sys import tempfile import threading import time +import shutil from .settings import Settings @@ -100,7 +101,9 @@ class Common: # Look for resources relative to the binary, so if the binary is /usr/bin/onionshare-gui and # the resource dir is /usr/share/onionshare, then the resource dir relative to the binary dir # is ../share/onionshare - prefix = os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), "share/onionshare") + prefix = os.path.join( + os.path.dirname(os.path.dirname(sys.argv[0])), "share/onionshare" + ) elif getattr(sys, "frozen", False): # Check if app is "frozen" @@ -114,11 +117,11 @@ class Common: def get_tor_paths(self): if self.platform == "Linux": - prefix = os.path.dirname(os.path.dirname(sys.argv[0])) - tor_path = os.path.join(prefix, "bin/tor") + tor_path = shutil.which("tor") + obfs4proxy_file_path = shutil.which("obfs4proxy") + prefix = os.path.dirname(os.path.dirname(tor_path)) tor_geo_ip_file_path = os.path.join(prefix, "share/tor/geoip") tor_geo_ipv6_file_path = os.path.join(prefix, "share/tor/geoip6") - obfs4proxy_file_path = os.path.join(prefix, "bin/obfs4proxy") elif self.platform == "Windows": base_path = os.path.join( os.path.dirname(os.path.dirname(self.get_resource_path(""))), "tor" diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index 45eef270..f8cb4204 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -142,7 +142,9 @@ class SettingsDialog(QtWidgets.QDialog): self.tor_geo_ipv6_file_path, self.obfs4proxy_file_path, ) = self.common.get_tor_paths() - if not os.path.isfile(self.obfs4proxy_file_path): + if not self.obfs4proxy_file_path or not os.path.isfile( + self.obfs4proxy_file_path + ): self.tor_bridges_use_obfs4_radio = QtWidgets.QRadioButton( strings._("gui_settings_tor_bridges_obfs4_radio_option_no_obfs4proxy") ) @@ -163,7 +165,9 @@ class SettingsDialog(QtWidgets.QDialog): self.tor_geo_ipv6_file_path, self.obfs4proxy_file_path, ) = self.common.get_tor_paths() - if not os.path.isfile(self.obfs4proxy_file_path): + if not self.obfs4proxy_file_path or not os.path.isfile( + self.obfs4proxy_file_path + ): self.tor_bridges_use_meek_lite_azure_radio = QtWidgets.QRadioButton( strings._( "gui_settings_tor_bridges_meek_lite_azure_radio_option_no_obfs4proxy" @@ -662,8 +666,7 @@ class SettingsDialog(QtWidgets.QDialog): onion = Onion(self.common, use_tmp_dir=True) onion.connect( - custom_settings=settings, - tor_status_update_func=tor_status_update_func, + custom_settings=settings, tor_status_update_func=tor_status_update_func, ) # If an exception hasn't been raised yet, the Tor settings work @@ -750,9 +753,7 @@ class SettingsDialog(QtWidgets.QDialog): ) close_forced_update_thread() - forced_update_thread = UpdateThread( - self.common, self.onion, force=True - ) + forced_update_thread = UpdateThread(self.common, self.onion, force=True) forced_update_thread.update_available.connect(update_available) forced_update_thread.update_not_available.connect(update_not_available) forced_update_thread.update_error.connect(update_error) @@ -850,7 +851,10 @@ class SettingsDialog(QtWidgets.QDialog): f"Onion done rebooting, connected to Tor: {self.common.gui.onion.connected_to_tor}", ) - if self.common.gui.onion.is_authenticated() and not tor_con.wasCanceled(): + if ( + self.common.gui.onion.is_authenticated() + and not tor_con.wasCanceled() + ): self.settings_saved.emit() self.close() @@ -866,7 +870,10 @@ class SettingsDialog(QtWidgets.QDialog): Cancel button clicked. """ self.common.log("SettingsDialog", "cancel_clicked") - if not self.common.gui.local_only and not self.common.gui.onion.is_authenticated(): + if ( + not self.common.gui.local_only + and not self.common.gui.onion.is_authenticated() + ): Alert( self.common, strings._("gui_tor_connection_canceled"), diff --git a/onionshare_gui/tab_widget.py b/onionshare_gui/tab_widget.py index 7d8283fc..e14d1f27 100644 --- a/onionshare_gui/tab_widget.py +++ b/onionshare_gui/tab_widget.py @@ -78,8 +78,9 @@ class TabWidget(QtWidgets.QTabWidget): def cleanup(self): # Stop the event thread - self.event_handler_t.stop() - self.event_handler_t.join() + self.event_handler_t.should_quit = True + self.event_handler_t.quit() + self.event_handler_t.wait(50) # Clean up each tab for index in range(self.count()): diff --git a/onionshare_gui/threads.py b/onionshare_gui/threads.py index ba490868..29554039 100644 --- a/onionshare_gui/threads.py +++ b/onionshare_gui/threads.py @@ -185,6 +185,7 @@ class EventHandlerThread(QtCore.QThread): super(EventHandlerThread, self).__init__() self.common = common self.common.log("EventHandlerThread", "__init__") + self.should_quit = False def run(self): self.common.log("EventHandlerThread", "run") @@ -246,4 +247,6 @@ class EventHandlerThread(QtCore.QThread): except: pass + if self.should_quit: + break time.sleep(0.2) diff --git a/onionshare_gui/tor_connection_dialog.py b/onionshare_gui/tor_connection_dialog.py index 37c0ebc3..9c17e65c 100644 --- a/onionshare_gui/tor_connection_dialog.py +++ b/onionshare_gui/tor_connection_dialog.py @@ -157,10 +157,8 @@ class TorConnectionThread(QtCore.QThread): self.canceled_connecting_to_tor.emit() except Exception as e: - self.common.log( - "TorConnectionThread", "run", f"caught exception: {e.args[0]}" - ) - self.error_connecting_to_tor.emit(str(e.args[0])) + self.common.log("TorConnectionThread", "run", f"caught exception: {e}") + self.error_connecting_to_tor.emit(str(e)) def _tor_status_update(self, progress, summary): self.tor_status_update.emit(progress, summary)