mirror of
https://github.com/onionshare/onionshare.git
synced 2025-06-21 21:14:19 -04:00
Move owernship of the TorConnetionDialog objection from __init__.py into the OnionShareGUI class, and make it so when the Tor connection gets canceled, OnionShare quits
This commit is contained in:
parent
d112b35414
commit
2ca92c52db
4 changed files with 57 additions and 38 deletions
|
@ -216,7 +216,10 @@ class Onion(object):
|
||||||
print("{}: {}% - {}{}".format(strings._('connecting_to_tor'), progress, summary, "\033[K"), end="\r")
|
print("{}: {}% - {}{}".format(strings._('connecting_to_tor'), progress, summary, "\033[K"), end="\r")
|
||||||
|
|
||||||
if callable(tor_status_update_func):
|
if callable(tor_status_update_func):
|
||||||
tor_status_update_func(progress, summary)
|
if not tor_status_update_func(progress, summary):
|
||||||
|
# If the dialog was canceled, stop connecting to Tor
|
||||||
|
print()
|
||||||
|
return False
|
||||||
|
|
||||||
if summary == 'Done':
|
if summary == 'Done':
|
||||||
print("")
|
print("")
|
||||||
|
|
|
@ -27,7 +27,6 @@ from onionshare.onionshare import OnionShare
|
||||||
from onionshare.settings import Settings
|
from onionshare.settings import Settings
|
||||||
|
|
||||||
from .onionshare_gui import OnionShareGui
|
from .onionshare_gui import OnionShareGui
|
||||||
from .tor_connection_dialog import TorConnectionDialog
|
|
||||||
|
|
||||||
class Application(QtWidgets.QApplication):
|
class Application(QtWidgets.QApplication):
|
||||||
"""
|
"""
|
||||||
|
@ -87,35 +86,22 @@ def main():
|
||||||
if not valid:
|
if not valid:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# Load settings
|
|
||||||
settings = Settings()
|
|
||||||
settings.load()
|
|
||||||
|
|
||||||
# Start the Onion
|
# Start the Onion
|
||||||
onion = 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
|
# Start the OnionShare app
|
||||||
web.set_stay_open(stay_open)
|
web.set_stay_open(stay_open)
|
||||||
app = OnionShare(onion, debug, local_only, stay_open)
|
app = OnionShare(onion, debug, local_only, stay_open)
|
||||||
|
|
||||||
|
# Launch the gui
|
||||||
|
gui = OnionShareGui(onion, qtapp, app, filenames)
|
||||||
|
|
||||||
# Clean up when app quits
|
# Clean up when app quits
|
||||||
def shutdown():
|
def shutdown():
|
||||||
onion.cleanup()
|
onion.cleanup()
|
||||||
app.cleanup()
|
app.cleanup()
|
||||||
qtapp.aboutToQuit.connect(shutdown)
|
qtapp.aboutToQuit.connect(shutdown)
|
||||||
|
|
||||||
# Launch the gui
|
|
||||||
gui = OnionShareGui(qtapp, app, filenames)
|
|
||||||
|
|
||||||
# All done
|
# All done
|
||||||
sys.exit(qtapp.exec_())
|
sys.exit(qtapp.exec_())
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ from onionshare import strings, helpers, web
|
||||||
from onionshare.settings import Settings
|
from onionshare.settings import Settings
|
||||||
from onionshare.onion import *
|
from onionshare.onion import *
|
||||||
|
|
||||||
|
from .tor_connection_dialog import TorConnectionDialog
|
||||||
from .menu import Menu
|
from .menu import Menu
|
||||||
from .file_selection import FileSelection
|
from .file_selection import FileSelection
|
||||||
from .server_status import ServerStatus
|
from .server_status import ServerStatus
|
||||||
|
@ -42,23 +43,31 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||||
starting_server_step3 = QtCore.pyqtSignal()
|
starting_server_step3 = QtCore.pyqtSignal()
|
||||||
starting_server_error = QtCore.pyqtSignal(str)
|
starting_server_error = QtCore.pyqtSignal(str)
|
||||||
|
|
||||||
def __init__(self, qtapp, app, filenames):
|
def __init__(self, onion, qtapp, app, filenames):
|
||||||
super(OnionShareGui, self).__init__()
|
super(OnionShareGui, self).__init__()
|
||||||
|
self.onion = onion
|
||||||
self.qtapp = qtapp
|
self.qtapp = qtapp
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
self.setWindowTitle('OnionShare')
|
self.setWindowTitle('OnionShare')
|
||||||
self.setWindowIcon(QtGui.QIcon(helpers.get_resource_path('images/logo.png')))
|
self.setWindowIcon(QtGui.QIcon(helpers.get_resource_path('images/logo.png')))
|
||||||
|
|
||||||
|
# Load settings
|
||||||
|
self.settings = Settings()
|
||||||
|
self.settings.load()
|
||||||
|
|
||||||
|
# Start the "Connecting to Tor" dialog, which calls onion.connect()
|
||||||
|
tor_con = TorConnectionDialog(self.settings, self.onion)
|
||||||
|
tor_con.canceled.connect(self._tor_connection_canceled)
|
||||||
|
tor_con.start()
|
||||||
|
|
||||||
# Menu bar
|
# Menu bar
|
||||||
self.setMenuBar(Menu(self.qtapp))
|
self.setMenuBar(Menu(self.qtapp))
|
||||||
|
|
||||||
# Check for updates in a new thread, if enabled
|
# Check for updates in a new thread, if enabled
|
||||||
system = platform.system()
|
system = platform.system()
|
||||||
if system == 'Windows' or system == 'Darwin':
|
if system == 'Windows' or system == 'Darwin':
|
||||||
settings = Settings()
|
if self.settings.get('use_autoupdate'):
|
||||||
settings.load()
|
|
||||||
if settings.get('use_autoupdate'):
|
|
||||||
def update_available(update_url, installed_version, latest_version):
|
def update_available(update_url, installed_version, latest_version):
|
||||||
Alert(strings._("update_available", True).format(update_url, installed_version, latest_version))
|
Alert(strings._("update_available", True).format(update_url, installed_version, latest_version))
|
||||||
|
|
||||||
|
@ -130,6 +139,16 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||||
self.timer.timeout.connect(self.check_for_requests)
|
self.timer.timeout.connect(self.check_for_requests)
|
||||||
self.timer.start(500)
|
self.timer.start(500)
|
||||||
|
|
||||||
|
def _tor_connection_canceled(self):
|
||||||
|
"""
|
||||||
|
If the user cancels before Tor finishes connecting, quit.
|
||||||
|
"""
|
||||||
|
def quit():
|
||||||
|
self.qtapp.quit()
|
||||||
|
|
||||||
|
# Wait 1ms for the event loop to finish closing the TorConnectionDialog before quitting
|
||||||
|
QtCore.QTimer.singleShot(1, quit)
|
||||||
|
|
||||||
def start_server(self):
|
def start_server(self):
|
||||||
"""
|
"""
|
||||||
Start the onionshare server. This uses multiple threads to start the Tor onion
|
Start the onionshare server. This uses multiple threads to start the Tor onion
|
||||||
|
@ -310,22 +329,26 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||||
self.status_bar.clearMessage()
|
self.status_bar.clearMessage()
|
||||||
|
|
||||||
def closeEvent(self, e):
|
def closeEvent(self, e):
|
||||||
if self.server_status.status != self.server_status.STATUS_STOPPED:
|
try:
|
||||||
dialog = QtWidgets.QMessageBox()
|
if self.server_status.status != self.server_status.STATUS_STOPPED:
|
||||||
dialog.setWindowTitle("OnionShare")
|
dialog = QtWidgets.QMessageBox()
|
||||||
dialog.setText(strings._('gui_quit_warning', True))
|
dialog.setWindowTitle("OnionShare")
|
||||||
quit_button = dialog.addButton(strings._('gui_quit_warning_quit', True), QtWidgets.QMessageBox.YesRole)
|
dialog.setText(strings._('gui_quit_warning', True))
|
||||||
dont_quit_button = dialog.addButton(strings._('gui_quit_warning_dont_quit', True), QtWidgets.QMessageBox.NoRole)
|
quit_button = dialog.addButton(strings._('gui_quit_warning_quit', True), QtWidgets.QMessageBox.YesRole)
|
||||||
dialog.setDefaultButton(dont_quit_button)
|
dont_quit_button = dialog.addButton(strings._('gui_quit_warning_dont_quit', True), QtWidgets.QMessageBox.NoRole)
|
||||||
reply = dialog.exec_()
|
dialog.setDefaultButton(dont_quit_button)
|
||||||
|
reply = dialog.exec_()
|
||||||
|
|
||||||
# Quit
|
# Quit
|
||||||
if reply == 0:
|
if reply == 0:
|
||||||
self.stop_server()
|
self.stop_server()
|
||||||
e.accept()
|
e.accept()
|
||||||
# Don't Quit
|
# Don't Quit
|
||||||
else:
|
else:
|
||||||
e.ignore()
|
e.ignore()
|
||||||
|
|
||||||
|
except:
|
||||||
|
e.accept()
|
||||||
|
|
||||||
|
|
||||||
class ZipProgressBar(QtWidgets.QProgressBar):
|
class ZipProgressBar(QtWidgets.QProgressBar):
|
||||||
|
|
|
@ -56,8 +56,12 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
|
||||||
self.setValue(0)
|
self.setValue(0)
|
||||||
try:
|
try:
|
||||||
self.onion.connect(self.settings, tor_status_update)
|
self.onion.connect(self.settings, tor_status_update)
|
||||||
|
|
||||||
|
# Close the dialog after connecting
|
||||||
|
self.setValue(self.maximum())
|
||||||
|
|
||||||
except BundledTorCanceled as e:
|
except BundledTorCanceled as e:
|
||||||
self.close()
|
self.cancel()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e.args[0])
|
print(e.args[0])
|
||||||
# TODO: Open settings to connect to Tor properly
|
# TODO: Open settings to connect to Tor properly
|
||||||
|
@ -66,3 +70,6 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
|
||||||
def tor_status_update(self, progress, summary):
|
def tor_status_update(self, progress, summary):
|
||||||
self.setValue(int(progress))
|
self.setValue(int(progress))
|
||||||
self.setLabelText("<strong>{}</strong><br>{}".format(strings._('connecting_to_tor', True), summary))
|
self.setLabelText("<strong>{}</strong><br>{}".format(strings._('connecting_to_tor', True), summary))
|
||||||
|
|
||||||
|
# Return False if the dialog was canceled
|
||||||
|
return not self.wasCanceled()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue