Made clicking Exit in the TorConnectionDialog exit the app

This commit is contained in:
Micah Lee 2017-04-17 20:49:50 -07:00
parent 6c02984a98
commit bcf2e518de
2 changed files with 20 additions and 13 deletions

View File

@ -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)

View File

@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
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.setLabelText("<strong>{}</strong><br>{}".format(strings._('connecting_to_tor', True), summary))