Do not launch the application twice

If the application is already running, simply raise the running
instance.
This commit is contained in:
Aleix Pol
2020-11-24 02:55:14 +01:00
committed by Aleix Pol Gonzalez
parent 0c28ec4041
commit 092f8ee75d
3 changed files with 21 additions and 1 deletions

View File

@@ -59,7 +59,7 @@ if(ANDROID)
"search"
)
else()
target_link_libraries(neochat PRIVATE Qt5::Widgets ${QTKEYCHAIN_LIBRARIES})
target_link_libraries(neochat PRIVATE Qt5::Widgets KF5::DBusAddons ${QTKEYCHAIN_LIBRARIES})
endif()
install(TARGETS neochat ${KF5_INSTALL_TARGETS_DEFAULT_ARGS})

View File

@@ -11,8 +11,12 @@
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickStyle>
#include <QQuickWindow>
#include <KAboutData>
#ifndef Q_OS_ANDROID
#include <KDBusService>
#endif
#include <KLocalizedContext>
#include <KLocalizedString>
@@ -58,6 +62,10 @@ int main(int argc, char *argv[])
app.setOrganizationName("KDE");
app.setWindowIcon(QIcon(":/assets/img/icon.png"));
#ifndef Q_OS_ANDROID
KDBusService service(KDBusService::Unique);
#endif
Clipboard clipboard;
auto config = NeoChatConfig::self();
@@ -115,5 +123,16 @@ int main(int argc, char *argv[])
if (engine.rootObjects().isEmpty())
return -1;
#ifndef Q_OS_ANDROID
QObject::connect(&service, &KDBusService::activateRequested, &engine, [&engine](const QStringList &/*arguments*/, const QString &/*workingDirectory*/) {
for (auto obj : engine.rootObjects()) {
auto view = qobject_cast<QQuickWindow*>(obj);
if (view) {
view->raise();
return;
}
}
});
#endif
return app.exec();
}