When Tor settings change, make sure the tabs know

This commit is contained in:
Micah Lee 2019-11-28 14:57:01 -08:00
parent cb8e836079
commit eefa43d923
3 changed files with 27 additions and 36 deletions

View File

@ -144,6 +144,7 @@ class MainWindow(QtWidgets.QMainWindow):
tor_con.open_settings.connect(self.tor_connection_open_settings)
if not self.common.gui.local_only:
tor_con.start()
self.settings_have_changed()
# After connecting to Tor, check for updates
self.check_for_updates()
@ -223,43 +224,20 @@ class MainWindow(QtWidgets.QMainWindow):
Open the SettingsDialog.
"""
self.common.log("MainWindow", "open_settings")
d = SettingsDialog(self.common)
d.settings_saved.connect(self.settings_have_changed)
d.exec_()
def reload_settings():
self.common.log(
"OnionShareGui", "open_settings", "settings have changed, reloading"
)
self.common.settings.load()
def settings_have_changed(self):
self.common.log("OnionShareGui", "settings_have_changed")
# 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.common.gui.local_only:
if self.common.gui.onion.is_authenticated():
if not self.timer.isActive():
self.timer.start(500)
self.share_mode.on_reload_settings()
self.receive_mode.on_reload_settings()
self.website_mode.on_reload_settings()
self.status_bar.clearMessage()
# If we switched off the auto-stop timer setting, ensure the widget is hidden.
if not self.common.settings.get("autostop_timer"):
self.share_mode.server_status.autostop_timer_container.hide()
self.receive_mode.server_status.autostop_timer_container.hide()
self.website_mode.server_status.autostop_timer_container.hide()
# If we switched off the auto-start timer setting, ensure the widget is hidden.
if not self.common.settings.get("autostart_timer"):
self.share_mode.server_status.autostart_timer_datetime = None
self.receive_mode.server_status.autostart_timer_datetime = None
self.website_mode.server_status.autostart_timer_datetime = None
self.share_mode.server_status.autostart_timer_container.hide()
self.receive_mode.server_status.autostart_timer_container.hide()
self.website_mode.server_status.autostart_timer_container.hide()
d = SettingsDialog(self.common)
# d.settings_saved.connect(reload_settings)
# TODO: move the reload_settings logic into tabs
d.exec_()
# Tell each tab that settings have changed
for index in range(self.tabs.count()):
tab = self.tabs.widget(index)
tab.settings_have_changed()
def check_for_updates(self):
"""

View File

@ -527,6 +527,19 @@ class Tab(QtWidgets.QWidget):
else:
return None
def settings_have_changed(self):
# Global settings have changed
self.common.log("Tab", "settings_have_changed")
# 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.common.gui.local_only:
if self.common.gui.onion.is_authenticated():
if not self.timer.isActive():
self.timer.start(500)
self.get_mode().on_reload_settings()
self.get_mode().primary_action.show()
def close_tab(self):
self.common.log("Tab", "close_tab")
if self.mode is None:

View File

@ -88,7 +88,7 @@
"settings_error_unreadable_cookie_file": "Connected to the Tor controller, but password may be wrong, or your user is not permitted to read the cookie file.",
"settings_error_bundled_tor_not_supported": "Using the Tor version that comes with OnionShare does not work in developer mode on Windows or macOS.",
"settings_error_bundled_tor_timeout": "Taking too long to connect to Tor. Maybe you aren't connected to the Internet, or have an inaccurate system clock?",
"settings_error_bundled_tor_broken": "OnionShare could not connect to Tor in the background:\n{}",
"settings_error_bundled_tor_broken": "OnionShare could not connect to Tor:\n{}",
"settings_test_success": "Connected to the Tor controller.\n\nTor version: {}\nSupports ephemeral onion services: {}.\nSupports client authentication: {}.\nSupports next-gen .onion addresses: {}.",
"error_tor_protocol_error": "There was an error with Tor: {}",
"error_tor_protocol_error_unknown": "There was an unknown error with Tor",