Fix order of pluginkit commands and modernise
authorHannah von Reth <hannah.vonreth@owncloud.com>
Tue, 12 May 2020 12:10:02 +0000 (14:10 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:12 +0000 (10:59 +0100)
src/gui/socketapi.cpp

index e453271bf0b737dbca7dfde15be669941b1fda9f..e1bfcdf610df8f1f97bfcfb85e5a6060c29c016d 100644 (file)
@@ -64,6 +64,7 @@
 #include <QClipboard>
 #include <QDesktopServices>
 
+#include <QProcess>
 #include <QStandardPaths>
 
 #ifdef Q_OS_MAC
@@ -232,18 +233,24 @@ 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)
-        cmd = QString("pluginkit -v -e use -i " APPLICATION_REV_DOMAIN ".FinderSyncExt");
-        ret = system(cmd.toLocal8Bit());
 
+        auto _system = [](const QString &cmd, const QStringList &args){
+            QProcess process;
+            process.setProcessChannelMode(QProcess::MergedChannels);
+            process.start(cmd, args);
+            if (!process.waitForFinished())
+            {
+                qCWarning(lcSocketApi) << "Failed to load shell extension:" << cmd << args.join(" ") << process.errorString();
+            } else {
+                qCInfo(lcSocketApi) << (process.exitCode() != 0 ? "Failed to load" : "Loaded") <<  "shell extension:" << cmd << args.join(" ") << process.readAll();
+            }
+        };
         // 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());
+        _system(QStringLiteral("pluginkit"), {QStringLiteral("-a"),QStringLiteral("%1Contents/PlugIns/FinderSyncExt.appex/").arg(bundlePath)});
+        // Tell Finder to use the Extension (checking it from System Preferences -> Extensions)
+        _system(QStringLiteral("pluginkit"), {QStringLiteral("-e"), QStringLiteral("use"), QStringLiteral("-i"), QStringLiteral(APPLICATION_REV_DOMAIN ".FinderSyncExt")});
 
 #endif
     } else if (Utility::isLinux() || Utility::isBSD()) {