terok_dbus
terok_dbus
¶
D-Bus desktop notification package for terok.
CLEARANCE_BUS_NAME = 'org.terok.Clearance'
module-attribute
¶
Well-known bus name for the clearance daemon.
CLEARANCE_INTERFACE_NAME = 'org.terok.Clearance1'
module-attribute
¶
Versioned interface name for clearance signals and methods.
CLEARANCE_OBJECT_PATH = '/org/terok/Clearance'
module-attribute
¶
Object path for the Clearance1 interface.
CLEARANCE_XML = '<node>\n <interface name="org.terok.Clearance1">\n <signal name="RequestReceived">\n <arg type="s" name="request_id" direction="out"/>\n <arg type="s" name="project" direction="out"/>\n <arg type="s" name="task" direction="out"/>\n <arg type="s" name="dest" direction="out"/>\n <arg type="q" name="port" direction="out"/>\n <arg type="s" name="reason" direction="out"/>\n </signal>\n <method name="Resolve">\n <arg type="s" name="request_id" direction="in"/>\n <arg type="s" name="action" direction="in"/>\n <arg type="b" name="ok" direction="out"/>\n </method>\n <method name="ListPending">\n <arg type="a(ssssqs)" name="requests" direction="out"/>\n </method>\n <signal name="RequestResolved">\n <arg type="s" name="request_id" direction="out"/>\n <arg type="s" name="action" direction="out"/>\n <arg type="as" name="ips" direction="out"/>\n </signal>\n </interface>\n</node>'
module-attribute
¶
Introspection XML for org.terok.Clearance1.
SHIELD_BUS_NAME = 'org.terok.Shield'
module-attribute
¶
Well-known bus name for the shield D-Bus bridge.
SHIELD_INTERFACE_NAME = 'org.terok.Shield1'
module-attribute
¶
Versioned interface name for shield signals and methods.
SHIELD_OBJECT_PATH = '/org/terok/Shield'
module-attribute
¶
Object path for the Shield1 interface.
SHIELD_XML = '<node>\n <interface name="org.terok.Shield1">\n <signal name="ConnectionBlocked">\n <arg type="s" name="container" direction="out"/>\n <arg type="s" name="dest" direction="out"/>\n <arg type="q" name="port" direction="out"/>\n <arg type="q" name="proto" direction="out"/>\n <arg type="s" name="domain" direction="out"/>\n <arg type="s" name="request_id" direction="out"/>\n </signal>\n <method name="Verdict">\n <arg type="s" name="request_id" direction="in"/>\n <arg type="s" name="action" direction="in"/>\n <arg type="b" name="ok" direction="out"/>\n </method>\n <signal name="VerdictApplied">\n <arg type="s" name="container" direction="out"/>\n <arg type="s" name="dest" direction="out"/>\n <arg type="s" name="request_id" direction="out"/>\n <arg type="s" name="action" direction="out"/>\n <arg type="b" name="ok" direction="out"/>\n </signal>\n </interface>\n</node>'
module-attribute
¶
Introspection XML for org.terok.Shield1.
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_dbus/_notifier.py
notify(summary, body='', *, actions=(), timeout_ms=-1, hints=None, replaces_id=0, app_icon='')
async
¶
Send a desktop notification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary
|
str
|
Notification title. |
required |
body
|
str
|
Optional body text. |
''
|
actions
|
Sequence[tuple[str, str]]
|
|
()
|
timeout_ms
|
int
|
Expiration hint in milliseconds ( |
-1
|
hints
|
Mapping[str, Any] | None
|
Freedesktop hint dict (values should be |
None
|
replaces_id
|
int
|
Replace an existing notification in-place. |
0
|
app_icon
|
str
|
Icon name or |
''
|
Returns:
| Type | Description |
|---|---|
int
|
Server-assigned notification ID. |
Source code in src/terok_dbus/_notifier.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_dbus/_notifier.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_dbus/_notifier.py
disconnect()
async
¶
Tear down the session-bus connection.
Source code in src/terok_dbus/_notifier.py
NullNotifier
¶
Silent fallback that satisfies the Notifier protocol.
Every method is a no-op. notify always returns 0.
Notifier
¶
Bases: Protocol
Structural type for desktop notification backends.
Implementations must provide notify, on_action, close, and
disconnect. DbusNotifier talks to a real session bus;
NullNotifier silently discards everything for headless environments.
notify(summary, body='', *, actions=(), timeout_ms=-1, hints=None, replaces_id=0, app_icon='')
async
¶
Send a desktop notification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary
|
str
|
Notification title. |
required |
body
|
str
|
Optional body text. |
''
|
actions
|
Sequence[tuple[str, str]]
|
|
()
|
timeout_ms
|
int
|
Expiration hint in milliseconds ( |
-1
|
hints
|
Mapping[str, Any] | None
|
Freedesktop hint dict (values are |
None
|
replaces_id
|
int
|
Replace an existing notification in-place. |
0
|
app_icon
|
str
|
Icon name or |
''
|
Returns:
| Type | Description |
|---|---|
int
|
Server-assigned notification ID ( |
Source code in src/terok_dbus/_protocol.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_dbus/_protocol.py
close(notification_id)
async
¶
Close an active notification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notification_id
|
int
|
ID returned by |
required |
EventSubscriber(notifier, bus=None)
¶
Subscribe to Shield1 and Clearance1 D-Bus signals and present desktop notifications.
Creates desktop notifications with Allow/Deny action buttons for blocked
connections (Shield) and clearance requests (Clearance). Operator actions are
routed back as Verdict / Resolve D-Bus method calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notifier
|
Notifier
|
Desktop notification backend. |
required |
bus
|
MessageBus | None
|
Optional pre-connected |
None
|
Initialise the subscriber with a notifier and optional bus.
Source code in src/terok_dbus/_subscriber.py
start()
async
¶
Connect to the session bus and subscribe to Shield1 and Clearance1 signals.
Source code in src/terok_dbus/_subscriber.py
stop()
async
¶
Unsubscribe from signals and disconnect the bus if owned.
Source code in src/terok_dbus/_subscriber.py
create_notifier(app_name='terok')
async
¶
Return a connected DbusNotifier, or a NullNotifier on failure.
This is the primary entry point. Callers get a working notifier without caring whether a D-Bus session bus is available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
Application name sent with every notification. |
'terok'
|
Returns:
| Type | Description |
|---|---|
Notifier
|
A |