Skip to content

factory

factory

Session-bus probing factory + the no-op fallback 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).

The no-op NullNotifier is co-located here because it has no state of its own and the factory is its only constructor in production code — keeping both in one module reduces the notifier surface to factory + desktop + protocol + callback instead of five files.

NullNotifier

Silent fallback that satisfies the Notifier protocol.

Every method is a no-op. notify always returns 0. Every method accepts **_ rather than spelling each protocol parameter: the no-op fallback discards every argument and the duck-typed match against Notifier is what matters at call sites, not the impl signature.

notify(summary, body='', **_) async

Accept and discard a notification, returning 0.

Source code in src/terok_clearance/notifications/factory.py
async def notify(self, summary: str, body: str = "", **_: Any) -> int:
    """Accept and discard a notification, returning ``0``."""
    del summary, body
    return 0

on_action(*_args, **_kw) async

Accept and discard an action callback registration.

Source code in src/terok_clearance/notifications/factory.py
async def on_action(self, *_args: Any, **_kw: Any) -> None:
    """Accept and discard an action callback registration."""

close(*_args, **_kw) async

Accept and discard a close request.

Source code in src/terok_clearance/notifications/factory.py
async def close(self, *_args: Any, **_kw: Any) -> None:
    """Accept and discard a close request."""

disconnect() async

Accept and discard a teardown request.

Source code in src/terok_clearance/notifications/factory.py
async def disconnect(self) -> None:
    """Accept and discard a teardown request."""

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, DBusFastError, ValueError) as exc:
        _log.debug("D-Bus session bus unavailable, falling back to NullNotifier: %s", exc)
        return NullNotifier()
    return notifier