Notification
Request permission and display native system notifications from C# - with body, icon, tag and full lifecycle callbacks for click, show, close and error.
@inject Bit.Butil.Notification notificationMDN reference
IsSupported reports whether the runtime implements the Notifications API at all. GetPermission reads the current decision without prompting, while RequestPermission shows the browser's permission dialog and resolves with the user's choice: Granted, Denied or Default.
@inject Bit.Butil.Notification notification
var isSupported = await notification.IsSupported();
var current = await notification.GetPermission();
var granted = await notification.RequestPermission(); // shows the browser promptCurrent permission: unknown
Displays a fire-and-forget system notification. NotificationOptions maps the full option surface of the Notification constructor: Body, Icon, Image, Badge, Tag, Lang, Dir, Renotify, RequireInteraction, Silent, Timestamp, Vibrate and arbitrary Data. Reusing the same Tag replaces the previous toast instead of stacking a new one.
await notification.Show("Deploy finished", new()
{
Body = "All 12 services rolled out successfully.",
Icon = "https://example.com/icon.png",
Tag = "deploy-status", // same tag replaces the previous toast
RequireInteraction = false, // auto-dismiss per OS rules
Silent = false,
});ShowTracked returns a NotificationHandle and wires C# callbacks to the notification's click, show, close and error events. The handle lets you close the toast programmatically; disposing it detaches the listeners. Tracked notifications stay on screen until dismissed or closed.
var handle = await notification.ShowTracked("Incoming call",
new() { Body = "Click to answer." },
onClick: () => { /* focus the call UI */ },
onShow: () => { /* start the ringtone */ },
onClose: () => { /* stop the ringtone */ },
onError: () => { /* fall back to in-app banner */ });
// later:
await handle.Close();
await handle.DisposeAsync();API reference
ValueTask<bool> IsSupported()ValueTask<NotificationPermission> GetPermission()ValueTask<NotificationPermission> RequestPermission()ValueTask Show(string title, NotificationOptions? options = null)ValueTask<NotificationHandle> ShowTracked(string title, NotificationOptions? options = null, Action? onClick = null, Action? onShow = null, Action? onClose = null, Action? onError = null)ValueTask DisposeAsync()Guid IdValueTask Close()ValueTask DisposeAsync()void InvokeNotification…(Guid id)