notify
notify solicita una notificación nativa del sistema y devuelve un error estructurado si el servicio de la plataforma no puede mostrarla.
Firma
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 asume los valores predeterminados de la propia plataforma para cada campo cuando se omite.
Campos de NotifyOptions
| Campo | Tipo | Significado |
|---|---|---|
icon | string? | El nombre o ruta de un ícono para mostrar junto a la notificación. |
urgency | NotifyUrgency? | Consulta NotifyUrgency. El valor predeterminado es Normal. |
timeout | u32? | Cuánto tiempo permanece visible la notificación, en milisegundos, antes de que el entorno de escritorio la descarte automáticamente. |
Miembros de NotifyUrgency
| Miembro | Significado |
|---|---|
Low | Prioridad baja, el entorno de escritorio puede no mostrarla en modo "no molestar". |
Normal | Prioridad predeterminada. |
Critical | Prioridad alta, algunos entornos de escritorio la mantienen en pantalla hasta que se descarta. |
Devuelve Err(OsError) con el código ERR_OS_NOTIFICATION_FAILED cuando el servicio de notificaciones de la plataforma no está disponible o rechaza la notificación. Un título o cuerpo nulo devuelve ERR_OS_INVALID_ARGUMENT.
Campos de OsError
| Campo | Tipo | Significado |
|---|---|---|
code | string | Un identificador de error estable y legible por máquina. |
message | string | Una descripción legible del error. |
| ::: |
