From c8a056f332296ee21abf55b991118d2b2ec0ae83 Mon Sep 17 00:00:00 2001 From: Ly-sec Date: Fri, 5 Sep 2025 22:42:40 +0200 Subject: [PATCH] Notification: add DND option to widget and notification panel as requested in #212 --- Commons/Settings.qml | 1 + Modules/Bar/Widgets/NotificationHistory.qml | 15 ++++++++++++--- Modules/Notification/NotificationHistoryPanel.qml | 13 +++++++++++++ Services/NotificationService.qml | 4 ++-- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Commons/Settings.qml b/Commons/Settings.qml index a416e7f..9565e2c 100644 --- a/Commons/Settings.qml +++ b/Commons/Settings.qml @@ -296,6 +296,7 @@ Singleton { // notifications property JsonObject notifications: JsonObject { + property bool doNotDisturb: false property list monitors: [] } diff --git a/Modules/Bar/Widgets/NotificationHistory.qml b/Modules/Bar/Widgets/NotificationHistory.qml index 222a0eb..cb11314 100644 --- a/Modules/Bar/Widgets/NotificationHistory.qml +++ b/Modules/Bar/Widgets/NotificationHistory.qml @@ -14,11 +14,20 @@ NIconButton { property real scaling: 1.0 sizeRatio: 0.8 - icon: "notifications" - tooltipText: "Notification history" + icon: Settings.data.notifications.doNotDisturb ? "notifications_off" : "notifications" + tooltipText: Settings.data.notifications.doNotDisturb ? "Notification history (Do Not Disturb ON)\nRight-click to toggle Do Not Disturb" : "Notification history\nRight-click to toggle Do Not Disturb" colorBg: Color.mSurfaceVariant - colorFg: Color.mOnSurface + colorFg: Settings.data.notifications.doNotDisturb ? Color.mError : Color.mOnSurface colorBorder: Color.transparent colorBorderHover: Color.transparent + onClicked: PanelService.getPanel("notificationHistoryPanel")?.toggle(screen, this) + + onRightClicked: { + Settings.data.notifications.doNotDisturb = !Settings.data.notifications.doNotDisturb + ToastService.showNotice( + Settings.data.notifications.doNotDisturb ? "Do Not Disturb enabled" : "Do Not Disturb disabled", + Settings.data.notifications.doNotDisturb ? "Notifications will be hidden but saved to history" : "Notifications will be shown normally", + "notice", false, 2000) + } } diff --git a/Modules/Notification/NotificationHistoryPanel.qml b/Modules/Notification/NotificationHistoryPanel.qml index 3b10aec..7bc2378 100644 --- a/Modules/Notification/NotificationHistoryPanel.qml +++ b/Modules/Notification/NotificationHistoryPanel.qml @@ -43,6 +43,19 @@ NPanel { Layout.fillWidth: true } + NIconButton { + icon: Settings.data.notifications.doNotDisturb ? "notifications_off" : "notifications_active" + tooltipText: Settings.data.notifications.doNotDisturb ? "Do Not Disturb (ON)" : "Do Not Disturb (OFF)" + sizeRatio: 0.8 + onClicked: { + Settings.data.notifications.doNotDisturb = !Settings.data.notifications.doNotDisturb + ToastService.showNotice( + Settings.data.notifications.doNotDisturb ? "Do Not Disturb enabled" : "Do Not Disturb disabled", + Settings.data.notifications.doNotDisturb ? "Notifications will be hidden but saved to history" : "Notifications will be shown normally", + "notice", false, 2000) + } + } + NIconButton { icon: "delete" tooltipText: "Clear history" diff --git a/Services/NotificationService.qml b/Services/NotificationService.qml index a79b812..62d88fb 100644 --- a/Services/NotificationService.qml +++ b/Services/NotificationService.qml @@ -29,8 +29,8 @@ Singleton { // Signal when notification is received onNotification: function (notification) { - // Check if notifications are suppressed - if (Settings.data.notifications && Settings.data.notifications.suppressed) { + // Check if do-not-disturb is enabled + if (Settings.data.notifications && Settings.data.notifications.doNotDisturb) { // Still add to history but don't show notification root.addToHistory(notification) return