@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#include "services/dbus/notification.hpp"
|
||||
#include "services/dbus/mpris.hpp"
|
||||
#include "services/notificationController.hpp"
|
||||
#include "services/textureCache.hpp"
|
||||
|
||||
App::App() {
|
||||
@@ -13,6 +14,12 @@ App::App() {
|
||||
this->notificationService = std::make_shared<NotificationService>();
|
||||
this->mprisController = std::make_shared<MprisController>();
|
||||
|
||||
auto notificationController = NotificationController::getInstance();
|
||||
this->mprisController->signal_mpris_updated().connect(
|
||||
[notificationController](const MprisPlayer2Message &msg) {
|
||||
notificationController->showSpotifyNotification(msg);
|
||||
});
|
||||
|
||||
app->signal_activate().connect([&]() {
|
||||
auto display = Gdk::Display::get_default();
|
||||
auto monitors = display->get_monitors();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
HyprlandService::HyprlandService() {
|
||||
init();
|
||||
bindSocket();
|
||||
this->bindHyprlandSocket();
|
||||
}
|
||||
|
||||
void HyprlandService::init() {
|
||||
@@ -83,7 +83,7 @@ void HyprlandService::init() {
|
||||
}
|
||||
}
|
||||
|
||||
void HyprlandService::bindSocket() {
|
||||
void HyprlandService::bindHyprlandSocket() {
|
||||
std::string socketPath = HyprSocketHelper::getHyprlandSocketPath();
|
||||
|
||||
socketFd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
@@ -105,7 +105,8 @@ void HyprlandService::bindSocket() {
|
||||
return;
|
||||
}
|
||||
|
||||
GSource *source = g_unix_fd_source_new(socketFd, static_cast<GIOCondition>(G_IO_IN | G_IO_HUP | G_IO_ERR));
|
||||
auto socket_conditions = static_cast<GIOCondition>(G_IO_IN | G_IO_HUP | G_IO_ERR); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
|
||||
GSource *source = g_unix_fd_source_new(socketFd, socket_conditions);
|
||||
|
||||
auto onSocketEvent = [](gint fd, GIOCondition , gpointer user_data) -> gboolean {
|
||||
HyprlandService *self = static_cast<HyprlandService *>(user_data);
|
||||
@@ -214,7 +215,6 @@ void HyprlandService::onCloseWindow(std::string windowData) {
|
||||
|
||||
void HyprlandService::handleSocketMessage(SocketHelper::SocketMessage message) {
|
||||
if (socketEventTypeMap.find(message.eventType) == socketEventTypeMap.end()) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user