Fixed various issues introduced by creating an singleton Onion object and passing it into the OnionShare object

This commit is contained in:
Micah Lee 2017-05-14 17:21:13 -07:00
parent adc450c971
commit dc23946fe8
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
4 changed files with 13 additions and 27 deletions

View File

@ -128,6 +128,7 @@ def main(cwd=None):
finally: finally:
# Shutdown # Shutdown
app.cleanup() app.cleanup()
onion.cleanup()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -52,6 +52,7 @@ class OnionShare(object):
""" """
Start the onionshare onion service. Start the onionshare onion service.
""" """
# Choose a random port
self.port = helpers.get_available_port(17600, 17650) self.port = helpers.get_available_port(17600, 17650)
if self.local_only: if self.local_only:
@ -74,7 +75,3 @@ class OnionShare(object):
elif os.path.isdir(filename): elif os.path.isdir(filename):
shutil.rmtree(filename) shutil.rmtree(filename)
self.cleanup_filenames = [] self.cleanup_filenames = []
# cleanup the onion
if self.onion:
self.onion.cleanup()

View File

@ -105,7 +105,7 @@ def main():
# Start the OnionShare app # Start the OnionShare app
web.set_stay_open(stay_open) web.set_stay_open(stay_open)
app = OnionShare(debug, local_only, stay_open) app = OnionShare(onion, debug, local_only, stay_open)
# Clean up when app quits # Clean up when app quits
def shutdown(): def shutdown():

View File

@ -22,6 +22,7 @@ from PyQt5 import QtCore, QtWidgets, QtGui
from onionshare import strings, helpers, web from onionshare import strings, helpers, web
from onionshare.settings import Settings from onionshare.settings import Settings
from onionshare.onion import *
from .menu import Menu from .menu import Menu
from .file_selection import FileSelection from .file_selection import FileSelection
@ -145,36 +146,23 @@ class OnionShareGui(QtWidgets.QMainWindow):
web.error404_count = 0 web.error404_count = 0
web.set_gui_mode() web.set_gui_mode()
# pick an available local port for the http service to listen on
self.app.choose_port()
# start onionshare http service in new thread
t = threading.Thread(target=web.start, args=(self.app.port, self.app.stay_open))
t.daemon = True
t.start()
# wait for modules in thread to load, preventing a thread-related cx_Freeze crash
time.sleep(0.2)
# start the onion service in a new thread # start the onion service in a new thread
def start_onion_service(self): def start_onion_service(self):
try: try:
# Show Tor connection status if connection type is bundled tor self.app.start_onion_service()
if settings.get('connection_type') == 'bundled':
def bundled_tor_func(message):
self.status_bar.showMessage(message)
if 'Done' in message:
self.status_bar.showMessage(strings._('gui_starting_server1', True))
else:
self.status_bar.showMessage(strings._('gui_starting_server1', True))
bundled_tor_func = None
self.app.start_onion_service(bundled_tor_func)
self.starting_server_step2.emit() self.starting_server_step2.emit()
except (onionshare.onion.TorTooOld, onionshare.onion.TorErrorInvalidSetting, onionshare.onion.TorErrorAutomatic, onionshare.onion.TorErrorSocketPort, onionshare.onion.TorErrorSocketFile, onionshare.onion.TorErrorMissingPassword, onionshare.onion.TorErrorUnreadableCookieFile, onionshare.onion.TorErrorAuthError, onionshare.onion.TorErrorProtocolError, onionshare.onion.BundledTorTimeout) as e: except (TorTooOld, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorTimeout) as e:
self.starting_server_error.emit(e.args[0]) self.starting_server_error.emit(e.args[0])
return return
# start onionshare http service in new thread
t = threading.Thread(target=web.start, args=(self.app.port, self.app.stay_open))
t.daemon = True
t.start()
# wait for modules in thread to load, preventing a thread-related cx_Freeze crash
time.sleep(0.2)
t = threading.Thread(target=start_onion_service, kwargs={'self': self}) t = threading.Thread(target=start_onion_service, kwargs={'self': self})
t.daemon = True t.daemon = True
t.start() t.start()