diff --git a/onionshare_gui/__init__.py b/onionshare_gui/__init__.py index e59c6cf5..8a8b955e 100644 --- a/onionshare_gui/__init__.py +++ b/onionshare_gui/__init__.py @@ -22,7 +22,7 @@ import os, sys, platform, argparse from PyQt5 import QtCore, QtWidgets from onionshare import strings, helpers, web -from onionshare.onion import * +from onionshare.onion import Onion from onionshare.onionshare import OnionShare from onionshare.settings import Settings @@ -93,7 +93,15 @@ def main(): # Start the Onion onion = Onion() + + def exit_early(): + # Wait for tor to exit + onion.cleanup() + sys.exit() + tor_con = TorConnectionDialog(settings, onion) + tor_con.canceled.connect(exit_early) + tor_con.start() # Start the OnionShare app web.set_stay_open(stay_open) diff --git a/onionshare_gui/tor_connection_dialog.py b/onionshare_gui/tor_connection_dialog.py index 734d2f5f..8c23f3cd 100644 --- a/onionshare_gui/tor_connection_dialog.py +++ b/onionshare_gui/tor_connection_dialog.py @@ -20,6 +20,7 @@ along with this program. If not, see . from PyQt5 import QtCore, QtWidgets, QtGui from onionshare import strings, helpers +from onionshare.onion import * class TorConnectionDialog(QtWidgets.QProgressDialog): """ @@ -28,6 +29,7 @@ class TorConnectionDialog(QtWidgets.QProgressDialog): def __init__(self, settings, onion): super(TorConnectionDialog, self).__init__(None) self.settings = settings + self.onion = onion self.setWindowTitle("OnionShare") self.setWindowIcon(QtGui.QIcon(helpers.get_resource_path('images/logo.png'))) @@ -39,11 +41,12 @@ class TorConnectionDialog(QtWidgets.QProgressDialog): # Progress bar ticks from 0 to 100 self.setRange(0, 100) - # Don't show if connection takes less than 200ms (for non-bundled tor) - self.setMinimumDuration(200) + # Don't show if connection takes less than 100ms (for non-bundled tor) + self.setMinimumDuration(100) + def start(self): # If bundled tor, prepare to display Tor connection status - if settings.get('connection_type') == 'bundled': + if self.settings.get('connection_type') == 'bundled': tor_status_update = self.tor_status_update else: tor_status_update = None @@ -51,18 +54,14 @@ class TorConnectionDialog(QtWidgets.QProgressDialog): # Connect to the Onion self.setValue(0) try: - onion.connect(self.settings, tor_status_update) - except (TorTooOld, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorNotSupported, BundledTorTimeout) as e: + self.onion.connect(self.settings, tor_status_update) + except BundledTorCanceled as e: + self.close() + except Exception as e: print(e.args[0]) # TODO: Open settings to connect to Tor properly sys.exit() - self.exec_() - def tor_status_update(self, progress, summary): - if summary == 'Done': - # All done - self.close() - else: - self.setValue(int(progress)) + self.setValue(int(progress)) self.setLabelText("{}
{}".format(strings._('connecting_to_tor', True), summary))