Cross-platform native tray helpers for MoonBit.
Dependencies
guard @tray.is_supported() else {
return
}
let tray = @tray.create(
identifier="com.example.demo",
tooltip="MoonBit tray demo",
)
match tray {
Ok(tray) => {
match
tray.set_menu([
@tray.TrayMenuItem::normal(id="show", label="Show"),
@tray.TrayMenuItem::separator(),
@tray.TrayMenuItem::checkbox(id="launch", label="Launch", checked=true),
@tray.TrayMenuItem::submenu(
label="More",
items=[
@tray.TrayMenuItem::normal(id="settings", label="Settings"),
],
),
]) {
Ok(_) => ()
Err(error) => println("set_menu skipped: \{error}")
}
match tray.show() {
Ok(_) =>
match tray.pump() {
Ok(_) =>
for event in tray.drain_events() {
println(event.event_name())
}
Err(error) => println(error)
}
Err(error) => println(error)
}
tray.destroy()
}
Err(error) => println(error)
}pub struct Tray {
// private fields
}pub(all) enum TrayMenuItem {
Normal(id~ : String, label~ : String, enabled~ : Bool)
Separator
Checkbox(id~ : String, label~ : String, checked~ : Bool, enabled~ : Bool)
Submenu(label~ : String, items~ : Array[TrayMenuItem], enabled~ : Bool)
} derive(Eq, Debug)fn TrayMenuItem::checkbox(id~ : String, label~ : String, checked? : Bool, enabled? : Bool) -> TrayMenuItemfn TrayMenuItem::submenu(label~ : String, items~ : Array[TrayMenuItem], enabled? : Bool) -> TrayMenuItemlet tray = @tray.create(icon=Some("/path/to/icon.png"), tooltip="My App").unwrap()
let _ = tray.show()
// ... run the application event loop, calling `tray.pump()` as needed ...
tray.destroy()fn default_identifier() -> Stringfn ensure_supported() -> Result[Unit, String]fn is_supported() -> Booltest "is_supported probes capability without creating a tray" {
let _ : Bool = is_supported()
}Cross-platform native tray helpers for MoonBit.
Dependencies