for my open-source app, I am trying to detect when my users are in DND to not disturb them. I have this working for KDE, XFCE and trying to do for Gnome now.
I am in node, so using some dbus library, and would like to do the same for Gnome.
const dbus = require('dbus-next')
const bus = dbus.sessionBus()
try {
const obj = await bus.getProxyObject('org.freedesktop.Notifications', '/org/freedesktop/Notifications')
const properties = obj.getInterface('org.freedesktop.DBus.Properties')
const dndEnabled = await properties.Get('org.freedesktop.Notifications', 'Inhibited')
if (await dndEnabled.value) {
return true
}
} catch (e) {
// KDE is not running
}
try {
const obj = await bus.getProxyObject('org.xfce.Xfconf', '/org/xfce/Xfconf')
const properties = obj.getInterface('org.xfce.Xfconf')
const dndEnabled = await properties.GetProperty('xfce4-notifyd', '/do-not-disturb')
if (await dndEnabled.value) {
return true
}
} catch (e) {
// XFCE is not running
}
I am trying to deduct with d-feet based on some ai / google help but can’t find the right place where it is:
I think there is no API to know if the desktop is in Do Not Disturb mode, because apps are supposed to send notifications as usual, it’s just that the user won’t be disturbed by them and can see the notifications afterwards.
What are you trying to achieve? What’s your goal by detecting the Do Not Disturb?
The fact that the system can be introspected (with D-Bus or other methods) when desktop settings are modified doesn’t mean that there is a guaranteed stable API for it.
It works by showing a window in specified intervals with some break / stretch idea. For MacOS / Windows I have a functionality where people can choose to not be shown breaks in DND mode. I want to have the same for Linux.
Here’s my PR where I am adding this (currently working on KDE, XFCE): basically when user enables DND, I pause showing of breaks and when DND ends breaks are resumed
That’s a solution, running the gsettings command in a sub-process. Probably good enough
Otherwise I don’t know if you have access to the GSettings API, part of the GIO library, from the programming language that you use. You can check https://gtk.org/ to see the language bindings.
Edit: GSettings has an introspectable part in its API, to look if the schema and key is present. Otherwise if you try to get a value directly, and the gsettings schema or key is not present on the system, the program crashes. In C it’s the g_settings_schema_has_key() function.