Merge branch 'censorship' into 1422_autodetect_location

This commit is contained in:
Micah Lee 2021-12-12 10:27:01 -08:00
commit 8fe54afe13
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
5 changed files with 34 additions and 17 deletions

View file

@ -37,7 +37,7 @@ class TestSettings:
"bridges_builtin": {}, "bridges_builtin": {},
"persistent_tabs": [], "persistent_tabs": [],
"theme": 0, "theme": 0,
"censorship_circumvention": False, "auto_connect": False,
} }
for key in settings_obj._settings: for key in settings_obj._settings:
# Skip locale, it will not always default to the same thing # Skip locale, it will not always default to the same thing

View file

@ -119,9 +119,7 @@ class AutoConnectTab(QtWidgets.QWidget):
""" """
self.common.log("AutoConnectTab", "autoconnect_checking") self.common.log("AutoConnectTab", "autoconnect_checking")
if self.auto_connect_enabled: if self.auto_connect_enabled:
self.first_launch_widget.enable_autoconnect_checkbox.setCheckState( self.first_launch_widget.enable_autoconnect_checkbox.setChecked(True)
QtCore.Qt.Checked
)
self.first_launch_widget_connect_clicked() self.first_launch_widget_connect_clicked()
def toggle_auto_connect(self): def toggle_auto_connect(self):
@ -136,7 +134,7 @@ class AutoConnectTab(QtWidgets.QWidget):
self.curr_settings.save() self.curr_settings.save()
def open_tor_settings(self): def open_tor_settings(self):
self.parent.open_tor_settings_tab() self.parent.open_tor_settings_tab(from_autoconnect=True)
def first_launch_widget_connect_clicked(self): def first_launch_widget_connect_clicked(self):
""" """
@ -145,11 +143,8 @@ class AutoConnectTab(QtWidgets.QWidget):
self.common.log("AutoConnectTab", "first_launch_widget_connect_clicked") self.common.log("AutoConnectTab", "first_launch_widget_connect_clicked")
self.first_launch_widget.hide_buttons() self.first_launch_widget.hide_buttons()
if not self.common.gui.local_only: self.tor_con.show()
self.tor_con.show() self.tor_con.start(self.curr_settings)
self.tor_con.start(self.curr_settings)
else:
self.close_this_tab.emit()
def use_bridge_connect_clicked(self): def use_bridge_connect_clicked(self):
""" """
@ -219,6 +214,13 @@ class AutoConnectTab(QtWidgets.QWidget):
self.first_launch_widget.hide() self.first_launch_widget.hide()
self.use_bridge_widget.show() self.use_bridge_widget.show()
def reload_settings(self):
self.curr_settings.load()
self.auto_connect_enabled = self.curr_settings.get("auto_connect")
self.first_launch_widget.enable_autoconnect_checkbox.setChecked(
self.auto_connect_enabled
)
class AutoConnectFirstLaunchWidget(QtWidgets.QWidget): class AutoConnectFirstLaunchWidget(QtWidgets.QWidget):
""" """

View file

@ -24,6 +24,7 @@ from PySide2 import QtCore, QtWidgets, QtGui
from . import strings from . import strings
from .widgets import Alert from .widgets import Alert
from .connection_tab import AutoConnectTab
from .update_checker import UpdateThread from .update_checker import UpdateThread
from .tab_widget import TabWidget from .tab_widget import TabWidget
from .settings_tab import SettingsTab from .settings_tab import SettingsTab
@ -147,6 +148,9 @@ class MainWindow(QtWidgets.QMainWindow):
if len(self.common.settings.get("persistent_tabs")) > 0: if len(self.common.settings.get("persistent_tabs")) > 0:
for mode_settings_id in self.common.settings.get("persistent_tabs"): for mode_settings_id in self.common.settings.get("persistent_tabs"):
self.tabs.load_tab(mode_settings_id) 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: else:
# Start with opening the first tab # Start with opening the first tab
self.tabs.new_tab_clicked() self.tabs.new_tab_clicked()
@ -238,7 +242,12 @@ class MainWindow(QtWidgets.QMainWindow):
Open the TorSettingsTab Open the TorSettingsTab
""" """
self.common.log("MainWindow", "open_tor_settings") self.common.log("MainWindow", "open_tor_settings")
self.tabs.open_tor_settings_tab() 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): def open_settings(self):
""" """

View file

@ -162,9 +162,9 @@ class TabWidget(QtWidgets.QTabWidget):
pass pass
def new_tab_clicked(self): 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 # 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() self.add_tab()
else: else:
self.open_connection_tab() self.open_connection_tab()
@ -222,6 +222,8 @@ class TabWidget(QtWidgets.QTabWidget):
self.common, self.current_tab_id, self.status_bar, parent=self self.common, self.current_tab_id, self.status_bar, parent=self
) )
connection_tab.close_this_tab.connect(self.close_connection_tab) 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.tabs[self.current_tab_id] = connection_tab
self.current_tab_id += 1 self.current_tab_id += 1
index = self.addTab(connection_tab, strings._("gui_autoconnect_start")) index = self.addTab(connection_tab, strings._("gui_autoconnect_start"))
@ -243,7 +245,7 @@ class TabWidget(QtWidgets.QTabWidget):
index = self.addTab(settings_tab, strings._("gui_settings_window_title")) index = self.addTab(settings_tab, strings._("gui_settings_window_title"))
self.setCurrentIndex(index) 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") self.common.log("TabWidget", "open_tor_settings_tab")
# See if a settings tab is already open, and if so switch to it # See if a settings tab is already open, and if so switch to it
@ -253,7 +255,7 @@ class TabWidget(QtWidgets.QTabWidget):
return return
self.tor_settings_tab = TorSettingsTab( 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.close_this_tab.connect(self.close_tor_settings_tab)
self.tor_settings_tab.tor_is_connected.connect(self.tor_is_connected) self.tor_settings_tab.tor_is_connected.connect(self.tor_is_connected)
@ -383,6 +385,9 @@ class TabWidget(QtWidgets.QTabWidget):
def close_tor_settings_tab(self): def close_tor_settings_tab(self):
self.common.log("TabWidget", "close_tor_settings_tab") 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: for tab_id in self.tabs:
if type(self.tabs[tab_id]) is TorSettingsTab: if type(self.tabs[tab_id]) is TorSettingsTab:
index = self.indexOf(self.tabs[tab_id]) index = self.indexOf(self.tabs[tab_id])

View file

@ -42,7 +42,7 @@ class TorSettingsTab(QtWidgets.QWidget):
tor_is_connected = QtCore.Signal() tor_is_connected = QtCore.Signal()
tor_is_disconnected = 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__() super(TorSettingsTab, self).__init__()
self.common = common self.common = common
@ -53,6 +53,7 @@ class TorSettingsTab(QtWidgets.QWidget):
self.system = platform.system() self.system = platform.system()
self.tab_id = tab_id self.tab_id = tab_id
self.from_autoconnect = from_autoconnect
# Connection type: either automatic, control port, or socket file # Connection type: either automatic, control port, or socket file
@ -709,7 +710,7 @@ class TorSettingsTab(QtWidgets.QWidget):
# If Tor isn't connected, or if Tor settings have changed, Reinitialize # If Tor isn't connected, or if Tor settings have changed, Reinitialize
# the Onion object # the Onion object
reboot_onion = False 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(): if self.common.gui.onion.is_authenticated():
self.common.log( self.common.log(
"TorSettingsTab", "save_clicked", "Connected to Tor" "TorSettingsTab", "save_clicked", "Connected to Tor"