desktop
desktop
¶
Desktop notifier backed by dbus-fast and the freedesktop Notifications spec.
BUS_NAME = 'org.freedesktop.Notifications'
module-attribute
¶
OBJECT_PATH = '/org/freedesktop/Notifications'
module-attribute
¶
INTERFACE_NAME = 'org.freedesktop.Notifications'
module-attribute
¶
CloseReason
¶
Bases: IntEnum
Reason a notification was closed, per the freedesktop spec.
EXPIRED = 1
class-attribute
instance-attribute
¶
The notification expired (timed out).
DISMISSED = 2
class-attribute
instance-attribute
¶
The notification was dismissed by the user.
CLOSED = 3
class-attribute
instance-attribute
¶
The notification was closed via CloseNotification.
UNDEFINED = 4
class-attribute
instance-attribute
¶
The notification server did not provide a reason.
DbusNotifier(app_name='terok')
¶
Send desktop notifications over the D-Bus session bus.
The connection is established lazily on the first notify call.
Action callbacks are dispatched from the ActionInvoked signal;
stale callbacks are cleaned up automatically on NotificationClosed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
Application name sent with every notification. |
'terok'
|
Initialise with the given application name.
Source code in src/terok_clearance/notifications/desktop.py
connect()
async
¶
Idempotently open the session-bus connection and subscribe to signals.
Safe to call concurrently and repeatedly: the lock serialises racing callers so exactly one MessageBus is ever created for this notifier.
Source code in src/terok_clearance/notifications/desktop.py
notify(summary, body='', *, actions=(), timeout_ms=-1, hints=None, replaces_id=0, app_icon='', container_id='', container_name='', project='', task_id='', task_name='')
async
¶
Send a desktop notification.
Freedesktop notifications render summary + body + actions only,
so the structured identity kwargs (container_id and the
terok task triple) are dropped on the floor here — callers are
expected to have folded the user-facing identity into body
already. The kwargs stay in the signature for
Notifier conformance so callers
don't have to branch on notifier kind.
Source code in src/terok_clearance/notifications/desktop.py
on_action(notification_id, callback)
async
¶
Register a callback for when the user clicks an action button.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notification_id
|
int
|
ID returned by |
required |
callback
|
Callable[[str], None]
|
Called with the |
required |
Source code in src/terok_clearance/notifications/desktop.py
close(notification_id)
async
¶
Close an active notification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notification_id
|
int
|
ID returned by |
required |
Source code in src/terok_clearance/notifications/desktop.py
disconnect()
async
¶
Tear down the session-bus connection.