Skip to content

Commit

Permalink
Improve initialisation of C++ FileProvider class
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Mar 15, 2023
1 parent 9f0ce59 commit 857df97
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,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);
Expand Down
10 changes: 8 additions & 2 deletions src/gui/macOS/fileprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

namespace OCC {

class Application;

namespace Mac {

// NOTE: For the file provider extension to work, the app bundle will
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/gui/macOS/fileprovider_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@

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;
Expand Down Expand Up @@ -61,6 +63,11 @@
return _instance;
}

FileProvider::~FileProvider()
{
_instance = nullptr;
}

bool FileProvider::fileProviderAvailable()
{
if (@available(macOS 11.0, *)) {
Expand Down

0 comments on commit 857df97

Please sign in to comment.