Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when window is closed while thread running #685

Merged
merged 5 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/vorta/application.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import sys
import sip
from PyQt5 import QtCore
from PyQt5.QtWidgets import QMessageBox

Expand Down Expand Up @@ -47,8 +46,9 @@ def __init__(self, args_raw, single_app=False):
self.scheduler = VortaScheduler(self)
self.setApplicationName("Vorta")

# Prepare system tray icon
# Prepare tray and main window
self.tray = TrayMenu(self)
self.main_window = MainWindow(self)

args = parse_args()
if getattr(args, 'daemonize', False):
Expand Down Expand Up @@ -88,16 +88,12 @@ def create_backup_action(self, profile_id=None):
self.backup_progress_event.emit(translate('messages', msg['message']))

def open_main_window_action(self):
if not self._main_window_exists():
self.main_window = MainWindow(self)
self.main_window.show()
self.main_window.raise_()

def _main_window_exists(self):
return hasattr(self, 'main_window') and not sip.isdeleted(self.main_window)
self.main_window.activateWindow()

def toggle_main_window_visibility(self):
if self._main_window_exists():
if self.main_window.isVisible():
self.main_window.close()
else:
self.open_main_window_action()
Expand Down Expand Up @@ -126,14 +122,13 @@ def set_borg_details_action(self):

def set_borg_details_result(self, result):
"""
Receive result from BorgVersionThread. If MainWindow is open, set the version in misc tab.
Receive result from BorgVersionThread.
If no valid version was found, display an error.
"""
if 'version' in result['data']:
borg_compat.set_version(result['data']['version'], result['data']['path'])
if self._main_window_exists():
self.main_window.miscTab.set_borg_details(borg_compat.version, borg_compat.path)
self.main_window.repoTab.toggle_available_compression()
self.main_window.miscTab.set_borg_details(borg_compat.version, borg_compat.path)
self.main_window.repoTab.toggle_available_compression()
else:
self._alert_missing_borg()

Expand Down
21 changes: 11 additions & 10 deletions src/vorta/views/archive_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
class ArchiveTab(ArchiveTabBase, ArchiveTabUI, BackupProfileMixin):
prune_intervals = ['hour', 'day', 'week', 'month', 'year']

def __init__(self, parent=None):
def __init__(self, parent=None, app=None):
super().__init__(parent)
self.setupUi(parent)
self.mount_points = {}
self.menu = None
self.app = app
self.toolBox.setCurrentIndex(0)

header = self.archiveTable.horizontalHeader()
Expand Down Expand Up @@ -178,7 +179,7 @@ def check_action(self):
archive_name = archive_cell.text()
params['cmd'][-1] += f'::{archive_name}'

thread = BorgCheckThread(params['cmd'], params, parent=self)
thread = BorgCheckThread(params['cmd'], params, parent=self.app)
thread.updated.connect(self._set_status)
thread.result.connect(self.check_result)
self._toggle_all_buttons(False)
Expand All @@ -191,7 +192,7 @@ def check_result(self, result):
def prune_action(self):
params = BorgPruneThread.prepare(self.profile())
if params['ok']:
thread = BorgPruneThread(params['cmd'], params, parent=self)
thread = BorgPruneThread(params['cmd'], params, parent=self.app)
thread.updated.connect(self._set_status)
thread.result.connect(self.prune_result)
self._toggle_all_buttons(False)
Expand All @@ -207,7 +208,7 @@ def prune_result(self, result):
def list_action(self):
params = BorgListRepoThread.prepare(self.profile())
if params['ok']:
thread = BorgListRepoThread(params['cmd'], params, parent=self)
thread = BorgListRepoThread(params['cmd'], params, parent=self.app)
thread.updated.connect(self._set_status)
thread.result.connect(self.list_result)
self._toggle_all_buttons(False)
Expand Down Expand Up @@ -254,7 +255,7 @@ def receive():
self.mount_points[params['current_archive']] = mount_point[0]
if params['ok']:
self._toggle_all_buttons(False)
thread = BorgMountThread(params['cmd'], params, parent=self)
thread = BorgMountThread(params['cmd'], params, parent=self.app)
thread.updated.connect(self.mountErrors.setText)
thread.result.connect(self.mount_result)
thread.start()
Expand Down Expand Up @@ -289,7 +290,7 @@ def umount_action(self):

if os.path.normpath(mount_point) in params['active_mount_points']:
params['cmd'].append(mount_point)
thread = BorgUmountThread(params['cmd'], params, parent=self)
thread = BorgUmountThread(params['cmd'], params, parent=self.app)
thread.updated.connect(self.mountErrors.setText)
thread.result.connect(self.umount_result)
thread.start()
Expand Down Expand Up @@ -333,7 +334,7 @@ def list_archive_action(self):
self._set_status('')
self._toggle_all_buttons(False)

thread = BorgListArchiveThread(params['cmd'], params, parent=self)
thread = BorgListArchiveThread(params['cmd'], params, parent=self.app)
thread.updated.connect(self.mountErrors.setText)
thread.result.connect(self.list_archive_result)
thread.start()
Expand All @@ -358,7 +359,7 @@ def receive():
self.profile(), archive.name, window.selected, extraction_folder[0])
if params['ok']:
self._toggle_all_buttons(False)
thread = BorgExtractThread(params['cmd'], params, parent=self)
thread = BorgExtractThread(params['cmd'], params, parent=self.app)
thread.updated.connect(self.mountErrors.setText)
thread.result.connect(self.extract_archive_result)
thread.start()
Expand Down Expand Up @@ -418,7 +419,7 @@ def delete_action(self):
return
params['cmd'][-1] += f'::{archive_name}'

thread = BorgDeleteThread(params['cmd'], params, parent=self)
thread = BorgDeleteThread(params['cmd'], params, parent=self.app)
thread.updated.connect(self._set_status)
thread.result.connect(self.delete_result)
self._toggle_all_buttons(False)
Expand Down Expand Up @@ -457,7 +458,7 @@ def diff_action(self):

if params['ok']:
self._toggle_all_buttons(False)
thread = BorgDiffThread(params['cmd'], params, parent=self)
thread = BorgDiffThread(params['cmd'], params, parent=self.app)
thread.updated.connect(self.mountErrors.setText)
thread.result.connect(self.list_diff_result)
thread.start()
Expand Down
3 changes: 1 addition & 2 deletions src/vorta/views/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def __init__(self, parent=None):
super().__init__()
self.setupUi(self)
self.setWindowTitle('Vorta for Borg Backup')
self.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
self.app = parent
self.setWindowIcon(get_colored_icon("icon"))
self.setWindowFlags(QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowMinimizeButtonHint)
Expand All @@ -47,7 +46,7 @@ def __init__(self, parent=None):
# Load tab models
self.repoTab = RepoTab(self.repoTabSlot)
self.sourceTab = SourceTab(self.sourceTabSlot)
self.archiveTab = ArchiveTab(self.archiveTabSlot)
self.archiveTab = ArchiveTab(self.archiveTabSlot, app=self.app)
self.scheduleTab = ScheduleTab(self.scheduleTabSlot)
self.miscTab = MiscTab(self.miscTabSlot)
self.miscTab.set_borg_details(borg_compat.version, borg_compat.path)
Expand Down