2015-02-24 06:12:45 +00:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2014 Yuri Samoilenko <kinnalru@gmail.com>
|
2015-02-24 06:12:45 +00:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2015-02-24 06:12:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QApplication>
|
2019-04-27 22:03:24 +01:00
|
|
|
#include <QCommandLineOption>
|
|
|
|
#include <QCommandLineParser>
|
|
|
|
#include <QDBusMessage>
|
2019-08-19 19:57:45 +01:00
|
|
|
#include <QIcon>
|
2020-01-17 00:33:03 +00:00
|
|
|
#include <QProcess>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QSessionManager>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QTimer>
|
2015-02-24 06:12:45 +00:00
|
|
|
|
2023-06-27 22:50:47 +01:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#include <Windows.h>
|
|
|
|
#endif
|
|
|
|
|
2019-01-25 21:32:34 +00:00
|
|
|
#include <KAboutData>
|
2024-07-31 21:44:55 +01:00
|
|
|
#include <KCrash>
|
2015-02-24 06:12:45 +00:00
|
|
|
#include <KDBusService>
|
2023-07-16 15:20:34 +01:00
|
|
|
#include <KIO/Global>
|
2023-12-27 13:37:29 +00:00
|
|
|
#include <KIO/JobTracker>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KNotification>
|
2022-05-12 02:59:56 +01:00
|
|
|
#include <KWindowSystem>
|
2015-02-24 06:12:45 +00:00
|
|
|
|
2019-06-09 16:28:49 +01:00
|
|
|
#include <dbushelper.h>
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
#include "core/backends/pairinghandler.h"
|
2024-09-12 23:44:38 +01:00
|
|
|
#include "desktop_daemon.h"
|
2015-03-24 11:26:37 +00:00
|
|
|
#include "core/device.h"
|
2022-05-12 02:59:56 +01:00
|
|
|
#include "core/openconfig.h"
|
2015-03-10 04:59:36 +00:00
|
|
|
#include "kdeconnect-version.h"
|
2020-05-26 17:55:47 +01:00
|
|
|
#include "kdeconnectd_debug.h"
|
2019-03-11 12:37:15 +00:00
|
|
|
|
2019-07-19 16:12:49 +01:00
|
|
|
// Copied from plasma-workspace/libkworkspace/kworkspace.cpp
|
|
|
|
static void detectPlatform(int argc, char **argv)
|
|
|
|
{
|
|
|
|
if (qEnvironmentVariableIsSet("QT_QPA_PLATFORM")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < argc; i++) {
|
2022-09-10 22:23:52 +01:00
|
|
|
if (qstrcmp(argv[i], "-platform") == 0 || qstrcmp(argv[i], "--platform") == 0 || QByteArray(argv[i]).startsWith("-platform=")
|
|
|
|
|| QByteArray(argv[i]).startsWith("--platform=")) {
|
2019-07-19 16:12:49 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const QByteArray sessionType = qgetenv("XDG_SESSION_TYPE");
|
|
|
|
if (sessionType.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2023-07-21 10:22:47 +01:00
|
|
|
if (qstrcmp(sessionType.constData(), "wayland") == 0) {
|
2019-07-19 16:12:49 +01:00
|
|
|
qputenv("QT_QPA_PLATFORM", "wayland");
|
2023-07-21 10:22:47 +01:00
|
|
|
} else if (qstrcmp(sessionType.constData(), "x11") == 0) {
|
2019-07-19 16:12:49 +01:00
|
|
|
qputenv("QT_QPA_PLATFORM", "xcb");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
int main(int argc, char *argv[])
|
2015-02-24 06:12:45 +00:00
|
|
|
{
|
2023-06-27 22:50:47 +01:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
// If ran from a console, redirect the output there
|
|
|
|
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
|
|
|
|
freopen("CONOUT$", "w", stdout);
|
|
|
|
freopen("CONOUT$", "w", stderr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-18 16:26:16 +01:00
|
|
|
detectPlatform(argc, argv);
|
2023-07-21 09:16:47 +01:00
|
|
|
QGuiApplication::setQuitLockEnabled(false);
|
2019-07-19 16:12:49 +01:00
|
|
|
|
2015-02-24 06:12:45 +00:00
|
|
|
QApplication app(argc, argv);
|
2022-09-10 22:23:52 +01:00
|
|
|
KAboutData aboutData(QStringLiteral("kdeconnect.daemon"),
|
|
|
|
i18n("KDE Connect Daemon"),
|
|
|
|
QStringLiteral(KDECONNECT_VERSION_STRING),
|
|
|
|
i18n("KDE Connect Daemon"),
|
|
|
|
KAboutLicense::GPL);
|
2019-01-25 21:32:34 +00:00
|
|
|
KAboutData::setApplicationData(aboutData);
|
2015-02-24 06:12:45 +00:00
|
|
|
app.setQuitOnLastWindowClosed(false);
|
|
|
|
|
2024-07-31 21:44:55 +01:00
|
|
|
KCrash::initialize();
|
|
|
|
|
2019-04-27 22:03:24 +01:00
|
|
|
QCommandLineParser parser;
|
|
|
|
QCommandLineOption replaceOption({QStringLiteral("replace")}, i18n("Replace an existing instance"));
|
|
|
|
parser.addOption(replaceOption);
|
2023-06-07 17:25:34 +01:00
|
|
|
#ifdef Q_OS_MAC
|
2022-04-12 06:40:03 +01:00
|
|
|
QCommandLineOption macosPrivateDBusOption({QStringLiteral("use-private-dbus")},
|
2022-09-10 22:23:52 +01:00
|
|
|
i18n("Launch a private D-Bus daemon with kdeconnectd (macOS test-purpose only)"));
|
2022-04-12 06:40:03 +01:00
|
|
|
parser.addOption(macosPrivateDBusOption);
|
2023-06-07 17:25:34 +01:00
|
|
|
#endif
|
2019-04-27 22:03:24 +01:00
|
|
|
aboutData.setupCommandLine(&parser);
|
|
|
|
|
|
|
|
parser.process(app);
|
2022-04-12 06:40:03 +01:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
if (parser.isSet(macosPrivateDBusOption)) {
|
|
|
|
DBusHelper::launchDBusDaemon();
|
|
|
|
}
|
|
|
|
#endif
|
2019-04-27 22:03:24 +01:00
|
|
|
aboutData.processCommandLine(&parser);
|
|
|
|
if (parser.isSet(replaceOption)) {
|
2019-07-20 18:53:17 +01:00
|
|
|
auto message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"),
|
2022-09-10 22:23:52 +01:00
|
|
|
QStringLiteral("/MainApplication"),
|
|
|
|
QStringLiteral("org.qtproject.Qt.QCoreApplication"),
|
|
|
|
QStringLiteral("quit"));
|
|
|
|
QDBusConnection::sessionBus().call(message); // deliberately block until it's done, so we register the name after the app quits
|
2019-04-27 22:03:24 +01:00
|
|
|
}
|
|
|
|
|
2015-02-24 06:12:45 +00:00
|
|
|
KDBusService dbusService(KDBusService::Unique);
|
|
|
|
|
2019-05-05 13:58:11 +01:00
|
|
|
DesktopDaemon daemon;
|
2016-06-15 19:37:42 +01:00
|
|
|
|
2023-07-11 19:41:36 +01:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
// make sure indicator shows up in the tray whenever daemon is spawned
|
2023-07-21 13:53:23 +01:00
|
|
|
QProcess::startDetached(QStringLiteral("kdeconnect-indicator.exe"), QStringList());
|
2023-07-11 19:41:36 +01:00
|
|
|
#endif
|
|
|
|
|
2019-06-02 15:01:42 +01:00
|
|
|
// kdeconnectd is autostarted, so disable session management to speed up startup
|
|
|
|
auto disableSessionManagement = [](QSessionManager &sm) {
|
|
|
|
sm.setRestartHint(QSessionManager::RestartNever);
|
|
|
|
};
|
|
|
|
QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement);
|
|
|
|
QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement);
|
|
|
|
|
2023-11-20 18:09:13 +00:00
|
|
|
qSetMessagePattern(QStringLiteral("%{time} %{category}: %{message}"));
|
|
|
|
|
2015-02-24 06:12:45 +00:00
|
|
|
return app.exec();
|
|
|
|
}
|