notify
notify requests a native desktop notification and returns a structured error if the platform service cannot show it.
Signature
notify(title: string, body: string, options?: NotifyOptions): Result<void, OsError>tyrus
import { NotifyOptions, NotifyUrgency, OsError, notify } from "tyrus:os";
const main = (): void => {
match (notify("Build complete", "All 42 tests passed.")) {
Ok() => print("Notification sent"); // Notification sent
Err(error) => printError(`${error.code}: ${error.message}`); // ERR_OS_NOTIFICATION_FAILED: the platform notification service could not show the notification
}
const options: NotifyOptions = { urgency: NotifyUrgency.Critical, timeout: 5000 };
match (notify("Build failed", "3 tests failed.", options)) {
Ok() => print("Critical notification sent"); // Critical notification sent
Err(error) => printError(`${error.code}: ${error.message}`); // ERR_OS_NOTIFICATION_FAILED: the platform notification service could not show the notification
}
};options defaults to the platform's own defaults for every field when omitted.
NotifyOptions Fields
| Field | Type | Meaning |
|---|---|---|
icon | string? | The name or path of an icon to show alongside the notification. |
urgency | NotifyUrgency? | See NotifyUrgency. Defaults to Normal. |
timeout | u32? | How long the notification stays visible, in milliseconds, before the desktop environment dismisses it automatically. |
NotifyUrgency Members
| Member | Meaning |
|---|---|
Low | Low priority, the desktop environment may not show it at all in "do not disturb" mode. |
Normal | Default priority. |
Critical | High priority, some desktop environments keep it on screen until dismissed. |
Returns Err(OsError) with code ERR_OS_NOTIFICATION_FAILED when the platform notification service is unavailable or rejects the notification. A null title or body returns ERR_OS_INVALID_ARGUMENT.
OsError Fields
| Field | Type | Meaning |
|---|---|---|
code | string | A stable, machine-readable error identifier. |
message | string | A human-readable description of the failure. |
| ::: |
