Show progress bar for Censorship Circumvention process

This commit is contained in:
Miguel Jacq 2021-12-14 14:20:45 +11:00
parent d699940615
commit b03823267e
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6
3 changed files with 59 additions and 5 deletions

View File

@ -149,10 +149,12 @@ class AutoConnectTab(QtWidgets.QWidget):
self.tor_con.start(self.curr_settings)
def _got_bridges(self):
self.use_bridge_widget.progress.hide()
self.use_bridge_widget.progress_label.hide()
# Try and connect again
self.common.log(
"AutoConnectTab",
"use_bridge_connect_clicked",
"_got_bridges",
"Got bridges. Trying to reconnect to Tor",
)
self.active = False
@ -160,10 +162,23 @@ class AutoConnectTab(QtWidgets.QWidget):
self.tor_con.start()
def _got_no_bridges(self):
self.use_bridge_widget.progress.hide()
self.use_bridge_widget.progress_label.hide()
self.common.log(
"AutoConnectTab",
"_got_no_bridges",
"Could not get bridges for this country. Raising TorSettingsTab",
)
self.active = False
self.tor_con.fail.emit()
self.open_tor_settings()
def _censorship_progress_update(self, progress, summary):
self.use_bridge_widget.progress.setValue(int(progress))
self.use_bridge_widget.progress_label.setText(
f"<strong>{strings._('gui_autoconnect_circumventing_censorship')}</strong><br>{summary}"
)
def use_bridge_connect_clicked(self):
"""
Connect button in use bridge widget clicked.
@ -181,9 +196,11 @@ class AutoConnectTab(QtWidgets.QWidget):
country = self.use_bridge_widget.country_code
t = CensorshipCircumventionThread(self.common, self.curr_settings, country)
t.progress_update.connect(self._censorship_progress_update)
t.got_bridges.connect(self._got_bridges)
t.got_no_bridges.connect(self._got_no_bridges)
t.start()
self.use_bridge_widget.progress.setValue(0)
self.active = True
while self.active:
time.sleep(0.1)
@ -394,6 +411,16 @@ class AutoConnectUseBridgeWidget(QtWidgets.QWidget):
self.configure_button.setStyleSheet(
common.gui.css["autoconnect_configure_button"]
)
self.progress = QtWidgets.QProgressBar()
self.progress.setRange(0, 100)
self.progress_label = QtWidgets.QLabel(
strings._("gui_autoconnect_circumventing_censorship")
)
self.progress_label.setAlignment(QtCore.Qt.AlignHCenter)
self.progress.hide()
self.progress_label.hide()
cta_layout = QtWidgets.QHBoxLayout()
cta_layout.addWidget(self.connect_button)
cta_layout.addWidget(self.back_button)
@ -410,6 +437,8 @@ class AutoConnectUseBridgeWidget(QtWidgets.QWidget):
layout.addWidget(self.country_image)
layout.addWidget(self.task_label)
layout.addWidget(cta_widget)
layout.addWidget(self.progress)
layout.addWidget(self.progress_label)
self.setLayout(layout)
self._country_changed()
@ -419,11 +448,15 @@ class AutoConnectUseBridgeWidget(QtWidgets.QWidget):
self.connect_button.hide()
self.back_button.hide()
self.configure_button.hide()
self.progress.show()
self.progress_label.show()
def show_buttons(self):
self.connect_button.show()
self.back_button.show()
self.configure_button.show()
self.progress.hide()
self.progress_label.hide()
def _country_changed(self, index=None):
self.country_code = str(self.country_combobox.currentData()).lower()
@ -451,9 +484,6 @@ class AutoConnectUseBridgeWidget(QtWidgets.QWidget):
self.detect_manual_radio.setEnabled(False)
self.country_combobox.setEnabled(False)
self.country_combobox.show()
self.country_image.show()
self.connect_clicked.emit()
def _back_clicked(self):

View File

@ -51,7 +51,12 @@
"gui_autoconnect_configure": "Network Settings",
"gui_autoconnect_bridge_start": "Use a Bridge",
"gui_autoconnect_bridge_back": "Back",
"gui_autoconnect_task_detect_location": "Automatically determining your country...",
"gui_autoconnect_circumventing_censorship": "Trying to resolve connectivity issues",
"gui_autoconnect_circumventing_censorship_starting_circumvention": "Starting censorship circumvention process",
"gui_autoconnect_circumventing_censorship_starting_meek": "Starting Meek for domain-fronting",
"gui_autoconnect_circumventing_censorship_requesting_bridges": "Requesting bridges from the Tor Censorship Circumvention API",
"gui_autoconnect_circumventing_censorship_got_bridges": "Got bridges! Trying to reconnect to Tor",
"gui_autoconnect_circumventing_censorship_no_bridges": "Could not find bridges. Opening manual Tor network settings",
"gui_settings_window_title": "Settings",
"gui_settings_autoupdate_label": "Check for new version",
"gui_settings_autoupdate_option": "Notify me when a new version is available",

View File

@ -273,12 +273,19 @@ class OnionCleanupThread(QtCore.QThread):
class CensorshipCircumventionThread(QtCore.QThread):
progress_update = QtCore.Signal(int, str)
got_bridges = QtCore.Signal()
got_no_bridges = QtCore.Signal()
def __init__(self, common, settings, country):
super(CensorshipCircumventionThread, self).__init__()
self.common = common
self.progress_update.emit(
25,
strings._(
"gui_autoconnect_circumventing_censorship_starting_circumvention"
),
)
self.common.log("CensorshipCircumventionThread", "__init__")
self.settings = settings
self.country = country
@ -286,10 +293,16 @@ class CensorshipCircumventionThread(QtCore.QThread):
def run(self):
self.common.log("CensorshipCircumventionThread", "run")
self.progress_update.emit(
50, strings._("gui_autoconnect_circumventing_censorship_starting_meek")
)
self.common.gui.meek.start()
self.censorship_circumvention = CensorshipCircumvention(
self.common, self.common.gui.meek
)
self.progress_update.emit(
75, strings._("gui_autoconnect_circumventing_censorship_requesting_bridges")
)
bridge_settings = self.censorship_circumvention.request_settings(
country=self.country
)
@ -297,6 +310,12 @@ class CensorshipCircumventionThread(QtCore.QThread):
if bridge_settings and self.censorship_circumvention.save_settings(
self.settings, bridge_settings
):
self.progress_update.emit(
100, strings._("gui_autoconnect_circumventing_censorship_got_bridges")
)
self.got_bridges.emit()
else:
self.progress_update.emit(
100, strings._("gui_autoconnect_circumventing_censorship_no_bridges")
)
self.got_no_bridges.emit()