diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 613c738d7..227ccebfb 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -1,11 +1,5 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kdeconnect-core\") -set(KDECONNECT_PRIVATE_DBUS_ADDR unix:tmpdir=/tmp) -if(WIN32) - set(KDECONNECT_PRIVATE_DBUS_ADDR tcp:host=localhost,port=0) -endif() -set(KDECONNECT_PRIVATE_DBUS_NAME DBusKDEConnectOnly) -configure_file(dbushelper.h.in ${CMAKE_CURRENT_BINARY_DIR}/dbushelper.h) option(MDNS_ENABLED "Use MDNS for device discovery" ON) diff --git a/core/dbushelper.cpp b/core/dbushelper.cpp index 9a9f641f4..0e770118a 100644 --- a/core/dbushelper.cpp +++ b/core/dbushelper.cpp @@ -18,28 +18,15 @@ #include "kdeconnectconfig.h" #ifdef Q_OS_MAC +#include #include #include +#include +#include #endif namespace DBusHelper { -#ifdef Q_OS_MAC -class DBusInstancePrivate -{ -public: - DBusInstancePrivate(); - ~DBusInstancePrivate(); - - void launchDBusDaemon(); - void closeDBusDaemon(); - -private: - QProcess *m_dbusProcess; -}; - -static DBusInstancePrivate dbusInstance; -#endif void filterNonExportableCharacters(QString &s) { @@ -48,35 +35,56 @@ void filterNonExportableCharacters(QString &s) } #ifdef Q_OS_MAC -void launchDBusDaemon() + +const QString PrivateDbusAddr = QStringLiteral("unix:tmpdir=/tmp"); +const QString PrivateDBusAddressPath = QStringLiteral("/tmp/private_dbus_address"); +const QString DBUS_LAUNCHD_SESSION_BUS_SOCKET = QStringLiteral("DBUS_LAUNCHD_SESSION_BUS_SOCKET"); + +QProcess *m_dbusProcess = nullptr; + +void setLaunchctlEnv(const QString &env) { - dbusInstance.launchDBusDaemon(); - qAddPostRoutine(closeDBusDaemon); + QProcess setLaunchdDBusEnv; + setLaunchdDBusEnv.setProgram(QStringLiteral("launchctl")); + setLaunchdDBusEnv.setArguments({QStringLiteral("setenv"), DBUS_LAUNCHD_SESSION_BUS_SOCKET, env}); + setLaunchdDBusEnv.start(); + setLaunchdDBusEnv.waitForFinished(); } -void closeDBusDaemon() +void unsetLaunchctlEnv() { - dbusInstance.closeDBusDaemon(); -} - -void macosUnsetLaunchctlEnv() -{ - // Unset Launchd env QProcess unsetLaunchdDBusEnv; unsetLaunchdDBusEnv.setProgram(QStringLiteral("launchctl")); - unsetLaunchdDBusEnv.setArguments({QStringLiteral("unsetenv"), QStringLiteral(KDECONNECT_SESSION_DBUS_LAUNCHD_ENV)}); + unsetLaunchdDBusEnv.setArguments({QStringLiteral("unsetenv"), DBUS_LAUNCHD_SESSION_BUS_SOCKET}); unsetLaunchdDBusEnv.start(); unsetLaunchdDBusEnv.waitForFinished(); } -void DBusInstancePrivate::launchDBusDaemon() +void stopDBusDaemon() { - // Kill old dbus daemon - if (m_dbusProcess != nullptr) - closeDBusDaemon(); + if (m_dbusProcess != nullptr) { + m_dbusProcess->terminate(); + m_dbusProcess->waitForFinished(); + delete m_dbusProcess; + m_dbusProcess = nullptr; + unsetLaunchctlEnv(); + } +} - // Start dbus daemon - m_dbusProcess = new QProcess(); +int startDBusDaemon() +{ + if (m_dbusProcess) { + return 0; + } + + qAddPostRoutine(stopDBusDaemon); + + // Unset launchctl env and private dbus addr file, avoid block + unsetLaunchctlEnv(); + QFile privateDBusAddressFile(PrivateDBusAddressPath); + if (privateDBusAddressFile.exists()) { + privateDBusAddressFile.resize(0); + } QString kdeconnectDBusConfiguration; QString dbusDaemonExecutable = QStandardPaths::findExecutable(QStringLiteral("dbus-daemon"), {QCoreApplication::applicationDirPath()}); @@ -87,60 +95,70 @@ void DBusInstancePrivate::launchDBusDaemon() dbusDaemonExecutable = QLatin1String(qgetenv("craftRoot")) + QLatin1String("/../bin/dbus-daemon"); kdeconnectDBusConfiguration = QLatin1String(qgetenv("craftRoot")) + QLatin1String("/../share/dbus-1/session.conf"); } + m_dbusProcess = new QProcess(); m_dbusProcess->setProgram(dbusDaemonExecutable); m_dbusProcess->setArguments({QStringLiteral("--print-address"), QStringLiteral("--nofork"), - QStringLiteral("--config-file=") + kdeconnectDBusConfiguration, - QStringLiteral("--address=") + QStringLiteral(KDECONNECT_PRIVATE_DBUS_ADDR)}); + QStringLiteral("--config-file"), + kdeconnectDBusConfiguration, + QStringLiteral("--address"), + PrivateDbusAddr}); m_dbusProcess->setWorkingDirectory(QCoreApplication::applicationDirPath()); - m_dbusProcess->setStandardOutputFile(KdeConnectConfig::instance().privateDBusAddressPath()); - m_dbusProcess->setStandardErrorFile(QProcess::nullDevice()); + m_dbusProcess->setStandardOutputFile(PrivateDBusAddressPath); m_dbusProcess->start(); - m_dbusProcess->waitForStarted(); // Avoid potential racing condition + m_dbusProcess->waitForStarted(); + + QFile dbusAddressFile(PrivateDBusAddressPath); + + if (!dbusAddressFile.open(QFile::ReadOnly | QFile::Text)) { + qCCritical(KDECONNECT_CORE) << "Private DBus enabled but error read private dbus address conf"; + return -1; + } + + QTextStream in(&dbusAddressFile); + + qCDebug(KDECONNECT_CORE) << "Waiting for private dbus"; + + int retry = 0; + QString addr = in.readLine(); + while (addr.length() == 0 && retry < 150) { + qCDebug(KDECONNECT_CORE) << "Retry reading private DBus address"; + QThread::msleep(100); + retry++; + addr = in.readLine(); // Read until first not empty line + } + + if (addr.length() == 0) { + qCCritical(KDECONNECT_CORE) << "Private DBus enabled but read private dbus address failed"; + return -2; + } + + qCDebug(KDECONNECT_CORE) << "Private dbus address: " << addr; -#ifdef Q_OS_MAC - // Set launchctl env - QString privateDBusAddress = KdeConnectConfig::instance().privateDBusAddress(); QRegularExpressionMatch path; - if (privateDBusAddress.contains(QRegularExpression(QStringLiteral("path=(?/tmp/dbus-[A-Za-z0-9]+)")), &path)) { - qCDebug(KDECONNECT_CORE) << "DBus address: " << path.captured(QStringLiteral("path")); - QProcess setLaunchdDBusEnv; - setLaunchdDBusEnv.setProgram(QStringLiteral("launchctl")); - setLaunchdDBusEnv.setArguments({QStringLiteral("setenv"), QStringLiteral(KDECONNECT_SESSION_DBUS_LAUNCHD_ENV), path.captured(QStringLiteral("path"))}); - setLaunchdDBusEnv.start(); - setLaunchdDBusEnv.waitForFinished(); - } else { - qCDebug(KDECONNECT_CORE) << "Cannot get dbus address"; + if (!addr.contains(QRegularExpression(QStringLiteral("path=(?/tmp/dbus-[A-Za-z0-9]+)")), &path)) { + qCCritical(KDECONNECT_CORE) << "Fail to parse dbus address"; + return -3; } -#endif -} -void DBusInstancePrivate::closeDBusDaemon() -{ - if (m_dbusProcess != nullptr) { - m_dbusProcess->terminate(); - m_dbusProcess->waitForFinished(); - delete m_dbusProcess; - m_dbusProcess = nullptr; - - QFile privateDBusAddressFile(KdeConnectConfig::instance().privateDBusAddressPath()); - - if (privateDBusAddressFile.exists()) - privateDBusAddressFile.resize(0); - - macosUnsetLaunchctlEnv(); + QString dbusAddress = path.captured(QStringLiteral("path")); + qCDebug(KDECONNECT_CORE) << "DBus address: " << dbusAddress; + if (dbusAddress.isEmpty()) { + qCCritical(KDECONNECT_CORE) << "Fail to extract dbus address"; + return -4; } + + setLaunchctlEnv(dbusAddress); + + if (!QDBusConnection::sessionBus().isConnected()) { + qCCritical(KDECONNECT_CORE) << "Invalid env:" << dbusAddress; + return -5; + } + + qCDebug(KDECONNECT_CORE) << "Private D-Bus daemon launched and connected."; + return 0; } -DBusInstancePrivate::DBusInstancePrivate() - : m_dbusProcess(nullptr) -{ -} +#endif // Q_OS_MAC -DBusInstancePrivate::~DBusInstancePrivate() -{ - closeDBusDaemon(); -} -#endif - -} +} // namespace DBusHelper diff --git a/core/dbushelper.h b/core/dbushelper.h new file mode 100644 index 000000000..be20d435a --- /dev/null +++ b/core/dbushelper.h @@ -0,0 +1,20 @@ +/** + * SPDX-FileCopyrightText: 2024 Albert Vaca + * + * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL + */ + +#pragma once + +#include +#include + +#include "kdeconnectcore_export.h" + +namespace DBusHelper +{ +void KDECONNECTCORE_EXPORT filterNonExportableCharacters(QString &s); +#ifdef Q_OS_MAC +int KDECONNECTCORE_EXPORT startDBusDaemon(); +#endif +} diff --git a/core/dbushelper.h.in b/core/dbushelper.h.in deleted file mode 100644 index 034359818..000000000 --- a/core/dbushelper.h.in +++ /dev/null @@ -1,29 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2014 Albert Vaca - * - * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL - */ - -#ifndef KDECONNECT_DBUSHELPER_H -#define KDECONNECT_DBUSHELPER_H -#include -#include - -#include "kdeconnectcore_export.h" - -#define KDECONNECT_PRIVATE_DBUS_ADDR "${KDECONNECT_PRIVATE_DBUS_ADDR}" -#define KDECONNECT_PRIVATE_DBUS_NAME "${KDECONNECT_PRIVATE_DBUS_NAME}" - -#define KDECONNECT_SESSION_DBUS_LAUNCHD_ENV "DBUS_LAUNCHD_SESSION_BUS_SOCKET" - -namespace DBusHelper { - void KDECONNECTCORE_EXPORT filterNonExportableCharacters(QString& s); - -#ifdef Q_OS_MAC - void KDECONNECTCORE_EXPORT launchDBusDaemon(); - void KDECONNECTCORE_EXPORT closeDBusDaemon(); - void KDECONNECTCORE_EXPORT macosUnsetLaunchctlEnv(); -#endif -} - -#endif diff --git a/core/kdeconnectconfig.cpp b/core/kdeconnectconfig.cpp index 9e4e54a92..8fc419e61 100644 --- a/core/kdeconnectconfig.cpp +++ b/core/kdeconnectconfig.cpp @@ -35,10 +35,6 @@ struct KdeConnectConfigPrivate { QSettings *m_config; QSettings *m_trustedDevices; - -#ifdef Q_OS_MAC - QString m_privateDBusAddress; // Private DBus Address cache -#endif }; static QString getDefaultDeviceName() @@ -381,48 +377,3 @@ void KdeConnectConfig::generateCertificate(const QString &certPath) Daemon::instance()->reportError(QStringLiteral("KDE Connect"), i18n("Could not store certificate file: %1", certPath)); } } - -#ifdef Q_OS_MAC -QString KdeConnectConfig::privateDBusAddressPath() -{ - return baseConfigDir().absoluteFilePath(QStringLiteral("private_dbus_address")); -} - -QString KdeConnectConfig::privateDBusAddress() -{ - if (d->m_privateDBusAddress.length() != 0) - return d->m_privateDBusAddress; - - QString dbusAddressPath = privateDBusAddressPath(); - QFile dbusAddressFile(dbusAddressPath); - - if (!dbusAddressFile.open(QFile::ReadOnly | QFile::Text)) { - qCCritical(KDECONNECT_CORE) << "Private DBus enabled but error read private dbus address conf"; - exit(1); - } - - QTextStream in(&dbusAddressFile); - - qCDebug(KDECONNECT_CORE) << "Waiting for private dbus"; - - int retry = 0; - QString addr = in.readLine(); - while (addr.length() == 0 && retry < 5) { - qCDebug(KDECONNECT_CORE) << "Retry reading private DBus address after 3s"; - QThread::sleep(3); - retry++; - addr = in.readLine(); // Read until first not empty line - } - - if (addr.length() == 0) { - qCCritical(KDECONNECT_CORE) << "Private DBus enabled but read private dbus address failed"; - exit(1); - } - - qCDebug(KDECONNECT_CORE) << "Private dbus address: " << addr; - - d->m_privateDBusAddress = addr; - - return addr; -} -#endif diff --git a/core/kdeconnectconfig.h b/core/kdeconnectconfig.h index 3cc426ef2..2137e2170 100644 --- a/core/kdeconnectconfig.h +++ b/core/kdeconnectconfig.h @@ -61,13 +61,6 @@ public: QDir deviceConfigDir(const QString &deviceId); QDir pluginConfigDir(const QString &deviceId, const QString &pluginName); // Used by KdeConnectPluginConfig -#ifdef Q_OS_MAC - /* - * Get private DBus Address when use private DBus - */ - QString privateDBusAddressPath(); - QString privateDBusAddress(); -#endif private: KdeConnectConfig(); diff --git a/daemon/kdeconnectd.cpp b/daemon/kdeconnectd.cpp index 6bf9d0fad..49578eb2b 100644 --- a/daemon/kdeconnectd.cpp +++ b/daemon/kdeconnectd.cpp @@ -86,19 +86,10 @@ int main(int argc, char *argv[]) QCommandLineParser parser; QCommandLineOption replaceOption({QStringLiteral("replace")}, i18n("Replace an existing instance")); parser.addOption(replaceOption); -#ifdef Q_OS_MAC - QCommandLineOption macosPrivateDBusOption({QStringLiteral("use-private-dbus")}, - i18n("Launch a private D-Bus daemon with kdeconnectd (macOS test-purpose only)")); - parser.addOption(macosPrivateDBusOption); -#endif aboutData.setupCommandLine(&parser); parser.process(app); -#ifdef Q_OS_MAC - if (parser.isSet(macosPrivateDBusOption)) { - DBusHelper::launchDBusDaemon(); - } -#endif + aboutData.processCommandLine(&parser); if (parser.isSet(replaceOption)) { auto message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), diff --git a/indicator/indicatorhelper.cpp b/indicator/indicatorhelper.cpp index 312c31b16..9b8e59209 100644 --- a/indicator/indicatorhelper.cpp +++ b/indicator/indicatorhelper.cpp @@ -12,23 +12,16 @@ IndicatorHelper::IndicatorHelper() { } + IndicatorHelper::~IndicatorHelper() { } -void IndicatorHelper::preInit() -{ -} - -void IndicatorHelper::postInit() -{ -} - void IndicatorHelper::iconPathHook() { } -int IndicatorHelper::daemonHook(QProcess & /*kdeconnectd*/) +int IndicatorHelper::startDaemon() { return 0; } diff --git a/indicator/indicatorhelper.h b/indicator/indicatorhelper.h index f2817959d..6e9e614fb 100644 --- a/indicator/indicatorhelper.h +++ b/indicator/indicatorhelper.h @@ -7,9 +7,6 @@ #ifndef INDICATORHELPER_H #define INDICATORHELPER_H -#include -#include - #ifdef Q_OS_WIN #include #else @@ -17,6 +14,7 @@ #endif #ifdef Q_OS_WIN +#include #include namespace processes { @@ -32,19 +30,12 @@ const QString kdeconnect_sms = QStringLiteral("kdeconnect-sms.exe"); class IndicatorHelper { public: -#ifdef Q_OS_WIN - IndicatorHelper(const QUrl &indicatorUrl); -#else IndicatorHelper(); -#endif ~IndicatorHelper(); - void preInit(); - void postInit(); - void iconPathHook(); - int daemonHook(QProcess &kdeconnectd); + int startDaemon(); #ifdef Q_OS_WIN void systrayIconHook(QSystemTrayIcon &systray); @@ -53,11 +44,9 @@ public: #endif private: -#ifdef Q_OS_MAC - QSplashScreen *m_splashScreen; -#endif - #ifdef Q_OS_WIN + QProcess kdeconnectd; + /** * Terminate processes of KDE Connect like kdeconnectd.exe and dbus-daemon.exe * diff --git a/indicator/indicatorhelper_mac.cpp b/indicator/indicatorhelper_mac.cpp index c22bc6cef..d8ea503f0 100644 --- a/indicator/indicatorhelper_mac.cpp +++ b/indicator/indicatorhelper_mac.cpp @@ -4,55 +4,29 @@ * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ +#include "indicatorhelper.h" + +#include #include #include #include #include #include +#include #include #include -#include - -#include - -#include "indicatorhelper.h" - #include "serviceregister_mac.h" - +#include #include IndicatorHelper::IndicatorHelper() { registerServices(); - - // Use a hardcoded QPixmap because QIcon::fromTheme will instantiate a QPlatformTheme theme - // which could try to use DBus before we have started it and cache an invalid DBus session - // in QDBusConnectionManager - const QString iconPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("kdeconnect-icons"), QStandardPaths::LocateDirectory); - QPixmap splashPixmap(iconPath + QStringLiteral("/hicolor/scalable/apps/kdeconnect.svg")); - m_splashScreen = new QSplashScreen(splashPixmap); - - // Icon is white, set the text color to black - m_splashScreen->showMessage(i18n("Launching") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::black); - m_splashScreen->show(); } IndicatorHelper::~IndicatorHelper() { - if (m_splashScreen != nullptr) { - delete m_splashScreen; - m_splashScreen = nullptr; - } -} - -void IndicatorHelper::preInit() -{ -} - -void IndicatorHelper::postInit() -{ - m_splashScreen->finish(nullptr); } void IndicatorHelper::iconPathHook() @@ -65,86 +39,26 @@ void IndicatorHelper::iconPathHook() } } -int IndicatorHelper::daemonHook(QProcess &kdeconnectd) +int IndicatorHelper::startDaemon() { - // This flag marks whether a session DBus daemon is installed and run - bool hasUsableSessionBus = true; - // Use another bus instance for detecting, avoid session bus cache in Qt - if (!QDBusConnection::connectToBus(QDBusConnection::SessionBus, QStringLiteral("kdeconnect-test-client")).isConnected()) { - qDebug() << "Default session bus not detected, will use private D-Bus."; - - // Unset launchctl env and private dbus addr file, avoid block - DBusHelper::macosUnsetLaunchctlEnv(); - QFile privateDBusAddressFile(KdeConnectConfig::instance().privateDBusAddressPath()); - if (privateDBusAddressFile.exists()) - privateDBusAddressFile.resize(0); - - // Update session bus usability state - hasUsableSessionBus = false; - } - - // Start daemon - m_splashScreen->showMessage(i18n("Launching daemon") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::black); - - // Here we will try to bring our private session D-Bus - if (!hasUsableSessionBus) { - qDebug() << "Launching private session D-Bus."; - DBusHelper::macosUnsetLaunchctlEnv(); - DBusHelper::launchDBusDaemon(); - // Wait for dbus daemon env - QProcess getLaunchdDBusEnv; - m_splashScreen->showMessage(i18n("Waiting D-Bus") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::black); - getLaunchdDBusEnv.setProgram(QStringLiteral("launchctl")); - getLaunchdDBusEnv.setArguments({QStringLiteral("getenv"), QStringLiteral(KDECONNECT_SESSION_DBUS_LAUNCHD_ENV)}); - getLaunchdDBusEnv.start(); - getLaunchdDBusEnv.waitForFinished(); - - QString launchdDBusEnv = QString::fromLocal8Bit(getLaunchdDBusEnv.readAllStandardOutput()); - - if (!launchdDBusEnv.isEmpty() && QDBusConnection::sessionBus().isConnected()) { - qDebug() << "Private D-Bus daemon launched and connected."; - hasUsableSessionBus = true; - } else if (!launchdDBusEnv.isEmpty()) { - // Show a warning and exit - qCritical() << "Invalid " << KDECONNECT_SESSION_DBUS_LAUNCHD_ENV << "env: \"" << launchdDBusEnv << "\""; - - QMessageBox::critical(nullptr, - i18n("KDE Connect"), - i18n("Cannot connect to DBus\n" - "KDE Connect will quit"), - QMessageBox::Abort, - QMessageBox::Abort); - // End the program - return -1; - } else { - // Show a warning and exit - qCritical() << "Fail to get launchctl" << KDECONNECT_SESSION_DBUS_LAUNCHD_ENV << "env"; - - QMessageBox::critical(nullptr, - i18n("KDE Connect"), - i18n("Cannot connect to DBus\n" - "KDE Connect will quit"), - QMessageBox::Abort, - QMessageBox::Abort); - return -2; - } - - // After D-Bus setting up, everything should go fine - QIcon kdeconnectIcon = QIcon::fromTheme(QStringLiteral("kdeconnect")); - m_splashScreen->setPixmap(QPixmap(kdeconnectIcon.pixmap(256, 256))); + int dbusStatus = DBusHelper::startDBusDaemon(); + if (dbusStatus) { + QMessageBox::critical(nullptr, + i18n("KDE Connect"), + i18n("Cannot connect to DBus\n" + "KDE Connect will quit"), + QMessageBox::Abort, + QMessageBox::Abort); + QApplication::exit(dbusStatus); } // Start kdeconnectd, the daemon will not duplicate when there is already one - if (QString daemon = QCoreApplication::applicationDirPath() + QLatin1String("/kdeconnectd"); QFile::exists(daemon)) { - kdeconnectd.setProgram(daemon); - } else { + QString daemonPath = QCoreApplication::applicationDirPath() + QLatin1String("/kdeconnectd"); + if (!QFile::exists(daemonPath)) { QMessageBox::critical(nullptr, i18n("KDE Connect"), i18n("Cannot find kdeconnectd"), QMessageBox::Abort, QMessageBox::Abort); - return -1; + QApplication::exit(-10); } - kdeconnectd.startDetached(); - - m_splashScreen->showMessage(i18n("Loading modules") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::white); - + QProcess::startDetached(daemonPath); return 0; } diff --git a/indicator/indicatorhelper_win.cpp b/indicator/indicatorhelper_win.cpp index 285fbec00..ee534a8e2 100644 --- a/indicator/indicatorhelper_win.cpp +++ b/indicator/indicatorhelper_win.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ +#include #include #include #include @@ -14,17 +15,15 @@ #include #include - #include #include #include "indicator_debug.h" #include "indicatorhelper.h" - winrt::Windows::UI::ViewManagement::UISettings uiSettings; -IndicatorHelper::IndicatorHelper(const QUrl &indicatorUrl) - : m_indicatorUrl(indicatorUrl) +IndicatorHelper::IndicatorHelper() + : m_indicatorUrl(QUrl::fromLocalFile(QApplication::applicationDirPath())) { uiSettings = winrt::Windows::UI::ViewManagement::UISettings(); } @@ -39,14 +38,6 @@ IndicatorHelper::~IndicatorHelper() this->terminateProcess(processes::kdeconnect_daemon, m_indicatorUrl); } -void IndicatorHelper::preInit() -{ -} - -void IndicatorHelper::postInit() -{ -} - void IndicatorHelper::iconPathHook() { // FIXME: This doesn't seem to be enough for QIcon::fromTheme to find the icons, so we still have to use the full path when setting the icon @@ -58,7 +49,7 @@ void IndicatorHelper::iconPathHook() } } -int IndicatorHelper::daemonHook(QProcess &kdeconnectd) +int IndicatorHelper::startDaemon() { kdeconnectd.start(processes::kdeconnect_daemon, QStringList()); return 0; diff --git a/indicator/main.cpp b/indicator/main.cpp index 9a61634a8..619dd1bda 100644 --- a/indicator/main.cpp +++ b/indicator/main.cpp @@ -49,6 +49,10 @@ int main(int argc, char **argv) QIcon::setFallbackThemeName(QStringLiteral("breeze")); QApplication app(argc, argv); + + IndicatorHelper helper; + helper.startDaemon(); + KAboutData about(QStringLiteral("kdeconnect-indicator"), i18n("KDE Connect Indicator"), QStringLiteral(KDECONNECT_VERSION_STRING), @@ -62,20 +66,8 @@ int main(int argc, char **argv) #ifdef Q_OS_WIN KColorSchemeManager manager; QApplication::setStyle(QStringLiteral("breeze")); - IndicatorHelper helper(QUrl::fromLocalFile(qApp->applicationDirPath())); -#else - IndicatorHelper helper; #endif - helper.preInit(); - - // Run Daemon initialization step - // When run from macOS app bundle, D-Bus call should be later than kdeconnectd and D-Bus daemon - QProcess kdeconnectd; - if (helper.daemonHook(kdeconnectd)) { - return -1; - } - KDBusService dbusService(KDBusService::Unique); // Trigger loading the KIconLoader plugin @@ -130,7 +122,6 @@ int main(int argc, char **argv) } // Add quit menu #if defined Q_OS_MAC - menu->addAction(i18n("Quit"), []() { auto message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect.daemon"), QStringLiteral("/MainApplication"), @@ -194,8 +185,5 @@ int main(int argc, char **argv) app.setQuitOnLastWindowClosed(false); - // Finish init - helper.postInit(); - return app.exec(); }