Improve initialisation of C++ FileProvider class

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-03-15 15:54:10 +01:00
parent ccad81949a
commit 22fc43e7b0
No known key found for this signature in database
GPG key ID: C839200C384636B0
3 changed files with 17 additions and 4 deletions

View file

@ -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);

View file

@ -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<FileProviderDomainManager> _domainManager;
std::unique_ptr<FileProviderSocketServer> _socketServer;
static FileProvider *_instance;
explicit FileProvider(QObject * const parent = nullptr);
friend class OCC::Application;
};
} // namespace Mac

View file

@ -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, *)) {