desktop
desktop
¶
Desktop notification implementation using plyer.
Provides cross-platform desktop notifications for Marianne job events. Uses the plyer library for platform-independent notification support.
Phase 5 of Marianne implementation: Missing README features.
Classes¶
DesktopNotifier
¶
Desktop notification implementation using plyer.
Provides cross-platform desktop notifications on Windows, macOS, and Linux. Gracefully degrades if plyer is not installed - logs warning but doesn't fail.
Example usage
notifier = DesktopNotifier( events={NotificationEvent.JOB_COMPLETE, NotificationEvent.JOB_FAILED}, app_name="Marianne", ) await notifier.send(context)
Configuration from YAML
notifications: - type: desktop on_events: [job_complete, job_failed] config: timeout: 10 app_name: "Marianne AI"
Initialize the desktop notifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
set[NotificationEvent] | None
|
Set of events to subscribe to. Defaults to job-level events. |
None
|
app_name
|
str
|
Application name shown in notifications. |
'Marianne AI Compose'
|
timeout
|
int
|
Notification display timeout in seconds (platform-dependent). |
10
|
Source code in src/marianne/notifications/desktop.py
Attributes¶
subscribed_events
property
¶
Events this notifier is registered to receive.
Returns:
| Type | Description |
|---|---|
set[NotificationEvent]
|
Set of subscribed NotificationEvent types. |
Functions¶
from_config
classmethod
¶
Create DesktopNotifier from YAML configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_events
|
list[str]
|
List of event name strings from config. |
required |
config
|
dict[str, Any] | None
|
Optional dict with 'app_name' and 'timeout'. |
None
|
Returns:
| Type | Description |
|---|---|
DesktopNotifier
|
Configured DesktopNotifier instance. |
Example
notifier = DesktopNotifier.from_config( on_events=["job_complete", "job_failed"], config={"timeout": 5, "app_name": "My App"}, )
Source code in src/marianne/notifications/desktop.py
send
async
¶
Send a desktop notification.
Uses plyer for cross-platform notification support. Fails gracefully if plyer is unavailable or notification fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
NotificationContext
|
Notification context with event details. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if notification was sent, False if unavailable or failed. |
Source code in src/marianne/notifications/desktop.py
close
async
¶
Clean up resources.
Desktop notifier has no resources to clean up, but implements the protocol method.
MockDesktopNotifier
¶
Mock desktop notifier for testing.
Records all notifications sent without actually displaying them. Useful for testing notification integration.
Initialize mock notifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
set[NotificationEvent] | None
|
Set of events to subscribe to. |
None
|
Source code in src/marianne/notifications/desktop.py
Attributes¶
Functions¶
set_fail_next
¶
Configure the next send() call to fail.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
should_fail
|
bool
|
If True, next send() returns False. |
True
|
send
async
¶
Record notification without displaying.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
NotificationContext
|
Notification context. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True unless set_fail_next was called. |
Source code in src/marianne/notifications/desktop.py
close
async
¶
get_notification_count
¶
get_notifications_for_event
¶
Get all notifications for a specific event type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
NotificationEvent
|
Event type to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[NotificationContext]
|
List of matching notification contexts. |
Source code in src/marianne/notifications/desktop.py
Functions¶
is_desktop_notification_available
¶
Check if desktop notifications are available.
Returns:
| Type | Description |
|---|---|
bool
|
True if plyer is installed and can send notifications. |