From eefa43d923ac2df1a34ba1d48204a9ff27576759 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 28 Nov 2019 14:57:01 -0800 Subject: [PATCH] When Tor settings change, make sure the tabs know --- onionshare_gui/main_window.py | 48 ++++++++++------------------------- onionshare_gui/tab/tab.py | 13 ++++++++++ share/locale/en.json | 2 +- 3 files changed, 27 insertions(+), 36 deletions(-) diff --git a/onionshare_gui/main_window.py b/onionshare_gui/main_window.py index 46c0c962..14328b26 100644 --- a/onionshare_gui/main_window.py +++ b/onionshare_gui/main_window.py @@ -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,44 +224,21 @@ class MainWindow(QtWidgets.QMainWindow): Open the SettingsDialog. """ self.common.log("MainWindow", "open_settings") - - def reload_settings(): - self.common.log( - "OnionShareGui", "open_settings", "settings have changed, reloading" - ) - self.common.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.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.settings_saved.connect(self.settings_have_changed) d.exec_() + def settings_have_changed(self): + self.common.log("OnionShareGui", "settings_have_changed") + + if self.common.gui.onion.is_authenticated(): + self.status_bar.clearMessage() + + # 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): """ Check for updates in a new thread, if enabled. diff --git a/onionshare_gui/tab/tab.py b/onionshare_gui/tab/tab.py index 74c42cbd..db10ba97 100644 --- a/onionshare_gui/tab/tab.py +++ b/onionshare_gui/tab/tab.py @@ -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: diff --git a/share/locale/en.json b/share/locale/en.json index 5425a336..cca7d92e 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -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",