Files
nixos/scripts/WMScripts/dunst_bar.py
T
2026-10-07 11:48:30 +02:00

51 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env nix-shell
#! nix-shell -i python3 --packages python314Packages.dbus-fast
from asyncio import run, Event
from json import dumps
from dbus_fast.aio import MessageBus
from dbus_fast.proxy_object import BaseProxyInterface, BaseProxyObject
def output(msg: string, clss: string = "unmuted-notifs"):
print(dumps({
"text": msg,
"alt": "",
"tooltip": "",
"class": clss,
"percentage": 0
}, ensure_ascii=False), flush=True)
def update_dbus_state(interface, changed, _) -> None:
if interface != 'org.dunstproject.cmd0':
output("", "error")
return
if 'paused' in changed:
update_output(changed['paused'].value)
def update_output(paused: bool) -> None:
output("󱙍" if paused else "󰍡", "muted-notifs" if paused else "unmuted-notifs")
async def main() -> None:
bus = await MessageBus().connect()
introspection = await bus.introspect('org.freedesktop.Notifications', '/org/freedesktop/Notifications')
notifications: BaseProxyObject = bus.get_proxy_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications', introspection)
properties = notifications.get_interface('org.freedesktop.DBus.Properties')
dunst = notifications.get_interface('org.dunstproject.cmd0')
properties.on_properties_changed(update_dbus_state)
update_output(await dunst.get_paused())
await Event().wait()
if __name__ == "__main__":
run(main())