@@ -1,11 +1,8 @@
|
||||
#include "services/dbus/mpris.hpp"
|
||||
#include "services/dbus/messages.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include "helpers/string.hpp"
|
||||
#include "services/notificationController.hpp"
|
||||
|
||||
#include "giomm/dbusconnection.h"
|
||||
#include "giomm/dbusproxy.h"
|
||||
@@ -17,6 +14,11 @@ MprisController::MprisController() {
|
||||
sigc::mem_fun(*this, &MprisController::on_bus_connected));
|
||||
}
|
||||
|
||||
sigc::signal<void(const MprisPlayer2Message &)> &
|
||||
MprisController::signal_mpris_updated() {
|
||||
return mprisUpdatedSignal;
|
||||
}
|
||||
|
||||
void MprisController::on_bus_connected(const Glib::RefPtr<Gio::AsyncResult> &result) {
|
||||
if (!result) {
|
||||
std::cerr << "DBus Connection Error: null async result" << std::endl;
|
||||
@@ -38,7 +40,7 @@ void MprisController::on_bus_connected(const Glib::RefPtr<Gio::AsyncResult> &res
|
||||
std::cout << "Connected to: " << player_bus_name << std::endl;
|
||||
|
||||
// uncomment if launch notification on start
|
||||
launchNotification();
|
||||
signalNotification();
|
||||
|
||||
m_proxy->signal_properties_changed().connect(
|
||||
sigc::mem_fun(*this, &MprisController::on_properties_changed));
|
||||
@@ -49,7 +51,7 @@ void MprisController::on_bus_connected(const Glib::RefPtr<Gio::AsyncResult> &res
|
||||
}
|
||||
}
|
||||
|
||||
void MprisController::launchNotification() {
|
||||
void MprisController::signalNotification() {
|
||||
if (!m_proxy) {
|
||||
return;
|
||||
}
|
||||
@@ -93,8 +95,6 @@ void MprisController::launchNotification() {
|
||||
artwork_url = art_var.get();
|
||||
}
|
||||
|
||||
auto notifactionController = NotificationController::getInstance();
|
||||
|
||||
MprisPlayer2Message mpris;
|
||||
mpris.title = StringHelper::trimToSize(title, 30);
|
||||
mpris.artist = StringHelper::trimToSize(artist, 30);
|
||||
@@ -102,14 +102,14 @@ void MprisController::launchNotification() {
|
||||
mpris.play_pause = [this]() { this->toggle_play(); };
|
||||
mpris.next = [this]() { this->next_song(); };
|
||||
mpris.previous = [this]() { this->previous_song(); };
|
||||
notifactionController->showSpotifyNotification(mpris);
|
||||
mprisUpdatedSignal.emit(mpris);
|
||||
}
|
||||
|
||||
void MprisController::on_properties_changed(const Gio::DBus::Proxy::MapChangedProperties &changed_properties,
|
||||
const std::vector<Glib::ustring> &) {
|
||||
|
||||
if (changed_properties.find("Metadata") != changed_properties.end()) {
|
||||
launchNotification();
|
||||
signalNotification();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user