Skip to content

factory

factory

Session-bus probing factory for the appropriate Notifier.

Thin convenience: try a real DbusNotifier, fall back to a NullNotifier if no session bus is reachable. Lives at the same layer as the concrete backends so CLI / consumer code can reach it without importing the package root (which causes a layering circularity — interface → interface).

create_notifier(app_name='terok') async

Return a connected DbusNotifier, or a NullNotifier on failure.

Parameters:

Name Type Description Default
app_name str

Application name sent with every notification.

'terok'

Returns:

Type Description
Notifier

A Notifier-compatible instance.

Source code in src/terok_clearance/notifications/factory.py
async def create_notifier(app_name: str = "terok") -> Notifier:
    """Return a connected ``DbusNotifier``, or a ``NullNotifier`` on failure.

    Args:
        app_name: Application name sent with every notification.

    Returns:
        A ``Notifier``-compatible instance.
    """
    notifier = DbusNotifier(app_name)
    try:
        await notifier.connect()
    except (OSError, DBusError, ValueError) as exc:
        _log.debug("D-Bus session bus unavailable, falling back to NullNotifier: %s", exc)
        return NullNotifier()
    return notifier