This commit is contained in:
Your Name
2026-07-17 20:03:04 +00:00
parent 880ee3974f
commit d4c5dfc135
4 changed files with 52 additions and 71 deletions
+41 -59
View File
@@ -1,6 +1,6 @@
import QtQuick
import QtMultimedia
import Quickshell
import Quickshell.Io
import Quickshell.Services.Notifications
import "../../config"
@@ -9,6 +9,7 @@ Item {
NotificationServer {
id: notificationServer
imageSupported: true
actionsSupported: true
bodyMarkupSupported: false
@@ -19,18 +20,20 @@ Item {
}
}
property ObjectModel notifications: ObjectModel {}
readonly property ObjectModel notifications: notificationServer.trackedNotifications
property int notificationCount: 0
property var lastNotification: null
property bool hasCritical: false
readonly property string soundDir: Config.configDir + "/assets/sounds"
property var _trackedIds: ({})
property var _dismissTimes: ({})
function onNotificationReceived(notification) {
notifications.append(notification)
notificationCount = notifications.count
_trackedIds[notification.id] = true
notificationCount = Object.keys(_trackedIds).length
lastNotification = notification
if (notification.urgency === NotificationUrgency.Critical)
hasCritical = true
@@ -41,26 +44,22 @@ Item {
function playSound(urgency) {
var path
var vol
switch (urgency) {
case NotificationUrgency.Low:
path = soundDir + "/notification-low.oga"
vol = 0.35
break
case NotificationUrgency.Critical:
path = soundDir + "/notification-critical.oga"
vol = 1.0
break
default:
path = soundDir + "/notification-normal.oga"
vol = 0.7
break
}
if (player.hasAudio) player.stop()
player.source = "file://" + path
audioOutput.volume = vol
player.play()
soundProc.command = [
"sh", "-c",
"pw-play \"" + path + "\" 2>/dev/null || paplay \"" + path + "\" 2>/dev/null || ffplay -nodisp -autoexit \"" + path + "\" 2>/dev/null"
]
soundProc.running = true
}
function scheduleDismiss(notification) {
@@ -77,44 +76,27 @@ Item {
}
function dismissNotification(notification) {
delete _trackedIds[notification.id]
delete _dismissTimes[notification.id]
notificationCount = Object.keys(_trackedIds).length
notification.tracked = false
refreshMetadata()
}
function refreshMetadata() {
hasCritical = false
lastNotification = null
for (var i = 0; i < notifications.count; i++) {
if (notifications.get(i).id === notification.id) {
notifications.remove(i)
break
var n = notifications.get(i)
if (_trackedIds[n.id]) {
lastNotification = n
if (n.urgency === NotificationUrgency.Critical)
hasCritical = true
}
}
notificationCount = notifications.count
delete _dismissTimes[notification.id]
if (notificationCount === 0) {
hasCritical = false
lastNotification = null
} else {
lastNotification = notifications.get(0)
hasCritical = false
for (var j = 0; j < notifications.count; j++) {
if (notifications.get(j).urgency === NotificationUrgency.Critical) {
hasCritical = true
break
}
}
}
notification.tracked = false
}
function dismissById(nid) {
for (var i = 0; i < notifications.count; i++) {
var n = notifications.get(i)
if (n.id === nid) {
dismissNotification(n)
return
}
}
}
function dismissAll() {
while (notifications.count > 0) {
var n = notifications.get(0)
dismissNotification(n)
}
}
@@ -124,24 +106,24 @@ Item {
repeat: true
onTriggered: {
var now = Date.now() / 1000
var toDismiss = []
for (var i = 0; i < notifications.count; i++) {
var n = notifications.get(i)
var t = _dismissTimes[n.id]
if (t !== undefined && now >= t)
toDismiss.push(n)
for (var id in _dismissTimes) {
if (_dismissTimes[id] <= now) {
for (var i = 0; i < notifications.count; i++) {
var n = notifications.get(i)
if (n.id.toString() === id) {
dismissNotification(n)
break
}
}
}
}
for (var j = 0; j < toDismiss.length; j++)
dismissNotification(toDismiss[j])
if (notifications.count === 0)
if (Object.keys(_trackedIds).length === 0)
running = false
}
}
MediaPlayer {
id: player
audioOutput: AudioOutput {
id: audioOutput
}
Process {
id: soundProc
running: false
}
}