(Ubuntu 22.04 wayland swaywm)
我对任何通知都不感兴趣,所以我卸载了 dunst。但是,现在许多应用程序都以非常不靠谱的方式制作自己的通知,例如制作一个弹出窗口,这真的很烦人。
我想知道是否存在某种虚拟通知守护进程,它在应用程序中看起来像通常的通知守护进程,但实际上从未向我显示任何内容?
PS Dunst 无论如何都无法工作,通知会出现并且永远不会自动消失,出于某种原因,更改配置文件无法解决这个问题。我不想修复这个问题(我也没有要求你这样做),所以我希望找到一个不需要重新安装 dunst 和更改其配置的解决方案,因为它可能对我来说不起作用。
答案1
这是一个虚拟通知守护进程:
#!/usr/bin/env python
# Derived from https://github.com/mk-fg/notification-thing/blob/6c298ea861327329b87116ac347a35d3bef6d7d2/notification_thing/daemon.py
from dbus.mainloop.glib import DBusGMainLoop
import dbus.service
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import GLib, Gdk
dbus_props = dbus.PROPERTIES_IFACE
dbus_iface = 'org.freedesktop.Notifications'
class NotificationDaemon(dbus.service.Object):
def __init__(self, bus):
dbus.service.Object.__init__( self, bus,
'/org/freedesktop/Notifications', dbus.service.BusName(dbus_iface, bus) )
@dbus.service.method(dbus_iface, '', 'ssss')
def GetServerInformation(self):
return 'dummy-notification-daemon', '[email protected]', '1.0', '1.0'
@dbus.service.method(dbus_iface, '', 'as')
def GetCapabilities(self):
return ['body', 'persistence', 'icon-static']
@dbus.service.signal(dbus_iface, 'uu')
def NotificationClosed(self, nid, reason=None):
pass
@dbus.service.signal(dbus_iface, 'us')
def ActionInvoked(self, nid, action_key):
pass
@dbus.service.method(dbus_props, 'ss', 'v')
def Get(self, iface, k):
raise KeyError
@dbus.service.method(dbus_props, 's', 'a{sv}')
def GetAll(self, iface):
return []
@dbus.service.method(dbus_props, 'ssv', '')
def Set(self, iface, k, v):
pass
@dbus.service.signal(dbus_props, 'sa{sv}as')
def PropertiesChanged(self, iface, props_changed, props_invalidated):
pass
@dbus.service.method(dbus_iface, 'susssasa{sv}i', 'u')
def Notify(self, app_name, nid, icon, summary, body, actions, hints, timeout):
return 0
@dbus.service.method(dbus_iface, 'u', '')
def CloseNotification(self, nid):
pass
if __name__ == "__main__":
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
daemon = NotificationDaemon(bus)
loop = GLib.MainLoop()
loop.run()
将其保存到dummy_notifications_server.py
文件,标记为可执行文件,然后运行或添加到自动启动。我测试过这满足要求notify-send
。