mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Various fixes for handling Tor connection errors, reconnecting scenarios, flow from fixing connection back to AutoConnect or main Mode tabs depending on autoconnect settings
This commit is contained in:
parent
4f40a9b501
commit
47d6f39c06
@ -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(
|
||||
|
@ -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": "<b>Failed connecting to Tor.</b> 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": "<b>Failed connecting to Tor.</b> This could be because your internet is being censored.<br>You might be able to bypass this censorship by using a bridge.<br><br>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",
|
||||
|
@ -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:
|
||||
# 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()
|
||||
for tab_id in self.tabs:
|
||||
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)
|
||||
|
@ -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)
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user