diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index b08ac34f0563d..f3a272f2104f9 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -216,21 +216,27 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) new ToolTipUpdater(_ui->_folderList); #if defined(BUILD_FILE_PROVIDER_MODULE) - const auto fileProviderPanelContents = _ui->fileProviderPanelContents; - const auto fpSettingsLayout = new QVBoxLayout(fileProviderPanelContents); - const auto fpAccountUserIdAtHost = _accountState->account()->userIdAtHostWithPort(); - const auto fpSettingsController = Mac::FileProviderSettingsController::instance(); - const auto fpSettingsWidget = fpSettingsController->settingsViewWidget(fpAccountUserIdAtHost, fileProviderPanelContents, - QQuickWidget::SizeRootObjectToView); - fpSettingsLayout->setContentsMargins(0, 0, 0, 0); - fpSettingsLayout->setSpacing(0); - - fpSettingsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - if (const auto fpSettingsWidgetLayout = fpSettingsWidget->layout()) { - fpSettingsWidgetLayout->setContentsMargins(0, 0, 0, 0); + if (Mac::FileProvider::available()) { + const auto fileProviderPanelContents = _ui->fileProviderPanelContents; + const auto fpSettingsLayout = new QVBoxLayout(fileProviderPanelContents); + const auto fpAccountUserIdAtHost = _accountState->account()->userIdAtHostWithPort(); + const auto fpSettingsController = Mac::FileProviderSettingsController::instance(); + const auto fpSettingsWidget = fpSettingsController->settingsViewWidget(fpAccountUserIdAtHost, fileProviderPanelContents, + QQuickWidget::SizeRootObjectToView); + fpSettingsLayout->setContentsMargins(0, 0, 0, 0); + fpSettingsLayout->setSpacing(0); + + fpSettingsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + if (const auto fpSettingsWidgetLayout = fpSettingsWidget->layout()) { + fpSettingsWidgetLayout->setContentsMargins(0, 0, 0, 0); + } + fpSettingsLayout->addWidget(fpSettingsWidget, 1); + fileProviderPanelContents->setLayout(fpSettingsLayout); + } else { + // macOS 13 Ventura: the file provider feature is unsupported there. + // This branch can be removed once Ventura is no longer supported. + _ui->fileProviderPanel->setVisible(false); } - fpSettingsLayout->addWidget(fpSettingsWidget, 1); - fileProviderPanelContents->setLayout(fpSettingsLayout); #else _ui->fileProviderPanel->setVisible(false); #endif diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 4b6daec531ea7..f68fb3db2feba 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -39,6 +39,7 @@ #include "shellextensionsserver.h" #elif defined(Q_OS_MACOS) #include "macOS/fileprovider.h" +#include "macOS/fileprovidersettingscontroller.h" #include "macOS/findersyncxpc.h" #include "macOS/findersyncservice.h" #endif @@ -497,7 +498,15 @@ Application::Application(int &argc, char **argv) #if defined(BUILD_FILE_PROVIDER_MODULE) Mac::FileProvider::instance(); - Mac::FileProvider::instance()->configureXPC(); + if (Mac::FileProvider::available()) { + Mac::FileProvider::instance()->configureXPC(); + } else { + // macOS 13 Ventura: instantiating the settings controller triggers the + // one-time cleanup that gracefully tears down any pre-existing VFS + // domains. The check (and this branch) can be removed once Ventura is + // no longer supported. + Mac::FileProviderSettingsController::instance(); + } #endif #if defined(Q_OS_MACOS) diff --git a/src/gui/macOS/fileprovider.h b/src/gui/macOS/fileprovider.h index 922731b4a67da..42f34ea3486f4 100644 --- a/src/gui/macOS/fileprovider.h +++ b/src/gui/macOS/fileprovider.h @@ -28,6 +28,15 @@ class FileProvider : public QObject static FileProvider *instance(); ~FileProvider() override; + /** + * @brief Whether the macOS file provider feature is usable on the current OS. + * + * Returns false on macOS 13 Ventura, where the extension is incompatible + * (see nextcloud/desktop#9927). This runtime check can be removed once + * macOS 13 Ventura is no longer supported. + */ + [[nodiscard]] static bool available(); + void configureXPC(); [[nodiscard]] FileProviderXPC *xpc() const; [[nodiscard]] FileProviderDomainManager *domainManager() const; diff --git a/src/gui/macOS/fileprovider_mac.mm b/src/gui/macOS/fileprovider_mac.mm index cdc863567623e..369702b3dbfa2 100644 --- a/src/gui/macOS/fileprovider_mac.mm +++ b/src/gui/macOS/fileprovider_mac.mm @@ -6,6 +6,7 @@ #include "fileprovider.h" #include +#include #include "libsync/configfile.h" #include "gui/macOS/fileproviderxpc.h" @@ -48,6 +49,11 @@ return _instance; } +bool FileProvider::available() +{ + return QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSSonoma; +} + FileProvider::~FileProvider() { _instance = nullptr; @@ -55,6 +61,11 @@ void FileProvider::configureXPC() { + if (!available()) { + qCInfo(lcMacFileProvider) << "Skipping file provider XPC configuration on unsupported macOS version."; + return; + } + _xpc = std::make_unique(new FileProviderXPC(this)); if (_xpc) { diff --git a/src/gui/macOS/fileprovidersettingscontroller_mac.mm b/src/gui/macOS/fileprovidersettingscontroller_mac.mm index 65d0464aa40ca..08ee1dc9c317c 100644 --- a/src/gui/macOS/fileprovidersettingscontroller_mac.mm +++ b/src/gui/macOS/fileprovidersettingscontroller_mac.mm @@ -57,9 +57,14 @@ explicit MacImplementation(FileProviderSettingsController *const parent) migrateToAppSandbox(); removeOrphanedDomains(); - restoreMissingDomains(); - Mac::FileProvider::instance()->domainManager()->reconnectAll(); - Mac::FileProvider::instance()->configureXPC(); + + if (Mac::FileProvider::available()) { + restoreMissingDomains(); + Mac::FileProvider::instance()->domainManager()->reconnectAll(); + Mac::FileProvider::instance()->configureXPC(); + } else { + disableFileProviderForAllEnabledAccountsOnUnsupportedOS(); + } }; ~MacImplementation() override = default; @@ -286,6 +291,32 @@ void removeOrphanedDomains() qCInfo(lcFileProviderSettingsController) << "Finished removing orphaned domains."; } + // macOS 13 Ventura cleanup: removes any pre-existing file provider domain + // gracefully (preserving dirty user data) for each account that still has + // VFS enabled. Can be deleted once Ventura is no longer supported. + void disableFileProviderForAllEnabledAccountsOnUnsupportedOS() + { + qCInfo(lcFileProviderSettingsController) << "macOS 13 Ventura: disabling file provider for all enabled accounts."; + + const auto accountStates = AccountManager::instance()->accounts(); + + for (const auto &accountState : accountStates) { + const auto account = accountState->account(); + + if (!account) { + continue; + } + + if (account->fileProviderDomainIdentifier().isEmpty()) { + continue; + } + + const auto userIdAtHost = account->userIdAtHostWithPort(); + qCInfo(lcFileProviderSettingsController) << "Disabling file provider for account" << userIdAtHost; + (void)setVfsEnabledForAccount(userIdAtHost, false); + } + } + private: [[maybe_unused]] FileProviderSettingsController *q = nullptr; }; diff --git a/src/gui/wizard/owncloudadvancedsetuppage.cpp b/src/gui/wizard/owncloudadvancedsetuppage.cpp index d5c7f481d3771..af2b2900a5719 100644 --- a/src/gui/wizard/owncloudadvancedsetuppage.cpp +++ b/src/gui/wizard/owncloudadvancedsetuppage.cpp @@ -106,7 +106,7 @@ OwncloudAdvancedSetupPage::OwncloudAdvancedSetupPage(OwncloudWizard *wizard) #ifdef Q_OS_WIN bestAvailableVfsMode() == Vfs::WindowsCfApi #elif defined(BUILD_FILE_PROVIDER_MODULE) - true + Mac::FileProvider::available() #else false #endif @@ -149,14 +149,14 @@ void OwncloudAdvancedSetupPage::initializePage() { WizardCommon::initErrorLabel(_ui.errorLabel); - if (Theme::instance()->disableVirtualFilesSyncFolder() - || !(Theme::instance()->showVirtualFilesOption() + const auto hideVfsOption = Theme::instance()->disableVirtualFilesSyncFolder() #ifdef BUILD_FILE_PROVIDER_MODULE - || true + || !Mac::FileProvider::available(); #else - && bestAvailableVfsMode() != Vfs::Off + || !(Theme::instance()->showVirtualFilesOption() && bestAvailableVfsMode() != Vfs::Off); #endif - )) { + + if (hideVfsOption) { // If the layout were wrapped in a widget, the auto-grouping of the // radio buttons no longer works and there are surprising margins. // Just manually hide the button and remove the layout. diff --git a/src/gui/wizard/owncloudwizard.cpp b/src/gui/wizard/owncloudwizard.cpp index 566266f895680..8c97981a29256 100644 --- a/src/gui/wizard/owncloudwizard.cpp +++ b/src/gui/wizard/owncloudwizard.cpp @@ -233,7 +233,7 @@ bool OwncloudWizard::needsToAcceptTermsOfService() const bool OwncloudWizard::useVirtualFileSyncByDefault() const { #ifdef BUILD_FILE_PROVIDER_MODULE - return true; + return Mac::FileProvider::available(); #else return false; #endif