Cross-platform native desktop notification helpers for MoonBit.
let result = @notification.show("Build finished", title=Some("CI"))
ignore(result)///|
test "build a notification value" {
let request = @notification.Notification::new(
"Artifacts uploaded",
title=Some("Release"),
level=@notification.Warning,
)
assert_eq(request.body, "Artifacts uploaded")
}pub(all) struct Notification {
title : String?
body : String
level : NotificationLevel
} derive(Eq, Debug)test "Notification::new packages fields without validating" {
let request = Notification::new("Body text", title=Some("Title"))
assert_eq(request.body, "Body text")
assert_true(request.title is Some("Title"))
}fn ensure_supported() -> Result[Unit, String]test "ensure_supported reports a reason when unavailable" {
match ensure_supported() {
Ok(_) => ()
Err(message) => assert_true(!message.is_empty())
}
}fn is_supported() -> Booltest "is_supported probes capability without delivering" {
let _ : Bool = is_supported()
}fn show(body : String, title? : String?, level? : NotificationLevel, delivery? : NotificationDelivery) -> Result[Unit, String]// Title defaults to the package name; level defaults to `Info`.
let _ = @notification.show("Download complete")
// Or provide a title and raise the severity.
let _ = @notification.show(
"Disk almost full",
title=Some("Storage"),
level=@notification.NotificationLevel::Warning,
)fn show_notification(notification : Notification, delivery? : NotificationDelivery) -> Result[Unit, String]let request = @notification.Notification::new(
"Build finished",
title=Some("CI"),
level=@notification.NotificationLevel::Info,
)
let _ = @notification.show_notification(request)fn show_with_window(window_handle : Int64, body : String, title? : String?, level? : NotificationLevel, delivery? : NotificationDelivery) -> Result[Unit, String]// `window_handle` is forwarded to the Windows backend and ignored elsewhere.
let _ = @notification.show_with_window(0L, "Render finished")Cross-platform native desktop notification helpers for MoonBit.