Separate starting of domain manager tasks from constructor

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-01-23 18:20:07 +08:00
parent 58dc42a521
commit 423891230e
3 changed files with 28 additions and 24 deletions

View file

@ -44,9 +44,10 @@ FileProvider::FileProvider(QObject * const parent)
}
qCInfo(lcMacFileProvider) << "Initialising file provider domain manager.";
_domainManager = std::make_unique<FileProviderDomainManager>(new FileProviderDomainManager(this));
_domainManager = std::make_unique<FileProviderDomainManager>(this);
if (_domainManager) {
_domainManager->start();
qCDebug(lcMacFileProvider()) << "Initialized file provider domain manager";
}

View file

@ -33,6 +33,7 @@ public:
~FileProviderDomainManager() override;
static AccountStatePtr accountStateFromFileProviderDomainIdentifier(const QString &domainIdentifier);
void start();
private slots:
void setupFileProviderDomains();

View file

@ -407,29 +407,6 @@ FileProviderDomainManager::FileProviderDomainManager(QObject * const parent)
{
if (@available(macOS 11.0, *)) {
d.reset(new FileProviderDomainManager::MacImplementation());
ConfigFile cfg;
std::chrono::milliseconds polltime = cfg.remotePollInterval();
_enumeratorSignallingTimer.setInterval(polltime.count());
connect(&_enumeratorSignallingTimer, &QTimer::timeout,
this, &FileProviderDomainManager::slotEnumeratorSignallingTimerTimeout);
_enumeratorSignallingTimer.start();
setupFileProviderDomains();
connect(AccountManager::instance(), &AccountManager::accountAdded,
this, &FileProviderDomainManager::addFileProviderDomainForAccount);
// If an account is deleted from the client, accountSyncConnectionRemoved will be
// emitted first. So we treat accountRemoved as only being relevant to client
// shutdowns.
connect(AccountManager::instance(), &AccountManager::accountSyncConnectionRemoved,
this, &FileProviderDomainManager::removeFileProviderDomainForAccount);
connect(AccountManager::instance(), &AccountManager::accountRemoved,
this, [this](const AccountState * const accountState) {
const auto trReason = tr("%1 application has been closed. Reopen to reconnect.").arg(APPLICATION_NAME);
disconnectFileProviderDomainForAccount(accountState, trReason);
});
} else {
qCWarning(lcMacFileProviderDomainManager()) << "Trying to run File Provider on system that does not support it.";
}
@ -437,6 +414,31 @@ FileProviderDomainManager::FileProviderDomainManager(QObject * const parent)
FileProviderDomainManager::~FileProviderDomainManager() = default;
void FileProviderDomainManager::start()
{
ConfigFile cfg;
std::chrono::milliseconds polltime = cfg.remotePollInterval();
_enumeratorSignallingTimer.setInterval(polltime.count());
connect(&_enumeratorSignallingTimer, &QTimer::timeout,
this, &FileProviderDomainManager::slotEnumeratorSignallingTimerTimeout);
_enumeratorSignallingTimer.start();
setupFileProviderDomains();
connect(AccountManager::instance(), &AccountManager::accountAdded,
this, &FileProviderDomainManager::addFileProviderDomainForAccount);
// If an account is deleted from the client, accountSyncConnectionRemoved will be
// emitted first. So we treat accountRemoved as only being relevant to client
// shutdowns.
connect(AccountManager::instance(), &AccountManager::accountSyncConnectionRemoved,
this, &FileProviderDomainManager::removeFileProviderDomainForAccount);
connect(AccountManager::instance(), &AccountManager::accountRemoved,
this, [this](const AccountState * const accountState) {
const auto trReason = tr("%1 application has been closed. Reopen to reconnect.").arg(APPLICATION_NAME);
disconnectFileProviderDomainForAccount(accountState, trReason);
});
}
void FileProviderDomainManager::setupFileProviderDomains()
{
if (!d) {