Files
Quickbar/Services/NotificationService.qml
2025-10-07 17:11:20 -03:00

67 lines
1.7 KiB
QML

pragma Singleton
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Layouts
import Quickshell
import Quickshell.Services.Notifications
import Quickshell.Widgets
import qs.Widgets
Singleton {
id: notificationRoot
readonly property var notificationServer: notificationServer
readonly property var trackedNotifications: notificationServer.trackedNotifications
readonly property var notificationsNumber: notificationServer.trackedNotifications.values.length
property bool shouldShowOsd: false
property var currentNotification: null
NotificationServer {
id: notificationServer
imageSupported: true
}
Connections {
function onNotification(notif) {
if (notif.body == "MediaOngoingActivity") {
notif.dismiss();
return;
}
notif.tracked = true;
notificationRoot.currentNotification = notif;
notificationRoot.shouldShowOsd = true;
notificationTimer.start();
}
target: notificationServer
}
Timer {
id: notificationTimer
interval: 5000
onTriggered: parent.shouldShowOsd = false
}
LazyLoader {
id: popupLoader
active: currentNotification && shouldShowOsd
component: NotificationPopup {
notification: currentNotification
// No signal handler here!
}
onItemChanged: {
if (item) {
item.dismissed.connect(function() {
notificationRoot.shouldShowOsd = false
currentNotification.dismiss()
})
}
}
}
}