From 5ca7236f0cdec55d7eb4a457affcb4dd78f84d84 Mon Sep 17 00:00:00 2001 From: Saptak S Date: Fri, 3 Dec 2021 20:03:22 +0530 Subject: [PATCH 1/6] Fixes CLI tests --- cli/tests/test_cli_settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/tests/test_cli_settings.py b/cli/tests/test_cli_settings.py index 9513b013..f4222b81 100644 --- a/cli/tests/test_cli_settings.py +++ b/cli/tests/test_cli_settings.py @@ -36,6 +36,7 @@ class TestSettings: "bridges_custom": "", "persistent_tabs": [], "theme": 0, + "auto_connect": False, } for key in settings_obj._settings: # Skip locale, it will not always default to the same thing From 2ad9f8df589f33082fbda47ec49b312db4c93f3e Mon Sep 17 00:00:00 2001 From: Saptak S Date: Thu, 9 Dec 2021 03:15:21 +0530 Subject: [PATCH 2/6] Don't show autoconnect tab if local only --- desktop/src/onionshare/tab_widget.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/desktop/src/onionshare/tab_widget.py b/desktop/src/onionshare/tab_widget.py index 41833635..99770576 100644 --- a/desktop/src/onionshare/tab_widget.py +++ b/desktop/src/onionshare/tab_widget.py @@ -162,9 +162,9 @@ class TabWidget(QtWidgets.QTabWidget): pass def new_tab_clicked(self): - # if already connected to tor, create a new tab + # if already connected to tor or local only, create a new tab # Else open the initial connection tab - if self.common.gui.onion.is_authenticated(): + if self.common.gui.local_only or self.common.gui.onion.is_authenticated(): self.add_tab() else: self.open_connection_tab() From 8d1d395d1100f704d2e03cf57958a004f4dcf82b Mon Sep 17 00:00:00 2001 From: Saptak S Date: Thu, 9 Dec 2021 03:20:54 +0530 Subject: [PATCH 3/6] Dont start tor if torsettingstab opened from autoconnect --- desktop/src/onionshare/connection_tab.py | 9 +++------ desktop/src/onionshare/main_window.py | 5 +++-- desktop/src/onionshare/tab_widget.py | 4 ++-- desktop/src/onionshare/tor_settings_tab.py | 5 +++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/desktop/src/onionshare/connection_tab.py b/desktop/src/onionshare/connection_tab.py index bb5f72a3..13a6b2ad 100644 --- a/desktop/src/onionshare/connection_tab.py +++ b/desktop/src/onionshare/connection_tab.py @@ -152,7 +152,7 @@ class AutoConnectTab(QtWidgets.QWidget): self.curr_settings.save() def open_tor_settings(self): - self.parent.open_tor_settings_tab() + self.parent.open_tor_settings_tab(from_autoconnect=True) def connect_clicked(self): """ @@ -164,11 +164,8 @@ class AutoConnectTab(QtWidgets.QWidget): self.connect_button.hide() self.configure_button.hide() - if not self.common.gui.local_only: - self.tor_con.show() - self.tor_con.start(self.curr_settings) - else: - self.close_this_tab.emit() + self.tor_con.show() + self.tor_con.start(self.curr_settings) def tor_con_success(self): """ diff --git a/desktop/src/onionshare/main_window.py b/desktop/src/onionshare/main_window.py index 54fef40c..80d9b5c1 100644 --- a/desktop/src/onionshare/main_window.py +++ b/desktop/src/onionshare/main_window.py @@ -23,8 +23,8 @@ import time from PySide2 import QtCore, QtWidgets, QtGui from . import strings -from .tor_connection import TorConnectionDialog from .widgets import Alert +from .connection_tab import AutoConnectTab from .update_checker import UpdateThread from .tab_widget import TabWidget from .gui_common import GuiCommon @@ -238,7 +238,8 @@ class MainWindow(QtWidgets.QMainWindow): Open the TorSettingsTab """ self.common.log("MainWindow", "open_tor_settings") - self.tabs.open_tor_settings_tab() + from_autoconnect = type(self.tabs.tabs[0]) is AutoConnectTab + self.tabs.open_tor_settings_tab(from_autoconnect) def open_settings(self): """ diff --git a/desktop/src/onionshare/tab_widget.py b/desktop/src/onionshare/tab_widget.py index 99770576..972792fd 100644 --- a/desktop/src/onionshare/tab_widget.py +++ b/desktop/src/onionshare/tab_widget.py @@ -241,7 +241,7 @@ class TabWidget(QtWidgets.QTabWidget): index = self.addTab(settings_tab, strings._("gui_settings_window_title")) self.setCurrentIndex(index) - def open_tor_settings_tab(self): + def open_tor_settings_tab(self, from_autoconnect=False): self.common.log("TabWidget", "open_tor_settings_tab") # See if a settings tab is already open, and if so switch to it @@ -251,7 +251,7 @@ class TabWidget(QtWidgets.QTabWidget): return self.tor_settings_tab = TorSettingsTab( - self.common, self.current_tab_id, self.are_tabs_active(), self.status_bar + 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) diff --git a/desktop/src/onionshare/tor_settings_tab.py b/desktop/src/onionshare/tor_settings_tab.py index 28778365..1557a4d6 100644 --- a/desktop/src/onionshare/tor_settings_tab.py +++ b/desktop/src/onionshare/tor_settings_tab.py @@ -43,7 +43,7 @@ class TorSettingsTab(QtWidgets.QWidget): tor_is_connected = QtCore.Signal() tor_is_disconnected = QtCore.Signal() - def __init__(self, common, tab_id, are_tabs_active, status_bar): + def __init__(self, common, tab_id, are_tabs_active, status_bar, from_autoconnect=False): super(TorSettingsTab, self).__init__() self.common = common @@ -54,6 +54,7 @@ class TorSettingsTab(QtWidgets.QWidget): self.system = platform.system() self.tab_id = tab_id + self.from_autoconnect = from_autoconnect # Connection type: either automatic, control port, or socket file @@ -692,7 +693,7 @@ 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: + if not self.common.gui.local_only and not self.from_autoconnect: if self.common.gui.onion.is_authenticated(): self.common.log( "TorSettingsTab", "save_clicked", "Connected to Tor" From 7e982f222364610165286a991451a23e93ea2695 Mon Sep 17 00:00:00 2001 From: Saptak S Date: Thu, 9 Dec 2021 03:43:19 +0530 Subject: [PATCH 4/6] Opens connect tab if persistent tab is there --- desktop/src/onionshare/main_window.py | 3 +++ desktop/src/onionshare/tab_widget.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/desktop/src/onionshare/main_window.py b/desktop/src/onionshare/main_window.py index 80d9b5c1..4ad5c14c 100644 --- a/desktop/src/onionshare/main_window.py +++ b/desktop/src/onionshare/main_window.py @@ -147,6 +147,9 @@ class MainWindow(QtWidgets.QMainWindow): if len(self.common.settings.get("persistent_tabs")) > 0: for mode_settings_id in self.common.settings.get("persistent_tabs"): self.tabs.load_tab(mode_settings_id) + # If not connected to tor in beginning, show autoconnect tab + if not self.common.gui.onion.connected_to_tor: + self.tabs.new_tab_clicked() else: # Start with opening the first tab self.tabs.new_tab_clicked() diff --git a/desktop/src/onionshare/tab_widget.py b/desktop/src/onionshare/tab_widget.py index 972792fd..b5df855e 100644 --- a/desktop/src/onionshare/tab_widget.py +++ b/desktop/src/onionshare/tab_widget.py @@ -220,6 +220,8 @@ class TabWidget(QtWidgets.QTabWidget): connection_tab = AutoConnectTab(self.common, self.current_tab_id, self.status_bar, parent=self) connection_tab.close_this_tab.connect(self.close_connection_tab) + connection_tab.tor_is_connected.connect(self.tor_is_connected) + connection_tab.tor_is_disconnected.connect(self.tor_is_disconnected) self.tabs[self.current_tab_id] = connection_tab self.current_tab_id += 1 index = self.addTab(connection_tab, strings._("gui_autoconnect_start")) From df85ea0f60f47c606ee59b8e96ebe94cf3b599aa Mon Sep 17 00:00:00 2001 From: Saptak S Date: Thu, 9 Dec 2021 14:07:25 +0530 Subject: [PATCH 5/6] Fixes from_autoconnect check from MainWindow --- desktop/src/onionshare/main_window.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/desktop/src/onionshare/main_window.py b/desktop/src/onionshare/main_window.py index 4ad5c14c..824aeb6c 100644 --- a/desktop/src/onionshare/main_window.py +++ b/desktop/src/onionshare/main_window.py @@ -241,7 +241,11 @@ class MainWindow(QtWidgets.QMainWindow): Open the TorSettingsTab """ self.common.log("MainWindow", "open_tor_settings") - from_autoconnect = type(self.tabs.tabs[0]) is AutoConnectTab + from_autoconnect = False + for tab_id in self.tabs.tabs: + if type(self.tabs.tabs[tab_id]) is AutoConnectTab: + from_autoconnect = True + break self.tabs.open_tor_settings_tab(from_autoconnect) def open_settings(self): From 24152e8b4d64082217e89a7b6a69b406c5435936 Mon Sep 17 00:00:00 2001 From: Saptak S Date: Thu, 9 Dec 2021 14:38:11 +0530 Subject: [PATCH 6/6] Reload settings in connection tab when tor settings tab closed --- desktop/src/onionshare/connection_tab.py | 7 ++++++- desktop/src/onionshare/tab_widget.py | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/desktop/src/onionshare/connection_tab.py b/desktop/src/onionshare/connection_tab.py index 13a6b2ad..bf9fbfea 100644 --- a/desktop/src/onionshare/connection_tab.py +++ b/desktop/src/onionshare/connection_tab.py @@ -138,7 +138,7 @@ class AutoConnectTab(QtWidgets.QWidget): """ self.common.log("AutoConnectTab", "autoconnect_checking") if self.auto_connect_enabled: - self.enable_autoconnect_checkbox.setCheckState(QtCore.Qt.Checked) + self.enable_autoconnect_checkbox.setChecked(True) self.connect_clicked() def toggle_auto_connect(self): @@ -191,3 +191,8 @@ class AutoConnectTab(QtWidgets.QWidget): self.connect_button.show() self.configure_button.show() self.error_label.setText(msg) + + def reload_settings(self): + self.curr_settings.load() + self.auto_connect_enabled = self.curr_settings.get("auto_connect") + self.enable_autoconnect_checkbox.setChecked(self.auto_connect_enabled) diff --git a/desktop/src/onionshare/tab_widget.py b/desktop/src/onionshare/tab_widget.py index b5df855e..92032f85 100644 --- a/desktop/src/onionshare/tab_widget.py +++ b/desktop/src/onionshare/tab_widget.py @@ -382,6 +382,9 @@ class TabWidget(QtWidgets.QTabWidget): def close_tor_settings_tab(self): self.common.log("TabWidget", "close_tor_settings_tab") + for tab_id in self.tabs: + if type(self.tabs[tab_id]) is AutoConnectTab: + self.tabs[tab_id].reload_settings() for tab_id in self.tabs: if type(self.tabs[tab_id]) is TorSettingsTab: index = self.indexOf(self.tabs[tab_id])