Fix crash when canceling while compressing files, and also prevent canceled share from starting when compressing finishes

This commit is contained in:
Micah Lee 2018-04-24 08:48:17 -07:00
parent 9b2b815525
commit bda82bc7a0
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
2 changed files with 20 additions and 11 deletions

View file

@ -146,6 +146,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.share_mode.server_status.server_stopped.connect(self.update_server_status_indicator) self.share_mode.server_status.server_stopped.connect(self.update_server_status_indicator)
self.share_mode.start_server_finished.connect(self.update_server_status_indicator) self.share_mode.start_server_finished.connect(self.update_server_status_indicator)
self.share_mode.stop_server_finished.connect(self.update_server_status_indicator) self.share_mode.stop_server_finished.connect(self.update_server_status_indicator)
self.share_mode.stop_server_finished.connect(self.stop_server_finished)
self.share_mode.start_server_finished.connect(self.clear_message) self.share_mode.start_server_finished.connect(self.clear_message)
self.share_mode.server_status.button_clicked.connect(self.clear_message) self.share_mode.server_status.button_clicked.connect(self.clear_message)
self.share_mode.server_status.url_copied.connect(self.copy_url) self.share_mode.server_status.url_copied.connect(self.copy_url)
@ -255,6 +256,10 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.systemTray.setContextMenu(menu) self.systemTray.setContextMenu(menu)
self.systemTray.show() self.systemTray.show()
def stop_server_finished(self):
# When the server stopped, cleanup the ephemeral onion service
self.onion.cleanup(stop_tor=False)
def _tor_connection_canceled(self): def _tor_connection_canceled(self):
""" """
If the user cancels before Tor finishes connecting, ask if they want to If the user cancels before Tor finishes connecting, ask if they want to

View file

@ -193,7 +193,7 @@ class ShareMode(QtWidgets.QWidget):
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
server and the web app. server and the web app.
""" """
self.common.log('OnionShareGui', 'start_server') self.common.log('ShareMode', 'start_server')
self.set_server_active.emit(True) self.set_server_active.emit(True)
@ -238,7 +238,7 @@ class ShareMode(QtWidgets.QWidget):
""" """
Step 2 in starting the onionshare server. Zipping up files. Step 2 in starting the onionshare server. Zipping up files.
""" """
self.common.log('OnionShareGui', 'start_server_step2') self.common.log('ShareMode', 'start_server_step2')
# add progress bar to the status bar, indicating the compressing of files. # add progress bar to the status bar, indicating the compressing of files.
self._zip_progress_bar = ZipProgressBar(0) self._zip_progress_bar = ZipProgressBar(0)
@ -258,10 +258,11 @@ class ShareMode(QtWidgets.QWidget):
try: try:
self.web.set_file_info(self.filenames, processed_size_callback=_set_processed_size) self.web.set_file_info(self.filenames, processed_size_callback=_set_processed_size)
self.app.cleanup_filenames.append(self.web.zip_filename) self.app.cleanup_filenames.append(self.web.zip_filename)
self.starting_server_step3.emit()
# done # Only continue if the server hasn't been canceled
self.start_server_finished.emit() if self.server_status.status != self.server_status.STATUS_STOPPED:
self.starting_server_step3.emit()
self.start_server_finished.emit()
except OSError as e: except OSError as e:
self.starting_server_error.emit(e.strerror) self.starting_server_error.emit(e.strerror)
return return
@ -275,7 +276,7 @@ class ShareMode(QtWidgets.QWidget):
Step 3 in starting the onionshare server. This displays the large filesize Step 3 in starting the onionshare server. This displays the large filesize
warning, if applicable. warning, if applicable.
""" """
self.common.log('OnionShareGui', 'start_server_step3') self.common.log('ShareMode', 'start_server_step3')
# Remove zip progress bar # Remove zip progress bar
if self._zip_progress_bar is not None: if self._zip_progress_bar is not None:
@ -304,7 +305,7 @@ class ShareMode(QtWidgets.QWidget):
""" """
If there's an error when trying to start the onion service If there's an error when trying to start the onion service
""" """
self.common.log('OnionShareGui', 'start_server_error') self.common.log('ShareMode', 'start_server_error')
self.set_server_active.emit(False) self.set_server_active.emit(False)
@ -327,7 +328,7 @@ class ShareMode(QtWidgets.QWidget):
""" """
Stop the onionshare server. Stop the onionshare server.
""" """
self.common.log('OnionShareGui', 'stop_server') self.common.log('ShareMode', 'stop_server')
if self.server_status.status != self.server_status.STATUS_STOPPED: if self.server_status.status != self.server_status.STATUS_STOPPED:
try: try:
@ -337,8 +338,11 @@ class ShareMode(QtWidgets.QWidget):
pass pass
self.app.cleanup() self.app.cleanup()
# Remove ephemeral service, but don't disconnect from Tor # Remove the progress bar
self.onion.cleanup(stop_tor=False) if self._zip_progress_bar is not None:
self.status_bar.removeWidget(self._zip_progress_bar)
self._zip_progress_bar = None
self.filesize_warning.hide() self.filesize_warning.hide()
self.downloads_in_progress = 0 self.downloads_in_progress = 0
self.downloads_completed = 0 self.downloads_completed = 0
@ -352,7 +356,7 @@ class ShareMode(QtWidgets.QWidget):
""" """
When the 'Show/hide downloads' button is toggled, show or hide the downloads window. When the 'Show/hide downloads' button is toggled, show or hide the downloads window.
""" """
self.common.log('OnionShareGui', 'toggle_downloads') self.common.log('ShareMode', 'toggle_downloads')
if checked: if checked:
self.downloads.downloads_container.show() self.downloads.downloads_container.show()
else: else: