notify
notify solicita uma notificação nativa do sistema e retorna um erro estruturado se o serviço da plataforma não conseguir exibi-la.
Assinatura
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 assume os padrões da própria plataforma para cada campo quando omitido.
Campos de NotifyOptions
| Campo | Tipo | Significado |
|---|---|---|
icon | string? | O nome ou caminho de um ícone para mostrar junto da notificação. |
urgency | NotifyUrgency? | Veja NotifyUrgency. Padrão é Normal. |
timeout | u32? | Por quanto tempo a notificação fica visível, em milissegundos, antes do ambiente de desktop dispensá-la automaticamente. |
Membros de NotifyUrgency
| Membro | Significado |
|---|---|
Low | Prioridade baixa, o ambiente de desktop pode nem mostrar em modo "não perturbe". |
Normal | Prioridade padrão. |
Critical | Prioridade alta, alguns ambientes de desktop mantêm na tela até ser dispensada. |
Retorna Err(OsError) com o código ERR_OS_NOTIFICATION_FAILED quando o serviço de notificações da plataforma está indisponível ou recusa a notificação. Um título ou corpo nulo retorna ERR_OS_INVALID_ARGUMENT.
Campos de OsError
| Campo | Tipo | Significado |
|---|---|---|
code | string | Um identificador de erro estável e legível por máquina. |
message | string | Uma descrição legível da falha. |
| ::: |
