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

[Enhancement] Avoid blocking UI while adding existing repo #1643

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
25 changes: 18 additions & 7 deletions src/vorta/views/repo_add_dialog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import re
from PyQt6 import QtCore, uic
from PyQt6.QtGui import QAction
Expand All @@ -10,6 +11,8 @@
from vorta.utils import borg_compat, choose_file_dialog, get_asset, get_private_keys, validate_passwords
from vorta.views.utils import get_colored_icon

logger = logging.getLogger(__name__)
real-yfprojects marked this conversation as resolved.
Show resolved Hide resolved

uifile = get_asset('UI/repoadd.ui')
AddRepoUI, AddRepoBase = uic.loadUiType(uifile)

Expand All @@ -28,7 +31,7 @@ def __init__(self, parent=None):
self.saveButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok)
self.saveButton.setText(self.tr("Add"))

self.buttonBox.rejected.connect(self.close)
self.buttonBox.rejected.connect(self.cancel_job)
self.buttonBox.accepted.connect(self.run)
self.chooseLocalFolderButton.clicked.connect(self.choose_local_backup_folder)
self.useRemoteRepoButton.clicked.connect(self.use_remote_repo_action)
Expand Down Expand Up @@ -146,7 +149,10 @@ def run_result(self, result):
self.added_repo.emit(result)
self.accept()
else:
self._set_status(self.tr('Unable to add your repository.'))
if self.cancel_job:
self._set_status(self.tr('Cancelled adding repo.'))
else:
self._set_status(self.tr('Unable to add your repository.'))

def init_encryption(self):
if borg_compat.check('V2'):
Expand Down Expand Up @@ -209,6 +215,11 @@ def password_listener(self):
self.passwordLabel.setText(translate('utils', msg))
return not bool(msg)

def cancel_job(self):
self.job.cancel()
logger.debug(f"Cancelled adding repo {self.values['repo_url']}")
return True


class ExistingRepoWindow(AddRepoWindow):
def __init__(self):
Expand Down Expand Up @@ -240,10 +251,10 @@ def run(self):
params = BorgInfoRepoJob.prepare(self.values)
if params['ok']:
self.saveButton.setEnabled(False)
thread = BorgInfoRepoJob(params['cmd'], params)
thread.updated.connect(self._set_status)
thread.result.connect(self.run_result)
self.thread = thread # Needs to be connected to self for tests to work.
self.thread.run()
job = BorgInfoRepoJob(params['cmd'], params, params['repo_id'])
real-yfprojects marked this conversation as resolved.
Show resolved Hide resolved
job.updated.connect(self._set_status)
job.result.connect(self.run_result)
self.job = job # Needs to be connected to self for tests to work.
QApplication.instance().jobs_manager.add_job(job)
else:
self._set_status(params['message'])