Files
quickshell/modules/notification/notificationServer/NotificationServer.qml
T

101 lines
3.0 KiB
QML

pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
import Quickshell.Hyprland
import Quickshell.Services.Notifications
import "../../../config"
Item {
id: notificationServerState
property var focusedMonitor: null
property var newestNotification: null
property bool soundEnabled: true
property alias trackedNotifications: notificationServer.trackedNotifications
property int notificationNum: trackedNotifications.values.length
signal notificationReceived(var notification)
function correctMonitor(screen) {
return (Hyprland.monitorFor(screen) === focusedMonitor)
}
Process {
id: notificationSound
command: ["pw-play", "--volume", "0.25", Config.configDir + "/modules/notification/assets/notification.ogg"]
function play() {
if (running)
return
Config.debug == "Notification" && console.log(
"[NotificationSound] Playing:", Config.configDir + "/modules/notification/assets/notification.ogg"
)
notificationSound.startDetached()
}
}
NotificationServer {
id: notificationServer
actionsSupported: true
bodyHyperlinksSupported: true
bodyImagesSupported: true
actionIconsSupported: true
imageSupported: true
persistenceSupported: true
bodyMarkupSupported: true
inlineReplySupported: true
onNotification: function(notification) {
// if(notification.lastGeneration){
// console.log(
// "[NotificationServer] Closing Notification:",
// notification.appName, notification.id, notification.summary, notification.body
// )
// notification.dismiss()
// return
// }
notification.tracked = true
!notification.lastGeneration && Config.debug == "Notification" && console.log(
"[NotificationServer] Notification received:",
notification.appName, notification.id, notification.summary, notification.body
)
let timer = notificationTimerComponent.createObject(
notificationServerState,
{ notification: notification }
)
Hyprland.refreshMonitors()
timer.start()
}
}
Component {
id: notificationTimerComponent
Timer {
required property var notification
interval: 2000
repeat: false
onTriggered: {
if(!notification.lastGeneration && notificationServerState.soundEnabled){
focusedMonitor = Hyprland.focusedMonitor
notificationReceived(notification)
notificationSound.play()
}
destroy()
}
}
}
Component.onCompleted: {
focusedMonitor = Hyprland.focusedMonitor
Config.debug == "Notification" && console.log("[NotificationServer]: Component completed")
}
}