mirror of
https://github.com/borgbase/vorta
synced 2025-01-03 05:36:19 +00:00
Fix crash when window is closed while thread running. By @samuel-w (#685)
This commit is contained in:
parent
47df3eccc9
commit
cc47c1bc78
3 changed files with 19 additions and 24 deletions
|
@ -1,6 +1,5 @@
|
|||
import os
|
||||
import sys
|
||||
import sip
|
||||
from PyQt5 import QtCore
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue