tray

Cross-platform native tray helpers for MoonBit.

tray
desktop
native
windows
macos
linux
moon add justjavac/tray@0.1.7
Download zip
Author
Version
0.1.7
License
MIT
Last updated
last month
Downloads
6K
README

#justjavac/tray

CI coverage Docs

Cross-platform native tray helpers for MoonBit.

#Example

guard @tray.is_supported() else {
return
}

let tray = @tray.create(
identifier="com.example.demo",
tooltip="MoonBit tray demo",
).unwrap()

ignore(tray.show())
ignore(tray.pump())
tray.destroy()

#
Platform

pub enum Platform {
Windows
Linux
MacOS
Unknown
} derive(Eq, Show, ToJson)

#
Tray

pub struct Tray {
handle : Int64
native : Bool
platform : Platform
identifier : String
icon : String?
tooltip : String
visible : Bool
destroyed : Bool
}

Represents a system tray handle created by this package.

A Tray tracks the user-visible state that the MoonBit layer believes is active, including whether the tray is currently visible, which tooltip is being shown, and which icon path was last requested. The underlying native resources are released by calling destroy().

#
Tray::destroy

fn Tray::destroy(self : Tray) -> Unit

Releases the underlying native resources and turns the handle into a no-op object that rejects later operations.

#
Tray::hide

fn Tray::hide(self : Tray) -> Result[Bool, String]

Hides the tray icon while keeping the handle valid for later show() calls.

#
Tray::pump

fn Tray::pump(self : Tray, blocking? : Bool) -> Result[Bool, String]

Pumps one native tray loop iteration.

Call this from long-running native applications when the host platform needs event-loop progress from the tray backend. A return value of Ok(false) means the backend asked to stop processing.

#
Tray::set_icon

fn Tray::set_icon(self : Tray, icon : String?) -> Result[Bool, String]

Changes the tray icon path or resets it to the platform default when None is passed.

#
Tray::set_tooltip

fn Tray::set_tooltip(self : Tray, tooltip : String) -> Result[Bool, String]

Replaces the current tooltip text without changing visibility.

Platforms that cannot show a real tooltip may map this value to the nearest native concept available to the host desktop environment.

#
Tray::show

fn Tray::show(self : Tray, tooltip? : String?) -> Result[Bool, String]

Shows the tray icon and optionally replaces the tooltip in the same call.

Passing tooltip=Some(...) is the most efficient way to update the tooltip immediately before the tray becomes visible.

#
create

fn create(identifier? : String, icon? : String?, tooltip? : String) -> Result[Tray, String]

Creates a tray handle with an optional icon path and initial tooltip.

  • identifier should be a stable, non-empty id for the tray instance.
  • icon may be None to request the platform default tray icon.
  • tooltip becomes the initial hover text when the platform supports it.

The returned handle starts hidden, so callers can finish any last setup and then call show().

#
current_platform

fn current_platform() -> Platform

Returns the desktop platform detected by the native backend for the current process.

The value is computed by the native stub so it matches the operating system that actually builds and runs the package.

#
default_identifier

fn default_identifier() -> String

Returns the default identifier used by create() when callers do not provide one.

The identifier is used as the native tray instance id on platforms that require one, and keeping it stable makes logs and diagnostics easier to follow.

#
ensure_supported

fn ensure_supported() -> Result[Unit, String]

Validates that the native backend is available before any tray is created.

Use this when an application wants to show an actionable startup error instead of deferring the failure until create().

#
is_supported

fn is_supported() -> Bool

Returns whether the native backend can create tray instances on the current machine.

On Windows this is expected to be true. On other platforms, or when the required desktop runtime is unavailable, this returns false.

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io