SocketApi: Fix owncloud/enterprise#2938
authorMarkus Goetz <markus@woboq.com>
Fri, 31 Aug 2018 13:03:33 +0000 (15:03 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:43 +0000 (10:58 +0100)
src/gui/socketapi.cpp

index 427110b46fa76d7b3e4a9b3d25fb992459430621..3e62918157c1a234194ca55b4d87303f3b1c60ab 100644 (file)
@@ -58,6 +58,9 @@
 
 #include <QStandardPaths>
 
+#ifdef Q_OS_MAC
+#include <CoreFoundation/CoreFoundation.h>
+#endif
 
 // This is the version that is returned when the client asks for the VERSION.
 // The first number should be changed if there is an incompatible change that breaks old clients.
@@ -198,8 +201,19 @@ SocketApi::SocketApi(QObject *parent)
         // Example for official signed packages: "9B5WD74GWJ." "com.owncloud.desktopclient" ".socketApi"
         socketPath = SOCKETAPI_TEAM_IDENTIFIER_PREFIX APPLICATION_REV_DOMAIN ".socketApi";
 #ifdef Q_OS_MAC
+        int ret = 0;
+        CFURLRef url = (CFURLRef)CFAutorelease((CFURLRef)CFBundleCopyBundleURL(CFBundleGetMainBundle()));
+        QString bundlePath = QUrl::fromCFURL(url).path();
+        QString cmd;
+
         // Tell Finder to use the Extension (checking it from System Preferences -> Extensions)
-        system("pluginkit -e use -i  " APPLICATION_REV_DOMAIN ".FinderSyncExt &");
+        cmd = QString("pluginkit -v -e use -i " APPLICATION_REV_DOMAIN ".FinderSyncExt");
+        ret = system(cmd.toLocal8Bit());
+
+        // Add it again. This was needed for Mojave to trigger a load.
+        cmd = QString("pluginkit -v -a ") + bundlePath + "Contents/PlugIns/FinderSyncExt.appex/";
+        ret = system(cmd.toLocal8Bit());
+
 #endif
     } else if (Utility::isLinux() || Utility::isBSD()) {
         QString runtimeDir;
@@ -238,11 +252,6 @@ SocketApi::~SocketApi()
     // All remaining sockets will be destroyed with _localServer, their parent
     ASSERT(_listeners.isEmpty() || _listeners.first().socket->parent() == &_localServer);
     _listeners.clear();
-
-#ifdef Q_OS_MAC
-    // Unload the extension (uncheck from System Preferences -> Extensions)
-    system("pluginkit -e ignore -i  " APPLICATION_REV_DOMAIN ".FinderSyncExt &");
-#endif
 }
 
 void SocketApi::slotNewConnection()