Skip to content

notify ​

notify requests a native desktop notification and returns a structured error if the platform service cannot show it.

Signaturenotify(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 ​

FieldTypeMeaning
iconstring?The name or path of an icon to show alongside the notification.
urgencyNotifyUrgency?See NotifyUrgency. Defaults to Normal.
timeoutu32?How long the notification stays visible, in milliseconds, before the desktop environment dismisses it automatically.

NotifyUrgency Members ​

MemberMeaning
LowLow priority, the desktop environment may not show it at all in "do not disturb" mode.
NormalDefault priority.
CriticalHigh 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 ​

FieldTypeMeaning
codestringA stable, machine-readable error identifier.
messagestringA human-readable description of the failure.
:::