From: Claudio Cambra Date: Wed, 15 Mar 2023 14:54:10 +0000 (+0100) Subject: Improve initialisation of C++ FileProvider class X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~10^2~55^2~70 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=22fc43e7b0737c2d01fb92e063df6b4bd5155d29;p=nextcloud-desktop.git Improve initialisation of C++ FileProvider class Signed-off-by: Claudio Cambra --- diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 4d6b25c62..57c5f9349 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -403,7 +403,7 @@ Application::Application(int &argc, char **argv) } #ifdef Q_OS_MACOS - _fileProvider.reset(Mac::FileProvider::instance()); + _fileProvider.reset(new Mac::FileProvider); #endif FolderMan::instance()->setSyncEnabled(true); diff --git a/src/gui/macOS/fileprovider.h b/src/gui/macOS/fileprovider.h index c974afb76..d45ba987d 100644 --- a/src/gui/macOS/fileprovider.h +++ b/src/gui/macOS/fileprovider.h @@ -21,6 +21,8 @@ namespace OCC { +class Application; + namespace Mac { // NOTE: For the file provider extension to work, the app bundle will @@ -32,14 +34,18 @@ class FileProvider : public QObject public: static FileProvider *instance(); - ~FileProvider() = default; + ~FileProvider() override; static bool fileProviderAvailable(); private: - explicit FileProvider(QObject * const parent = nullptr); std::unique_ptr _domainManager; std::unique_ptr _socketServer; + + static FileProvider *_instance; + explicit FileProvider(QObject * const parent = nullptr); + + friend class OCC::Application; }; } // namespace Mac diff --git a/src/gui/macOS/fileprovider_mac.mm b/src/gui/macOS/fileprovider_mac.mm index 879a39098..9cb5b739b 100644 --- a/src/gui/macOS/fileprovider_mac.mm +++ b/src/gui/macOS/fileprovider_mac.mm @@ -24,11 +24,13 @@ Q_LOGGING_CATEGORY(lcMacFileProvider, "nextcloud.gui.macfileprovider", QtInfoMsg namespace Mac { -static FileProvider *_instance = nullptr; +FileProvider* FileProvider::_instance = nullptr; FileProvider::FileProvider(QObject * const parent) : QObject(parent) { + Q_ASSERT(!_instance); + if (!fileProviderAvailable()) { qCDebug(lcMacFileProvider) << "File provider system is not available on this version of macOS."; return; @@ -61,6 +63,11 @@ FileProvider *FileProvider::instance() return _instance; } +FileProvider::~FileProvider() +{ + _instance = nullptr; +} + bool FileProvider::fileProviderAvailable() { if (@available(macOS 11.0, *)) {