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