From d4c5dfc13523c1896f46eb2f5d31accd85dc0225 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 17 Jul 2026 20:03:04 +0000 Subject: [PATCH] Test --- modules/notifications/NotificationCard.qml | 8 +- .../notifications/NotificationIndicator.qml | 13 ++- modules/notifications/NotificationManager.qml | 100 +++++++----------- modules/notifications/NotificationPopup.qml | 2 +- 4 files changed, 52 insertions(+), 71 deletions(-) diff --git a/modules/notifications/NotificationCard.qml b/modules/notifications/NotificationCard.qml index 54716b9..9ab70b7 100644 --- a/modules/notifications/NotificationCard.qml +++ b/modules/notifications/NotificationCard.qml @@ -1,7 +1,6 @@ import QtQuick import Quickshell import Quickshell.Services.Notifications -import Quickshell.Widgets import "../../config" Rectangle { @@ -78,13 +77,14 @@ Rectangle { height: 28 anchors.verticalCenter: parent.verticalCenter - IconImage { + Image { id: notifIcon anchors.fill: parent - icon: notification.appIcon + source: notification.appIcon ? "file://" + notification.appIcon : "" sourceSize.width: 28 sourceSize.height: 28 - visible: notification.appIcon !== "" + asynchronous: true + visible: status === Image.Ready } Text { diff --git a/modules/notifications/NotificationIndicator.qml b/modules/notifications/NotificationIndicator.qml index ee20793..e4eef4d 100644 --- a/modules/notifications/NotificationIndicator.qml +++ b/modules/notifications/NotificationIndicator.qml @@ -1,7 +1,6 @@ import QtQuick import Quickshell import Quickshell.Services.Notifications -import Quickshell.Widgets import "../../config" MouseArea { @@ -44,13 +43,15 @@ MouseArea { height: Config.iconSize(indicator.height) anchors.verticalCenter: parent.verticalCenter - IconImage { + Image { id: notifIcon anchors.fill: parent - icon: manager.lastNotification ? manager.lastNotification.appIcon : "" + source: (manager.lastNotification && manager.lastNotification.appIcon) + ? "file://" + manager.lastNotification.appIcon : "" sourceSize.width: Config.iconSize(indicator.height) sourceSize.height: Config.iconSize(indicator.height) - visible: manager.lastNotification && manager.lastNotification.appIcon !== "" + asynchronous: true + visible: status === Image.Ready } Text { @@ -159,9 +160,7 @@ MouseArea { radius: Config.small_radius color: Qt.alpha(Colors.surfaceContainerHighest, 0.5) - required property var model - - property var notif: model.object + property var notif: modelData Row { anchors { diff --git a/modules/notifications/NotificationManager.qml b/modules/notifications/NotificationManager.qml index 7faecbf..d1df9e9 100644 --- a/modules/notifications/NotificationManager.qml +++ b/modules/notifications/NotificationManager.qml @@ -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 } } diff --git a/modules/notifications/NotificationPopup.qml b/modules/notifications/NotificationPopup.qml index 4f92459..f644da2 100644 --- a/modules/notifications/NotificationPopup.qml +++ b/modules/notifications/NotificationPopup.qml @@ -62,7 +62,7 @@ Variants { delegate: NotificationCard { width: contentColumn.width - notification: model.object + notification: modelData manager: root.manager } }