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.
This commit is contained in:
Devin Lin 2025-06-25 13:12:24 -04:00
parent 46578fde73
commit ca9696b84d
4 changed files with 58 additions and 9 deletions

View file

@ -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 property bool inhibited: false
onInhibitedChanged: { onInhibitedChanged: {
var pa = pulseAudio.item; var pa = __pulseAudio.item;
if (!pa) { if (!pa) {
return; return;
} }

View file

@ -0,0 +1,39 @@
/*
SPDX-FileCopyrightText: 2017, 2019 Kai Uwe Broulik <kde@privat.broulik.de>
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;
}
}
}
}

View file

@ -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.plasma5support 2.0 as P5Support
import org.kde.plasma.private.mobileshell as MobileShell import org.kde.plasma.private.mobileshell as MobileShell
import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings 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.extras 2.0 as PlasmaExtras
import org.kde.plasma.components 3.0 as PlasmaComponents3 import org.kde.plasma.components 3.0 as PlasmaComponents3
@ -131,13 +132,12 @@ Item {
if (doNotDisturbModeEnabled) { if (doNotDisturbModeEnabled) {
notificationSettings.defaults(); notificationSettings.defaults();
} else { } else {
// We just have a global toggle, so set it to a really long time (in this case, a year)
var until = new Date(); var until = new Date();
until.setFullYear(until.getFullYear() + 1); until.setFullYear(until.getFullYear() + 1);
notificationSettings.notificationsInhibitedUntil = until; notificationSettings.notificationsInhibitedUntil = until;
} }
notificationSettings.save(); notificationSettings.save();
} }
@ -148,6 +148,17 @@ Item {
MobileShell.ShellUtil.executeCommand("plasma-open-settings kcm_notifications"); 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 { P5Support.DataSource {
id: timeDataSource id: timeDataSource
engine: "time" engine: "time"

View file

@ -118,12 +118,6 @@ ContainmentItem {
function onCloseActionDrawerRequested() { function onCloseActionDrawerRequested() {
drawer.actionDrawer.close(); drawer.actionDrawer.close();
} }
function onDoNotDisturbChanged() {
if (drawer.actionDrawer.notificationsWidget.doNotDisturbModeEnabled !== MobileShellState.ShellDBusClient.doNotDisturb) {
drawer.actionDrawer.notificationsWidget.toggleDoNotDisturbMode();
}
}
} }
Binding { Binding {