diff --git a/desktop/src/onionshare/connection_tab.py b/desktop/src/onionshare/connection_tab.py index a8c8f8ec..096c503f 100644 --- a/desktop/src/onionshare/connection_tab.py +++ b/desktop/src/onionshare/connection_tab.py @@ -37,6 +37,7 @@ from .tor_connection import TorConnectionWidget from .update_checker import UpdateThread from .widgets import Alert + class AutoConnectTab(QtWidgets.QWidget): """ Initial Tab that appears in the very beginning to ask user if @@ -81,7 +82,9 @@ class AutoConnectTab(QtWidgets.QWidget): self.image.setLayout(image_layout) # First launch widget - self.first_launch_widget = AutoConnectFirstLaunchWidget(self.common, self.curr_settings) + self.first_launch_widget = AutoConnectFirstLaunchWidget( + self.common, self.curr_settings + ) self.first_launch_widget.toggle_auto_connect.connect(self.toggle_auto_connect) self.first_launch_widget.connect_clicked.connect( self.first_launch_widget_connect_clicked @@ -168,7 +171,6 @@ class AutoConnectTab(QtWidgets.QWidget): def _got_no_bridges(self): self.use_bridge_widget.progress.hide() self.use_bridge_widget.progress_label.hide() - self.tor_con.fail.emit() Alert( self.common, @@ -214,7 +216,10 @@ class AutoConnectTab(QtWidgets.QWidget): self.common, self.common.gui.meek ) self._censorship_progress_update( - 75, strings._("gui_autoconnect_circumventing_censorship_requesting_bridges") + 75, + strings._( + "gui_autoconnect_circumventing_censorship_requesting_bridges" + ), ) bridge_settings = self.censorship_circumvention.request_settings( country=country @@ -225,12 +230,14 @@ class AutoConnectTab(QtWidgets.QWidget): self.curr_settings, bridge_settings ): self._censorship_progress_update( - 100, strings._("gui_autoconnect_circumventing_censorship_got_bridges") + 100, + strings._("gui_autoconnect_circumventing_censorship_got_bridges"), ) self._got_bridges() else: self._censorship_progress_update( - 100, strings._("gui_autoconnect_circumventing_censorship_no_bridges") + 100, + strings._("gui_autoconnect_circumventing_censorship_no_bridges"), ) self._got_no_bridges() except ( @@ -281,7 +288,7 @@ class AutoConnectTab(QtWidgets.QWidget): # Close the tab self.close_this_tab.emit() - def tor_con_fail(self): + def tor_con_fail(self, msg): """ Finished testing tor connection. """ @@ -299,6 +306,9 @@ class AutoConnectTab(QtWidgets.QWidget): self.first_launch_widget.enable_autoconnect_checkbox.setChecked( self.auto_connect_enabled ) + self.use_bridge_widget.hide() + self.first_launch_widget.show_buttons() + self.first_launch_widget.show() class AutoConnectFirstLaunchWidget(QtWidgets.QWidget): @@ -323,9 +333,7 @@ class AutoConnectFirstLaunchWidget(QtWidgets.QWidget): self.enable_autoconnect_checkbox = ToggleCheckbox( strings._("gui_enable_autoconnect_checkbox") ) - self.enable_autoconnect_checkbox.setChecked( - self.settings.get("auto_connect") - ) + self.enable_autoconnect_checkbox.setChecked(self.settings.get("auto_connect")) self.enable_autoconnect_checkbox.clicked.connect(self._toggle_auto_connect) self.enable_autoconnect_checkbox.setFixedWidth(400) self.enable_autoconnect_checkbox.setStyleSheet( diff --git a/desktop/src/onionshare/resources/locale/en.json b/desktop/src/onionshare/resources/locale/en.json index 65a9c56d..d9ca9578 100644 --- a/desktop/src/onionshare/resources/locale/en.json +++ b/desktop/src/onionshare/resources/locale/en.json @@ -44,7 +44,7 @@ "gui_tor_settings_window_title": "Tor Settings", "gui_autoconnect_description": "OnionShare relies on the Tor Network, run by thousands of volunteers around the world.", "gui_enable_autoconnect_checkbox": "Enable automatically connecting to Tor", - "gui_autoconnect_bridge_description": "Failed connecting to Tor. This could be because your internet is being censored. You might be able to bypass this censorship by using a bridge.", + "gui_autoconnect_bridge_description": "Failed connecting to Tor. This could be because your internet is being censored.
You might be able to bypass this censorship by using a bridge.

Or, you might just need to configure the Tor connection in Network Settings.", "gui_autoconnect_bridge_detect_automatic": "Automatically determine my country from my IP address, to bypass country-specific censorship", "gui_autoconnect_bridge_detect_manual": "Manually select my country instead", "gui_autoconnect_start": "Connect to Tor", diff --git a/desktop/src/onionshare/tab_widget.py b/desktop/src/onionshare/tab_widget.py index cacc658e..b810d607 100644 --- a/desktop/src/onionshare/tab_widget.py +++ b/desktop/src/onionshare/tab_widget.py @@ -255,7 +255,11 @@ class TabWidget(QtWidgets.QTabWidget): return self.tor_settings_tab = TorSettingsTab( - self.common, self.current_tab_id, self.are_tabs_active(), self.status_bar, from_autoconnect + self.common, + self.current_tab_id, + self.are_tabs_active(), + self.status_bar, + from_autoconnect, ) self.tor_settings_tab.close_this_tab.connect(self.close_tor_settings_tab) self.tor_settings_tab.tor_is_connected.connect(self.tor_is_connected) @@ -385,10 +389,30 @@ class TabWidget(QtWidgets.QTabWidget): def close_tor_settings_tab(self): self.common.log("TabWidget", "close_tor_settings_tab") - for tab_id in self.tabs: + for tab_id in list(self.tabs): if type(self.tabs[tab_id]) is AutoConnectTab: - self.tabs[tab_id].reload_settings() - for tab_id in self.tabs: + # If we are being returned to the AutoConnectTab, but + # the user has fixed their Tor settings in the TorSettings + # tab, *and* they have enabled autoconnect, then + # we should close the AutoConnect Tab. + if self.common.gui.onion.is_authenticated(): + self.common.log( + "TabWidget", + "close_tor_settings_tab", + "Tor is connected and we can auto-connect, so closing the tab", + ) + index = self.indexOf(self.tabs[tab_id]) + self.close_tab(index) + else: + self.tabs[tab_id].reload_settings() + self.common.log( + "TabWidget", + "close_tor_settings_tab", + "Reloading settings in case they changed in the TorSettingsTab. Not auto-connecting", + ) + break + # List of indices may have changed due to the above, so we loop over it again as another copy + for tab_id in list(self.tabs): if type(self.tabs[tab_id]) is TorSettingsTab: index = self.indexOf(self.tabs[tab_id]) self.close_tab(index) diff --git a/desktop/src/onionshare/tor_connection.py b/desktop/src/onionshare/tor_connection.py index c69342ae..1f07242d 100644 --- a/desktop/src/onionshare/tor_connection.py +++ b/desktop/src/onionshare/tor_connection.py @@ -48,7 +48,7 @@ class TorConnectionWidget(QtWidgets.QWidget): open_tor_settings = QtCore.Signal() success = QtCore.Signal() - fail = QtCore.Signal() + fail = QtCore.Signal(str) def __init__(self, common, status_bar): super(TorConnectionWidget, self).__init__(None) @@ -112,7 +112,7 @@ class TorConnectionWidget(QtWidgets.QWidget): def cancel_clicked(self): self.was_canceled = True - self.fail.emit() + self.fail.emit("") def wasCanceled(self): return self.was_canceled @@ -141,17 +141,17 @@ class TorConnectionWidget(QtWidgets.QWidget): # Cancel connecting to Tor QtCore.QTimer.singleShot(1, self.cancel_clicked) - def _error_connecting_to_tor(self): + def _error_connecting_to_tor(self, msg): self.common.log("TorConnectionWidget", "_error_connecting_to_tor") self.active = False - self.fail.emit() + self.fail.emit(msg) class TorConnectionThread(QtCore.QThread): tor_status_update = QtCore.Signal(str, str) connected_to_tor = QtCore.Signal() canceled_connecting_to_tor = QtCore.Signal() - error_connecting_to_tor = QtCore.Signal() + error_connecting_to_tor = QtCore.Signal(str) def __init__(self, common, settings, parent): super(TorConnectionThread, self).__init__() @@ -196,7 +196,7 @@ class TorConnectionThread(QtCore.QThread): self.common.log( "TorConnectionThread", "run", f"caught exception: {message}" ) - self.error_connecting_to_tor.emit() + self.error_connecting_to_tor.emit(message) def _tor_status_update(self, progress, summary): self.tor_status_update.emit(progress, summary) diff --git a/desktop/src/onionshare/tor_settings_tab.py b/desktop/src/onionshare/tor_settings_tab.py index 5ffea747..28cafc4c 100644 --- a/desktop/src/onionshare/tor_settings_tab.py +++ b/desktop/src/onionshare/tor_settings_tab.py @@ -691,7 +691,9 @@ class TorSettingsTab(QtWidgets.QWidget): # If Tor isn't connected, or if Tor settings have changed, Reinitialize # the Onion object reboot_onion = False - if not self.common.gui.local_only and not self.from_autoconnect: + if not self.common.gui.local_only and not ( + self.from_autoconnect and not settings.get("auto_connect") + ): if self.common.gui.onion.is_authenticated(): self.common.log( "TorSettingsTab", "save_clicked", "Connected to Tor"