Don't start the check_for_requests timer until after connected to Tor, and remove OnionShareGui.tor_con and TorConnectionDialog.t as class variables, making them local variables instead

This commit is contained in:
Micah Lee 2018-01-13 22:42:27 -08:00
parent 7c653b6a8d
commit 2dd2052c69
2 changed files with 24 additions and 25 deletions

View File

@ -130,11 +130,6 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.setCentralWidget(central_widget)
self.show()
# Check for requests frequently
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.check_for_requests)
self.timer.start(500)
# Always start with focus on file selection
self.file_selection.setFocus()
@ -142,10 +137,15 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.set_server_active(False)
# Start the "Connecting to Tor" dialog, which calls onion.connect()
self.tor_con = TorConnectionDialog(self.qtapp, self.settings, self.onion)
self.tor_con.canceled.connect(self._tor_connection_canceled)
self.tor_con.open_settings.connect(self._tor_connection_open_settings)
self.tor_con.start()
tor_con = TorConnectionDialog(self.qtapp, self.settings, self.onion)
tor_con.canceled.connect(self._tor_connection_canceled)
tor_con.open_settings.connect(self._tor_connection_open_settings)
tor_con.start()
# Check for requests frequently
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.check_for_requests)
self.timer.start(500)
# After connecting to Tor, check for updates
self.check_for_updates()
@ -410,15 +410,14 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.update()
# Have we lost connection to Tor somehow?
if self.tor_con.t.isFinished():
if not self.onion.is_authenticated():
self.timer.stop()
if self.server_status.status != self.server_status.STATUS_STOPPED:
self.server_status.stop_server()
self.server_status.server_button.setEnabled(False)
self.status_bar.showMessage(strings._('gui_tor_connection_lost', True))
if self.systemTray.supportsMessages() and self.settings.get('systray_notifications'):
self.systemTray.showMessage(strings._('gui_tor_connection_lost', True), strings._('gui_tor_connection_error_settings', True))
if not self.onion.is_authenticated():
self.timer.stop()
if self.server_status.status != self.server_status.STATUS_STOPPED:
self.server_status.stop_server()
self.server_status.server_button.setEnabled(False)
self.status_bar.showMessage(strings._('gui_tor_connection_lost', True))
if self.systemTray.supportsMessages() and self.settings.get('systray_notifications'):
self.systemTray.showMessage(strings._('gui_tor_connection_lost', True), strings._('gui_tor_connection_error_settings', True))
# scroll to the bottom of the dl progress bar log pane
# if a new download has been added

View File

@ -57,14 +57,14 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
def start(self):
common.log('TorConnectionDialog', 'start')
self.t = TorConnectionThread(self, self.settings, self.onion)
self.t.tor_status_update.connect(self._tor_status_update)
self.t.connected_to_tor.connect(self._connected_to_tor)
self.t.canceled_connecting_to_tor.connect(self._canceled_connecting_to_tor)
self.t.error_connecting_to_tor.connect(self._error_connecting_to_tor)
self.t.start()
t = TorConnectionThread(self, self.settings, self.onion)
t.tor_status_update.connect(self._tor_status_update)
t.connected_to_tor.connect(self._connected_to_tor)
t.canceled_connecting_to_tor.connect(self._canceled_connecting_to_tor)
t.error_connecting_to_tor.connect(self._error_connecting_to_tor)
t.start()
# The main thread needs to remain active, and checkign for Qt events,
# The main thread needs to remain active, and checking for Qt events,
# until the thread is finished. Otherwise it won't be able to handle
# accepting signals.
self.active = True