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": {},
"persistent_tabs": [],
"theme": 0,
"censorship_circumvention": False,
"auto_connect": False,
}
for key in settings_obj._settings:
# 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")
if self.auto_connect_enabled:
self.first_launch_widget.enable_autoconnect_checkbox.setCheckState(
QtCore.Qt.Checked
)
self.first_launch_widget.enable_autoconnect_checkbox.setChecked(True)
self.first_launch_widget_connect_clicked()
def toggle_auto_connect(self):
@ -136,7 +134,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 first_launch_widget_connect_clicked(self):
"""
@ -145,11 +143,8 @@ class AutoConnectTab(QtWidgets.QWidget):
self.common.log("AutoConnectTab", "first_launch_widget_connect_clicked")
self.first_launch_widget.hide_buttons()
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 use_bridge_connect_clicked(self):
"""
@ -219,6 +214,13 @@ class AutoConnectTab(QtWidgets.QWidget):
self.first_launch_widget.hide()
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):
"""

View file

@ -24,6 +24,7 @@ from PySide2 import QtCore, QtWidgets, QtGui
from . import strings
from .widgets import Alert
from .connection_tab import AutoConnectTab
from .update_checker import UpdateThread
from .tab_widget import TabWidget
from .settings_tab import SettingsTab
@ -147,6 +148,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()
@ -238,7 +242,12 @@ class MainWindow(QtWidgets.QMainWindow):
Open the TorSettingsTab
"""
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):
"""

View file

@ -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()
@ -222,6 +222,8 @@ class TabWidget(QtWidgets.QTabWidget):
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"))
@ -243,7 +245,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
@ -253,7 +255,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)
@ -383,6 +385,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])

View file

@ -42,7 +42,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
@ -53,6 +53,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
@ -709,7 +710,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"