diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 0158c22488ef8..f7b575d36dfc9 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -873,8 +873,10 @@ AccountPtr AccountManager::createAccount() acc->setSslErrorHandler(new SslDialogErrorHandler); connect(acc.data(), &Account::proxyAuthenticationRequired, ProxyAuthHandler::instance(), &ProxyAuthHandler::handleProxyAuthenticationRequired); - connect(acc.data(), &Account::lockFileError, - Systray::instance(), &Systray::showErrorMessageDialog); + if (Systray::instance()) { + connect(acc.data(), &Account::lockFileError, + Systray::instance(), &Systray::showErrorMessageDialog); + } return acc; } diff --git a/src/gui/accountsetupcommandlinemanager.cpp b/src/gui/accountsetupcommandlinemanager.cpp index 8d89213cfe73f..de1b0ec4cf54e 100644 --- a/src/gui/accountsetupcommandlinemanager.cpp +++ b/src/gui/accountsetupcommandlinemanager.cpp @@ -83,7 +83,7 @@ bool AccountSetupCommandLineManager::parseCommandlineOption(const QString &optio bool AccountSetupCommandLineManager::isCommandLineParsed() const { - return !_appPassword.isEmpty() && !_userId.isEmpty() && _serverUrl.isValid(); + return !_userId.isEmpty() && _serverUrl.isValid(); } bool AccountSetupCommandLineManager::isVfsEnabled() const diff --git a/src/gui/accountsetupfromcommandlinejob.cpp b/src/gui/accountsetupfromcommandlinejob.cpp index 33044a0d74336..397d26607b38a 100644 --- a/src/gui/accountsetupfromcommandlinejob.cpp +++ b/src/gui/accountsetupfromcommandlinejob.cpp @@ -19,6 +19,8 @@ #include #include +using namespace Qt::StringLiterals; + namespace OCC { Q_LOGGING_CATEGORY(lcAccountSetupCommandLineJob, "nextcloud.gui.accountsetupcommandlinejob", QtInfoMsg) @@ -70,8 +72,14 @@ void AccountSetupFromCommandLineJob::handleAccountSetupFromCommandLine() const auto credentials = new WebFlowCredentials(_userId, _appPassword); _account = AccountManager::createAccount(); + _account->setCredentials(credentials); + _account->setCredentialSetting(u"user"_s, _userId); _account->setUrl(_serverUrl); + auto accountState = AccountManager::instance()->addAccount(_account); + setupLocalSyncFolder(accountState); + + Q_EMIT _account->wantsAccountSaved(_account); fetchUserName(); } @@ -194,7 +202,7 @@ void AccountSetupFromCommandLineJob::setupLocalSyncFolder(AccountState *accountS AccountManager::instance()->deleteAccount(accountState); printAccountSetupFromCommandLineStatusAndExit( QStringLiteral("Account %1 setup from command line failed, due to folder creation failure.").arg(_account->displayName()), - false); + true); } } diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 40cba58df8b56..8da2fc1f98e9d 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -344,7 +344,7 @@ Application::Application(int &argc, char **argv) // try to migrate legacy accounts and folders from a previous client version // only copy the settings and check what should be skipped - if (!configVersionMigration()) { + if (!AccountSetupCommandLineManager::instance()->isCommandLineParsed() && !configVersionMigration()) { qCWarning(lcApplication) << "Config version migration was not possible."; } @@ -412,6 +412,16 @@ Application::Application(int &argc, char **argv) connect(&_singleApp, &KDSingleApplication::messageReceived, this, &Application::slotParseMessage); #endif + if (AccountSetupCommandLineManager::instance()->isCommandLineParsed()) { + _folderManager.reset(new FolderMan); + AccountSetupCommandLineManager::instance()->setupAccountFromCommandLine(); + _quitInstance = true; + } + AccountSetupCommandLineManager::destroy(); + if (_quitInstance) { + return; + } + // create accounts and folders from a legacy desktop client or from the current config file setupAccountsAndFolders(); @@ -501,11 +511,6 @@ Application::Application(int &argc, char **argv) } #endif - if (AccountSetupCommandLineManager::instance()->isCommandLineParsed()) { - AccountSetupCommandLineManager::instance()->setupAccountFromCommandLine(); - } - AccountSetupCommandLineManager::destroy(); - #if defined(BUILD_FILE_PROVIDER_MODULE) Mac::FileProvider::instance(); if (Mac::FileProvider::available()) { diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index d9641b09be0fb..9c08aff4285df 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -108,8 +108,10 @@ Systray::Systray() this, [this]{ showWindow(WindowPosition::Center); }); #endif - connect(FolderMan::instance(), &FolderMan::folderListChanged, this, &Systray::slotSyncFoldersChanged); - slotSyncFoldersChanged(FolderMan::instance()->map()); + if (FolderMan::instance()) { + connect(FolderMan::instance(), &FolderMan::folderListChanged, this, &Systray::slotSyncFoldersChanged); + slotSyncFoldersChanged(FolderMan::instance()->map()); + } } void Systray::create()