49 lines
1.4 KiB
C++
49 lines
1.4 KiB
C++
#include <QApplication>
|
|
#include <QDBusConnection>
|
|
#include <QDBusConnectionInterface>
|
|
#include <QDBusServiceWatcher>
|
|
#include <QDebug>
|
|
|
|
#include "ollie_tray.h"
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
QApplication app(argc, argv);
|
|
app.setApplicationName("ollie-tray");
|
|
app.setOrganizationName("ollie");
|
|
app.setQuitOnLastWindowClosed(false);
|
|
|
|
QDBusConnection bus = QDBusConnection::sessionBus();
|
|
if (!bus.isConnected()) {
|
|
qCritical() << "Cannot connect to D-Bus session bus";
|
|
return 1;
|
|
}
|
|
|
|
OllieTray tray;
|
|
|
|
// Watch for daemon appearing/disappearing
|
|
auto *watcher = new QDBusServiceWatcher(
|
|
"org.ollie.SessionManager",
|
|
bus,
|
|
QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration,
|
|
&app);
|
|
|
|
QObject::connect(watcher, &QDBusServiceWatcher::serviceRegistered, [&]() {
|
|
qDebug() << "Daemon appeared on D-Bus";
|
|
tray.updateStatus();
|
|
});
|
|
|
|
QObject::connect(watcher, &QDBusServiceWatcher::serviceUnregistered, [&]() {
|
|
qDebug() << "Daemon disappeared from D-Bus";
|
|
tray.updateStatus();
|
|
});
|
|
|
|
if (bus.interface()->isServiceRegistered("org.ollie.SessionManager")) {
|
|
qDebug() << "ollie-tray started (daemon running)";
|
|
} else {
|
|
qDebug() << "ollie-tray started (waiting for daemon)";
|
|
}
|
|
|
|
return app.exec();
|
|
}
|