kdeconnect-app: add CLI option to allow starting handler via app

this feature is important to enable sendTo-menu-like integration in the Microsoft Store build
This commit is contained in:
Piyush Aggarwal 2021-07-14 09:14:12 +05:30
parent cec5d8086a
commit 6712953279

View file

@ -11,6 +11,7 @@
#include <QQmlContext> #include <QQmlContext>
#include <QQuickStyle> #include <QQuickStyle>
#include <QStandardPaths> #include <QStandardPaths>
#include <QProcess>
#include <KAboutData> #include <KAboutData>
#include <KLocalizedString> #include <KLocalizedString>
@ -35,11 +36,21 @@ int main(int argc, char* argv[])
QQuickStyle::setStyle(QStringLiteral("org.kde.desktop")); QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
} }
QString urlToShare;
{ {
QCommandLineParser parser; QCommandLineParser parser;
parser.addPositionalArgument(QStringLiteral("url"), i18n("URL to share"));
aboutData.setupCommandLine(&parser); aboutData.setupCommandLine(&parser);
parser.process(app); parser.process(app);
aboutData.processCommandLine(&parser); aboutData.processCommandLine(&parser);
if (parser.positionalArguments().count() == 1) {
urlToShare = parser.positionalArguments().constFirst();
const QString kdeconnectHandlerExecutable = QStandardPaths::findExecutable(QStringLiteral("kdeconnect-handler"), { QCoreApplication::applicationDirPath() });
if (!kdeconnectHandlerExecutable.isEmpty()) {
QProcess::startDetached(kdeconnectHandlerExecutable, { urlToShare });
return 0; // exit the app once kdeconnect-handler is started
}
}
} }
QQmlApplicationEngine engine; QQmlApplicationEngine engine;