### Build Example App (Windows) Source: https://github.com/getlantern/systray/blob/master/README.md Command to build the example application on Windows, using flags to avoid opening a console window. ```sh env GO111MODULE=on go build -ldflags "-H=windowsgui" ``` -------------------------------- ### Clone and Build Example App (macOS) Source: https://github.com/getlantern/systray/blob/master/README.md Steps to clone the repository and build the example application on macOS. Requires Go v1.12+. ```sh git clone https://github.com/getlantern/systray cd systray/example env GO111MODULE=on go build ./example ``` -------------------------------- ### Install Linux Dependencies (Debian/Ubuntu) Source: https://github.com/getlantern/systray/blob/master/README.md Installs necessary development headers for building systray applications on Debian or Ubuntu. ```sh sudo apt-get install gcc libgtk-3-dev libayatana-appindicator3-dev ``` -------------------------------- ### Start Systray Event Loop with Run Source: https://context7.com/getlantern/systray/llms.txt Initializes the native GUI, registers callbacks, and blocks on the platform event loop. Must be called from the main thread. onReady is executed in a separate goroutine. ```go package main import ( "fmt" "time" "os" "github.com/getlantern/systray" "github.com/getlantern/systray/example/icon" ) func main() { // Run blocks until systray.Quit() is called. systray.Run(onReady, onExit) } func onReady() { systray.SetIcon(icon.Data) systray.SetTitle("My App") systray.SetTooltip("My App is running") mQuit := systray.AddMenuItem("Quit", "Exit the application") go func() { <-mQuit.ClickedCh systray.Quit() }() } func onExit() { // Cleanup runs on the event loop thread before process exits fmt.Println("Exiting at:", time.Now()) os.WriteFile("exit_time.txt", []byte(time.Now().String()), 0644) } ``` -------------------------------- ### systray.Run Source: https://context7.com/getlantern/systray/llms.txt Starts the systray event loop and blocks until Quit() is called. It initializes the native GUI and registers callbacks for application readiness (onReady) and exit (onExit). Must be called from the main thread. ```APIDOC ## systray.Run — Start the systray event loop ### Description `Run` initializes the native GUI, registers the `onReady` and `onExit` callbacks, and blocks on the platform event loop until `Quit()` is called. Must be called from the main thread (especially on macOS). `onReady` is executed in a separate goroutine; `onExit` runs on the event loop thread to guarantee it completes before process exit. ### Usage Example ```go package main import ( "fmt" time os "github.com/getlantern/systray" "github.com/getlantern/systray/example/icon" ) func main() { // Run blocks until systray.Quit() is called. systray.Run(onReady, onExit) } func onReady() { systray.SetIcon(icon.Data) systray.SetTitle("My App") systray.SetTooltip("My App is running") mQuit := systray.AddMenuItem("Quit", "Exit the application") go func() { <- mQuit.ClickedCh systray.Quit() }() } func onExit() { // Cleanup runs on the event loop thread before process exits fmt.Println("Exiting at:", time.Now()) os.WriteFile("exit_time.txt", []byte(time.Now().String()), 0644) } ``` ``` -------------------------------- ### Run Systray Application Source: https://github.com/getlantern/systray/blob/master/README.md Basic structure for running a systray application. Requires `onReady` and `onExit` callback functions. ```go func main() { systray.Run(onReady, onExit) } func onReady() { systray.SetIcon(icon.Data) systray.SetTitle("Awesome App") systray.SetTooltip("Pretty awesome超级棒") mQuit := systray.AddMenuItem("Quit", "Quit the whole app") // Sets the icon of a menu item. Only available on Mac and Windows. mQuit.SetIcon(icon.Data) } func onExit() { // clean up here } ``` -------------------------------- ### Build Windows GUI Application Source: https://github.com/getlantern/systray/blob/master/README.md Compile flags for building a Windows application that does not open a console window at startup. ```sh go build -ldflags -H=windowsgui ``` -------------------------------- ### Build with Legacy Appindicator (Linux) Source: https://github.com/getlantern/systray/blob/master/README.md Build flag to support the older `libappindicator3` library on Linux. ```sh go build -tags=legacy_appindicator ``` -------------------------------- ### Register Callbacks Without Blocking with Register Source: https://context7.com/getlantern/systray/llms.txt Sets up the systray and registers callbacks without taking over the main thread's event loop. Useful when running another UI framework alongside systray. On macOS versions before Catalina, this behaves identically to Run. ```go package main import ( "github.com/getlantern/systray" "github.com/getlantern/systray/example/icon" ) func main() { // Register returns immediately; the caller drives the event loop elsewhere. systray.Register(onReady, nil) // Run your own event loop here — e.g., a webview or other UI toolkit. runWebview("My App", 1024, 768) // hypothetical webview loop } func onReady() { systray.SetTemplateIcon(icon.Data, icon.Data) systray.SetTitle("Webview App") mOpen := systray.AddMenuItem("Open Window", "Show the webview") mQuit := systray.AddMenuItem("Quit", "Quit the app") go func() { for { select { case <-mOpen.ClickedCh: showWebview("https://example.com") case <-mQuit.ClickedCh: systray.Quit() return } } }() } ``` -------------------------------- ### Set Systray Icon from Bytes Source: https://context7.com/getlantern/systray/llms.txt Sets the systray icon from raw image bytes. Call this any time after onReady fires to update the icon dynamically. Supports .ico on Windows and .ico, .jpg, or .png on macOS/Linux. ```go import "os" func onReady() { // Load from embedded bytes iconData, err := os.ReadFile("assets/icon.png") if err != nil { panic(err) } systray.SetIcon(iconData) // Later, swap the icon dynamically from another goroutine: go func() { time.Sleep(5 * time.Second) activeIcon, _ := os.ReadFile("assets/icon_active.png") systray.SetIcon(activeIcon) }() } ``` -------------------------------- ### Toggle Menu Item Visibility Source: https://context7.com/getlantern/systray/llms.txt Use `Hide()` and `Show()` to control the visibility of a menu item without removing it. Hidden items retain their state and can be shown later. ```go func onReady() { mPause := systray.AddMenuItem("Pause", "Pause the service") mResume := systray.AddMenuItem("Resume", "Resume the service") mResume.Hide() // not relevant until paused go func() { for { select { case <-mPause.ClickedCh: pauseService() mPause.Hide() mResume.Show() case <-mResume.ClickedCh: resumeService() mResume.Hide() mPause.Show() } } }() } ``` -------------------------------- ### macOS Info.plist Keys Source: https://github.com/getlantern/systray/blob/master/README.md XML snippets for `Info.plist` to configure application behavior on macOS, such as high-resolution icon support and hiding from the Dock. ```xml NSHighResolutionCapable True LSUIElement 1 ``` -------------------------------- ### Set Template Icon (macOS) with Regular Fallback Source: https://context7.com/getlantern/systray/llms.txt Sets the tray icon as a macOS template icon, which automatically adapts to light/dark mode. Falls back to regularIconBytes on Windows and Linux. Use this instead of SetIcon for best visual results on macOS. ```go func onReady() { // templateIconBytes: monochrome icon for macOS template rendering // regularIconBytes: full-color icon for Windows/Linux systray.SetTemplateIcon(icon.TemplateData, icon.RegularData) } ``` -------------------------------- ### Set Per-Item Icons Source: https://context7.com/getlantern/systray/llms.txt Use `SetIcon()` for standard icons on macOS and Windows, and `SetTemplateIcon()` for macOS template icons that adapt to dark/light mode. Ensure icon data is loaded correctly. ```go func onReady() { mOpen := systray.AddMenuItem("Open App", "Show the main window") iconData, err := os.ReadFile("assets/open_icon.png") if err == nil { // Use template icon on macOS, regular icon on Windows mOpen.SetTemplateIcon(iconData, iconData) } mQuit := systray.AddMenuItem("Quit", "Quit") quitIcon, err := os.ReadFile("assets/quit_icon.ico") if err == nil { mQuit.SetIcon(quitIcon) // macOS and Windows only } } ``` -------------------------------- ### Enable/Disable Menu Item Source: https://context7.com/getlantern/systray/llms.txt Use `Enable()` and `Disable()` to control the interactive state of a menu item. Disabled items are grayed out and do not trigger click events. ```go func onReady() { mConnect := systray.AddMenuItem("Connect", "Connect to server") mDisconnect := systray.AddMenuItem("Disconnect", "Disconnect from server") mDisconnect.Disable() // greyed out at start go func() { for { select { case <-mConnect.ClickedCh: connect() mConnect.Disable() mDisconnect.Enable() case <-mDisconnect.ClickedCh: disconnect() mDisconnect.Disable() mConnect.Enable() } } }() } ``` -------------------------------- ### systray.SetIcon Source: https://context7.com/getlantern/systray/llms.txt Sets the system tray icon using raw image bytes. Supports .ico on Windows and .ico, .jpg, or .png on macOS/Linux. Can be called anytime after onReady to update the icon. ```APIDOC ## systray.SetIcon — Set the tray icon ### Description Sets the systray icon from raw image bytes (`.ico` on Windows; `.ico`, `.jpg`, or `.png` on macOS/Linux). Call this any time after `onReady` fires to update the icon dynamically. ### Usage Example ```go import "os" func onReady() { // Load from embedded bytes iconData, err := os.ReadFile("assets/icon.png") if err != nil { panic(err) } systray.SetIcon(iconData) // Later, swap the icon dynamically from another goroutine: go func() { time.Sleep(5 * time.Second) activeIcon, _ := os.ReadFile("assets/icon_active.png") systray.SetIcon(activeIcon) }() } ``` ``` -------------------------------- ### Set Icon/SetTemplateIcon Source: https://context7.com/getlantern/systray/llms.txt Set icons for individual menu items. `SetIcon` is for macOS and Windows. `SetTemplateIcon` is for macOS template icons and falls back on Windows. ```APIDOC ## (*MenuItem).SetIcon / (*MenuItem).SetTemplateIcon ### Description Sets an icon on an individual menu item. `SetIcon` works on macOS and Windows. `SetTemplateIcon` renders as a macOS template icon (adapts to dark/light mode) and falls back to the regular icon bytes on Windows; does nothing on Linux. ### Method - `SetIcon(icon []byte)` - `SetTemplateIcon(icon []byte, darkIcon []byte)` ### Example ```go iconData, _ := os.ReadFile("assets/open_icon.png") mOpen.SetTemplateIcon(iconData, iconData) quitIcon, _ := os.ReadFile("assets/quit_icon.ico") mQuit.SetIcon(quitIcon) ``` ``` -------------------------------- ### Manage Checkbox State of Menu Item Source: https://context7.com/getlantern/systray/llms.txt Use `Check()`, `Uncheck()`, and `Checked()` to programmatically manage the checkbox state of a menu item. This is useful for toggleable options. ```go func onReady() { mVPN := systray.AddMenuItemCheckbox("VPN Enabled", "Toggle VPN", false) go func() { for range mVPN.ClickedCh { if mVPN.Checked() { mVPN.Uncheck() mVPN.SetTitle("VPN Disabled") stopVPN() } else { mVPN.Check() mVPN.SetTitle("VPN Enabled") startVPN() } } }() } ``` -------------------------------- ### systray.SetTooltip Source: https://context7.com/getlantern/systray/llms.txt Sets the tooltip text that appears when a user hovers over the tray icon. Supports Unicode characters. ```APIDOC ## systray.SetTooltip — Set the tray icon tooltip ### Description Sets the tooltip text shown when the user hovers over the tray icon. Supports Unicode. ### Method `systray.SetTooltip(tooltip string)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go systray.SetTooltip("My App — Connected") ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### systray.SetTitle Source: https://context7.com/getlantern/systray/llms.txt Sets the text displayed next to the tray icon. This is particularly visible on macOS in the menu bar. ```APIDOC ## systray.SetTitle — Set the tray title text ### Description Sets text displayed next to the tray icon. On macOS this text appears in the menu bar; on Windows and Linux it may not be visible depending on the desktop environment. ### Method `systray.SetTitle(title string)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go systray.SetTitle("My App") ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Set Systray Title Text Source: https://context7.com/getlantern/systray/llms.txt Sets the text displayed next to the tray icon. On macOS, this appears in the menu bar. On Windows and Linux, visibility depends on the desktop environment. ```go func onReady() { systray.SetTitle("My App") // shown next to icon on macOS } // Dynamically update it from a goroutine: func updateStatus(connected bool) { if connected { systray.SetTitle("My App ●") } else { systray.SetTitle("My App ○") } } ``` -------------------------------- ### (*MenuItem).SetTitle / (*MenuItem).SetTooltip Source: https://context7.com/getlantern/systray/llms.txt Dynamically updates the title or tooltip text of an existing menu item at runtime. ```APIDOC ## (*MenuItem).SetTitle / (*MenuItem).SetTooltip — Update item text dynamically ### Description Updates the visible title or tooltip of an existing menu item at runtime. Both are safe to call from any goroutine. ### Method `(*MenuItem).SetTitle(title string)` `(*MenuItem).SetTooltip(tooltip string)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go mStatus := systray.AddMenuItem("Status: Disconnected", "Connection status") mStatus.SetTitle("Status: Connected") mStatus.SetTooltip("Connected to server") ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Add Checkable Menu Item Source: https://context7.com/getlantern/systray/llms.txt Creates a menu item with an explicit checkbox state, required for checkbox behavior on Linux. On Windows and macOS, this is equivalent to AddMenuItem. ```go func onReady() { // Start checked=true mNotifications := systray.AddMenuItemCheckbox("Notifications", "Toggle notifications", true) mAutoStart := systray.AddMenuItemCheckbox("Start at Login", "Launch on system startup", false) go func() { for { select { case <-mNotifications.ClickedCh: if mNotifications.Checked() { mNotifications.Uncheck() disableNotifications() } else { mNotifications.Check() enableNotifications() } case <-mAutoStart.ClickedCh: if mAutoStart.Checked() { mAutoStart.Uncheck() } else { mAutoStart.Check() } } } }() } ``` -------------------------------- ### Dynamically Update Menu Item Text Source: https://context7.com/getlantern/systray/llms.txt Updates the visible title or tooltip of an existing menu item at runtime. Both methods are safe to call from any goroutine. ```go func onReady() { mStatus := systray.AddMenuItem("Status: Disconnected", "Connection status") go func() { for event := range connectionEvents { if event.Connected { mStatus.SetTitle("Status: Connected") mStatus.SetTooltip("Connected to " + event.ServerName) } else { mStatus.SetTitle("Status: Disconnected") mStatus.SetTooltip("Not connected") } } }() } ``` -------------------------------- ### systray.AddMenuItem Source: https://context7.com/getlantern/systray/llms.txt Adds a new top-level menu item to the systray menu. Returns a pointer to the created MenuItem. ```APIDOC ## systray.AddMenuItem — Add a top-level menu item ### Description Creates and returns a `*MenuItem` with the given title and tooltip. The returned item's `ClickedCh` channel receives an empty struct when clicked. Safe to call from any goroutine. On Windows and macOS items are checkable by default; on Linux use `AddMenuItemCheckbox` for checkable items. ### Method `systray.AddMenuItem(title string, tooltip string) *MenuItem` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go mAbout := systray.AddMenuItem("About", "About this app") ``` ### Response #### Success Response (200) Returns a `*MenuItem` object. #### Response Example None ``` -------------------------------- ### systray.SetTemplateIcon Source: https://context7.com/getlantern/systray/llms.txt Sets a template icon for macOS that automatically adapts to light/dark mode. Falls back to a regular icon on Windows and Linux. Recommended for better visual integration on macOS. ```APIDOC ## systray.SetTemplateIcon — Set a template icon (macOS) with regular fallback ### Description Sets the tray icon as a macOS template icon (automatically adapts to light/dark mode). Falls back to `regularIconBytes` on Windows and Linux. Use this instead of `SetIcon` for best visual results on macOS. ### Usage Example ```go func onReady() { // templateIconBytes: monochrome icon for macOS template rendering // regularIconBytes: full-color icon for Windows/Linux systray.SetTemplateIcon(icon.TemplateData, icon.RegularData) } ``` ``` -------------------------------- ### Add Top-Level Menu Item Source: https://context7.com/getlantern/systray/llms.txt Creates a top-level menu item with a title and tooltip. The returned item's ClickedCh channel receives an empty struct when clicked. Safe to call from any goroutine. On Windows and macOS, items are checkable by default; on Linux, use AddMenuItemCheckbox for checkable items. ```go func onReady() { mAbout := systray.AddMenuItem("About", "About this app") mPrefs := systray.AddMenuItem("Preferences", "Open preferences") mQuit := systray.AddMenuItem("Quit", "Quit the application") go func() { for { select { case <-mAbout.ClickedCh: fmt.Println("Show about dialog") case <-mPrefs.ClickedCh: fmt.Println("Open preferences window") case <-mQuit.ClickedCh: systray.Quit() return } } }() } ``` -------------------------------- ### Set Systray Tooltip Text Source: https://context7.com/getlantern/systray/llms.txt Sets the tooltip text shown when the user hovers over the tray icon. Supports Unicode and can be called from any goroutine. ```go func onReady() { systray.SetTooltip("My App — Connected") // Can be called anytime from any goroutine go func() { for status := range statusUpdates { systray.SetTooltip(fmt.Sprintf("My App — %s", status)) } }() } ``` -------------------------------- ### Programmatically Quit Systray Source: https://context7.com/getlantern/systray/llms.txt Signals the event loop to stop, triggering the onExit callback. It is safe to call from any goroutine and uses sync.Once internally so multiple calls are a no-op. ```go func onReady() { mQuit := systray.AddMenuItem("Quit", "Quit the whole app") go func() { <-mQuit.ClickedCh fmt.Println("Quit requested by user") systray.Quit() // Any code here runs after the quit signal is sent but the // event loop may still be winding down. fmt.Println("Quit signal dispatched") }() } ``` -------------------------------- ### systray.AddMenuItemCheckbox Source: https://context7.com/getlantern/systray/llms.txt Adds a checkable menu item. This is necessary for checkbox behavior on Linux systems. ```APIDOC ## systray.AddMenuItemCheckbox — Add a checkable menu item ### Description Creates a `*MenuItem` with an explicit checkbox state, required for checkbox behavior on Linux. On Windows and macOS this is equivalent to `AddMenuItem` (all items are checkable there). ### Method `systray.AddMenuItemCheckbox(title string, tooltip string, checked bool) *MenuItem` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go mNotifications := systray.AddMenuItemCheckbox("Notifications", "Toggle notifications", true) ``` ### Response #### Success Response (200) Returns a `*MenuItem` object. #### Response Example None ``` -------------------------------- ### Hide/Show Menu Item Source: https://context7.com/getlantern/systray/llms.txt Toggle the visibility of a menu item. Hidden items can be shown again later without losing their state. ```APIDOC ## (*MenuItem).Hide / (*MenuItem).Show ### Description Hides or reveals a menu item without removing it. Hidden items retain their state and can be shown again at any time. ### Method - `Hide()` - `Show()` ### Example ```go mResume.Hide() // Hide the resume button initially mPause.Show() // Show the pause button when needed ``` ``` -------------------------------- ### systray.Register Source: https://context7.com/getlantern/systray/llms.txt Registers callbacks for systray events without blocking the main thread's event loop. This is useful when integrating with other UI frameworks. On older macOS versions, it behaves like Run. ```APIDOC ## systray.Register — Register callbacks without blocking ### Description `Register` sets up the systray and registers the callbacks but does not take over the main thread's event loop. This is useful when the application needs to run another UI framework (e.g., a webview) alongside the systray. On macOS versions before Catalina, this behaves identically to `Run`. ### Usage Example ```go package main import ( "github.com/getlantern/systray" "github.com/getlantern/systray/example/icon" ) func main() { // Register returns immediately; the caller drives the event loop elsewhere. systray.Register(onReady, nil) // Run your own event loop here — e.g., a webview or other UI toolkit. runWebview("My App", 1024, 768) // hypothetical webview loop } func onReady() { systray.SetTemplateIcon(icon.Data, icon.Data) systray.SetTitle("Webview App") mOpen := systray.AddMenuItem("Open Window", "Show the webview") mQuit := systray.AddMenuItem("Quit", "Quit the app") go func() { for { select { case <- mOpen.ClickedCh: showWebview("https://example.com") case <- mQuit.ClickedCh: systray.Quit() return } } }() } ``` ``` -------------------------------- ### systray.Quit Source: https://context7.com/getlantern/systray/llms.txt Programmatically quits the systray application. This function signals the event loop to stop, which in turn triggers the onExit callback. It is safe to call from any goroutine. ```APIDOC ## systray.Quit — Programmatically quit the systray ### Description `Quit` signals the event loop to stop, triggering the `onExit` callback. It is safe to call from any goroutine and uses `sync.Once` internally so multiple calls are a no-op. ### Usage Example ```go func onReady() { mQuit := systray.AddMenuItem("Quit", "Quit the whole app") go func() { <- mQuit.ClickedCh fmt.Println("Quit requested by user") systray.Quit() // Any code here runs after the quit signal is sent but the // event loop may still be winding down. fmt.Println("Quit signal dispatched") }() } ``` ``` -------------------------------- ### (*MenuItem).AddSubMenuItem Source: https://context7.com/getlantern/systray/llms.txt Adds a nested submenu item under an existing menu item, allowing for hierarchical menu structures. ```APIDOC ## (*MenuItem).AddSubMenuItem — Add a nested submenu item ### Description Creates a child `*MenuItem` under an existing item, forming a hierarchical submenu. Supports arbitrary nesting depth. Use `AddSubMenuItemCheckbox` for checkable children on Linux. ### Method `(*MenuItem).AddSubMenuItem(title string, tooltip string) *MenuItem` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go subMenuTop := systray.AddMenuItem("View", "View options") mZoomIn := subMenuTop.AddSubMenuItem("Zoom In", "Increase zoom level") ``` ### Response #### Success Response (200) Returns a `*MenuItem` object representing the submenu item. #### Response Example None ``` -------------------------------- ### Enable/Disable/Disabled Menu Item Source: https://context7.com/getlantern/systray/llms.txt Control the enabled state of a menu item. Disabled items are grayed out and do not trigger click events. The `Disabled()` method returns the current enabled state. ```APIDOC ## (*MenuItem).Enable / (*MenuItem).Disable / (*MenuItem).Disabled ### Description Enables or disables a menu item. Disabled items are grayed out and their `ClickedCh` does not fire. `Disabled()` returns the current state. ### Method - `Enable()` - `Disable()` - `Disabled() bool` ### Example ```go mDisconnect.Disable() // Initially disabled mConnect.Enable() // Enable when needed isDisabled := mDisconnect.Disabled() ``` ``` -------------------------------- ### Add Nested Submenu Item Source: https://context7.com/getlantern/systray/llms.txt Creates a child menu item under an existing item, forming a hierarchical submenu. Supports arbitrary nesting depth. Use AddSubMenuItemCheckbox for checkable children on Linux. ```go func onReady() { subMenuTop := systray.AddMenuItem("View", "View options") mZoomIn := subMenuTop.AddSubMenuItem("Zoom In", "Increase zoom level") mZoomOut := subMenuTop.AddSubMenuItem("Zoom Out", "Decrease zoom level") subMenuThemes := subMenuTop.AddSubMenuItem("Theme", "Select theme") mLight := subMenuThemes.AddSubMenuItem("Light", "Light theme") mDark := subMenuThemes.AddSubMenuItemCheckbox("Dark", "Dark theme", false) go func() { for { select { case <-mZoomIn.ClickedCh: adjustZoom(+1) case <-mZoomOut.ClickedCh: adjustZoom(-1) case <-mLight.ClickedCh: setTheme("light") case <-mDark.ClickedCh: if mDark.Checked() { mDark.Uncheck() setTheme("light") } else { mDark.Check() setTheme("dark") } } } }() } ``` -------------------------------- ### Add Separator to Menu Source: https://context7.com/getlantern/systray/llms.txt Inserts a horizontal separator bar into the menu at the current position to group related menu items visually. ```go func onReady() { systray.AddMenuItem("Open", "Open the app window") systray.AddMenuItem("Settings", "Open settings") systray.AddSeparator() systray.AddMenuItem("Quit", "Quit the application") } ``` -------------------------------- ### Check/Uncheck/Checked Menu Item Source: https://context7.com/getlantern/systray/llms.txt Manage the checkbox state of a menu item. Programmatically set or remove the check mark, and retrieve the current checked state. ```APIDOC ## (*MenuItem).Check / (*MenuItem).Uncheck / (*MenuItem).Checked ### Description Programmatically sets or removes the check mark on a menu item, and reads the current checked state. ### Method - `Check()` - `Uncheck()` - `Checked() bool` ### Example ```go mVPN.Check() // Check the item mVPN.Uncheck() // Uncheck the item isChecked := mVPN.Checked() // Get current state ``` ``` -------------------------------- ### systray.AddSeparator Source: https://context7.com/getlantern/systray/llms.txt Inserts a horizontal separator line into the systray menu to visually group items. ```APIDOC ## systray.AddSeparator — Add a visual separator ### Description Inserts a horizontal separator bar into the menu at the current position to group related menu items visually. ### Method `systray.AddSeparator()` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go systray.AddSeparator() ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Allow User to Remove Menu Bar Icon (macOS) Source: https://context7.com/getlantern/systray/llms.txt Set `systray.SetRemovalAllowed(true)` to enable the macOS `NSStatusItemBehaviorRemovalAllowed` behavior, allowing users to cmd-drag the icon off the menu bar. This has no effect on other operating systems. ```go func onReady() { mAllowRemoval := systray.AddMenuItem("Allow Icon Removal", "Let user cmd-drag icon away (macOS)") go func() { <-mAllowRemoval.ClickedCh systray.SetRemovalAllowed(true) mAllowRemoval.Disable() mAllowRemoval.SetTitle("Icon Removal Allowed") }() } ``` -------------------------------- ### SetRemovalAllowed Source: https://context7.com/getlantern/systray/llms.txt Allow the user to remove the menu bar icon on macOS. This enables the `NSStatusItemBehaviorRemovalAllowed` behavior. ```APIDOC ## systray.SetRemovalAllowed ### Description Allow user to remove the menu bar icon (macOS only). When set to `true`, enables the macOS `NSStatusItemBehaviorRemovalAllowed` behavior, allowing the user to cmd-drag the icon off the menu bar. Has no effect on Windows or Linux. ### Method - `SetRemovalAllowed(allowed bool)` ### Example ```go systray.SetRemovalAllowed(true) ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.