mirror of
https://github.com/spalencsar/bearwave.git
synced 2026-07-06 14:24:14 +02:00
Implement single instance check using DBus
This commit is contained in:
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Added
|
||||
|
||||
- SPDX license identifiers (GPL-3.0-or-later) to all source files.
|
||||
- Single instance application check via DBus to prevent multiple concurrent instances.
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
15
src/main.cpp
15
src/main.cpp
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusConnectionInterface>
|
||||
#include <QDBusMessage>
|
||||
#include <QIcon>
|
||||
#include <QLocale>
|
||||
#include <QQmlApplicationEngine>
|
||||
@@ -23,6 +25,18 @@ int main(int argc, char *argv[])
|
||||
QApplication::setApplicationVersion(QStringLiteral("1.0.1"));
|
||||
|
||||
QApplication app(argc, argv);
|
||||
|
||||
QDBusConnection sessionBus = QDBusConnection::sessionBus();
|
||||
if (sessionBus.isConnected() && sessionBus.interface() && sessionBus.interface()->isServiceRegistered(QStringLiteral("org.mpris.MediaPlayer2.bearwave"))) {
|
||||
QDBusMessage call = QDBusMessage::createMethodCall(
|
||||
QStringLiteral("org.mpris.MediaPlayer2.bearwave"),
|
||||
QStringLiteral("/org/mpris/MediaPlayer2"),
|
||||
QStringLiteral("org.mpris.MediaPlayer2"),
|
||||
QStringLiteral("Raise")
|
||||
);
|
||||
sessionBus.call(call);
|
||||
return 0;
|
||||
}
|
||||
app.setWindowIcon(QIcon::fromTheme(QStringLiteral("de.nerdbear.bearwave")));
|
||||
app.setQuitOnLastWindowClosed(false);
|
||||
|
||||
@@ -45,7 +59,6 @@ int main(int argc, char *argv[])
|
||||
Q_UNUSED(controlAdaptor)
|
||||
Q_UNUSED(notificationManager)
|
||||
|
||||
QDBusConnection sessionBus = QDBusConnection::sessionBus();
|
||||
sessionBus.registerObject(QStringLiteral("/org/mpris/MediaPlayer2"), &backend, QDBusConnection::ExportAdaptors);
|
||||
sessionBus.registerService(QStringLiteral("org.mpris.MediaPlayer2.bearwave"));
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ bool MprisRootAdaptor::canSetFullscreen() const
|
||||
|
||||
bool MprisRootAdaptor::canRaise() const
|
||||
{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MprisRootAdaptor::hasTrackList() const
|
||||
@@ -94,6 +94,7 @@ QStringList MprisRootAdaptor::supportedMimeTypes() const
|
||||
|
||||
void MprisRootAdaptor::Raise()
|
||||
{
|
||||
emit m_backend->raiseRequested();
|
||||
}
|
||||
|
||||
void MprisRootAdaptor::Quit()
|
||||
|
||||
@@ -20,6 +20,15 @@ ApplicationWindow {
|
||||
root.hide()
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: backend
|
||||
function onRaiseRequested() {
|
||||
root.show()
|
||||
root.raise()
|
||||
root.requestActivate()
|
||||
}
|
||||
}
|
||||
|
||||
Platform.SystemTrayIcon {
|
||||
id: systray
|
||||
visible: true
|
||||
|
||||
@@ -83,6 +83,7 @@ signals:
|
||||
void resumeStateChanged();
|
||||
void filterQueryChanged();
|
||||
void currentStationChanged();
|
||||
void raiseRequested();
|
||||
|
||||
private slots:
|
||||
void onStationsLoaded(const QList<RadioStation*> &stations);
|
||||
|
||||
Reference in New Issue
Block a user