From ca9696b84d7f4e73cd02b406b14c824c62567a44 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Wed, 25 Jun 2025 13:12:24 -0400 Subject: [PATCH] notifications: Fix do-not-disturb The implementation of do-not-disturb broke after the port to our own notification popups. Since the notification widget is quite deep in the ActionDrawer, just implement the DBus listening directly in NotificationsWidget. Also add the missing pulseAudio object in NotificationPopupProvider to implement notification inhibition. --- .../NotificationPopupProvider.qml | 7 +++- .../qml/popups/notifications/PulseAudio.qml | 39 +++++++++++++++++++ .../notifications/NotificationsWidget.qml | 15 ++++++- .../panel/package/contents/ui/main.qml | 6 --- 4 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 components/mobileshell/qml/popups/notifications/PulseAudio.qml diff --git a/components/mobileshell/qml/popups/notifications/NotificationPopupProvider.qml b/components/mobileshell/qml/popups/notifications/NotificationPopupProvider.qml index 712db175..e033550f 100644 --- a/components/mobileshell/qml/popups/notifications/NotificationPopupProvider.qml +++ b/components/mobileshell/qml/popups/notifications/NotificationPopupProvider.qml @@ -62,10 +62,15 @@ QtObject { } } + // TODO use pulseaudio-qt for this once it becomes a framework + property QtObject __pulseAudio: Loader { + source: "PulseAudio.qml" + } + property bool inhibited: false onInhibitedChanged: { - var pa = pulseAudio.item; + var pa = __pulseAudio.item; if (!pa) { return; } diff --git a/components/mobileshell/qml/popups/notifications/PulseAudio.qml b/components/mobileshell/qml/popups/notifications/PulseAudio.qml new file mode 100644 index 00000000..337d3a19 --- /dev/null +++ b/components/mobileshell/qml/popups/notifications/PulseAudio.qml @@ -0,0 +1,39 @@ +/* + SPDX-FileCopyrightText: 2017, 2019 Kai Uwe Broulik + + SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +*/ + +import QtQuick 2.2 + +import org.kde.plasma.private.volume 0.1 + +QtObject { + id: pulseAudio + + readonly property string notificationStreamId: "sink-input-by-media-role:event" + + property QtObject notificationStream + + property QtObject instantiator: Instantiator { + model: StreamRestoreModel {} + + delegate: QtObject { + readonly property string name: Name + readonly property bool muted: Muted + + function mute() { + Muted = true + } + function unmute() { + Muted = false + } + } + + onObjectAdded: (index, object) => { + if (object.name === notificationStreamId) { + notificationStream = object; + } + } + } +} diff --git a/components/mobileshell/qml/widgets/notifications/NotificationsWidget.qml b/components/mobileshell/qml/widgets/notifications/NotificationsWidget.qml index bfc48068..e1c0e3d6 100644 --- a/components/mobileshell/qml/widgets/notifications/NotificationsWidget.qml +++ b/components/mobileshell/qml/widgets/notifications/NotificationsWidget.qml @@ -15,6 +15,7 @@ import org.kde.kirigami 2.12 as Kirigami import org.kde.plasma.plasma5support 2.0 as P5Support import org.kde.plasma.private.mobileshell as MobileShell import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings +import org.kde.plasma.private.mobileshell.state as MobileShellState import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.components 3.0 as PlasmaComponents3 @@ -131,13 +132,12 @@ Item { if (doNotDisturbModeEnabled) { notificationSettings.defaults(); } else { + // We just have a global toggle, so set it to a really long time (in this case, a year) var until = new Date(); - until.setFullYear(until.getFullYear() + 1); notificationSettings.notificationsInhibitedUntil = until; } - notificationSettings.save(); } @@ -148,6 +148,17 @@ Item { MobileShell.ShellUtil.executeCommand("plasma-open-settings kcm_notifications"); } + // Implement listening to system "do not disturb" requests + Connections { + target: MobileShellState.ShellDBusClient + + function onDoNotDisturbChanged() { + if (root.doNotDisturbModeEnabled !== MobileShellState.ShellDBusClient.doNotDisturb) { + root.toggleDoNotDisturbMode(); + } + } + } + P5Support.DataSource { id: timeDataSource engine: "time" diff --git a/containments/panel/package/contents/ui/main.qml b/containments/panel/package/contents/ui/main.qml index cf84d1dc..27266cf9 100644 --- a/containments/panel/package/contents/ui/main.qml +++ b/containments/panel/package/contents/ui/main.qml @@ -118,12 +118,6 @@ ContainmentItem { function onCloseActionDrawerRequested() { drawer.actionDrawer.close(); } - - function onDoNotDisturbChanged() { - if (drawer.actionDrawer.notificationsWidget.doNotDisturbModeEnabled !== MobileShellState.ShellDBusClient.doNotDisturb) { - drawer.actionDrawer.notificationsWidget.toggleDoNotDisturbMode(); - } - } } Binding {