service/mpris: preserve mpris watcher and players across reload

This commit is contained in:
outfoxxed 2024-06-02 16:18:45 -07:00
parent 9d5dd402b9
commit b1f5a5eb94
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
4 changed files with 29 additions and 11 deletions

View file

@ -43,7 +43,7 @@ To disable: `-DSOCKETS=OFF`
### Wayland ### Wayland
This feature enables wayland support. Subfeatures exist for each particular wayland integration. This feature enables wayland support. Subfeatures exist for each particular wayland integration.
WARNING: Wayland integration relies on featurs that are not part of the public Qt API and which WARNING: Wayland integration relies on features that are not part of the public Qt API and which
may break in minor releases. Updating quickshell's dependencies without ensuring without ensuring may break in minor releases. Updating quickshell's dependencies without ensuring without ensuring
that the current Qt version is supported WILL result in quickshell failing to build or misbehaving that the current Qt version is supported WILL result in quickshell failing to build or misbehaving
at runtime. at runtime.

View file

@ -156,9 +156,7 @@ void ProxyWindowBase::completeWindow() {
emit this->screenChanged(); emit this->screenChanged();
} }
bool ProxyWindowBase::deleteOnInvisible() const { bool ProxyWindowBase::deleteOnInvisible() const { return false; }
return false;
}
QQuickWindow* ProxyWindowBase::backingWindow() const { return this->window; } QQuickWindow* ProxyWindowBase::backingWindow() const { return this->window; }
QQuickItem* ProxyWindowBase::contentItem() const { return this->mContentItem; } QQuickItem* ProxyWindowBase::contentItem() const { return this->mContentItem; }

View file

@ -16,7 +16,7 @@ namespace qs::service::mpris {
Q_LOGGING_CATEGORY(logMprisWatcher, "quickshell.service.mpris.watcher", QtWarningMsg); Q_LOGGING_CATEGORY(logMprisWatcher, "quickshell.service.mpris.watcher", QtWarningMsg);
MprisWatcher::MprisWatcher(QObject* parent): QObject(parent) { MprisWatcher::MprisWatcher() {
qCDebug(logMprisWatcher) << "Starting MprisWatcher"; qCDebug(logMprisWatcher) << "Starting MprisWatcher";
auto bus = QDBusConnection::sessionBus(); auto bus = QDBusConnection::sessionBus();
@ -102,4 +102,13 @@ void MprisWatcher::registerPlayer(const QString& address) {
qCDebug(logMprisWatcher) << "Registered MprisPlayer" << address; qCDebug(logMprisWatcher) << "Registered MprisPlayer" << address;
} }
MprisWatcher* MprisWatcher::instance() {
static MprisWatcher* instance = new MprisWatcher(); // NOLINT
return instance;
}
ObjectModel<MprisPlayer>* MprisQml::players() { // NOLINT
return MprisWatcher::instance()->players();
}
} // namespace qs::service::mpris } // namespace qs::service::mpris

View file

@ -18,16 +18,12 @@ namespace qs::service::mpris {
///! Provides access to MprisPlayers. ///! Provides access to MprisPlayers.
class MprisWatcher: public QObject { class MprisWatcher: public QObject {
Q_OBJECT; Q_OBJECT;
QML_NAMED_ELEMENT(Mpris);
QML_SINGLETON;
/// All connected MPRIS players.
Q_PROPERTY(ObjectModel<MprisPlayer>* players READ players CONSTANT);
public: public:
explicit MprisWatcher(QObject* parent = nullptr);
[[nodiscard]] ObjectModel<MprisPlayer>* players(); [[nodiscard]] ObjectModel<MprisPlayer>* players();
static MprisWatcher* instance();
private slots: private slots:
void onServiceRegistered(const QString& service); void onServiceRegistered(const QString& service);
void onServiceUnregistered(const QString& service); void onServiceUnregistered(const QString& service);
@ -35,6 +31,8 @@ private slots:
void onPlayerDestroyed(QObject* object); void onPlayerDestroyed(QObject* object);
private: private:
explicit MprisWatcher();
void registerExisting(); void registerExisting();
void registerPlayer(const QString& address); void registerPlayer(const QString& address);
@ -43,4 +41,17 @@ private:
ObjectModel<MprisPlayer> readyPlayers {this}; ObjectModel<MprisPlayer> readyPlayers {this};
}; };
class MprisQml: public QObject {
Q_OBJECT;
QML_NAMED_ELEMENT(Mpris);
QML_SINGLETON;
/// All connected MPRIS players.
Q_PROPERTY(ObjectModel<MprisPlayer>* players READ players CONSTANT);
public:
explicit MprisQml(QObject* parent = nullptr): QObject(parent) {};
[[nodiscard]] ObjectModel<MprisPlayer>* players();
};
} // namespace qs::service::mpris } // namespace qs::service::mpris