How getlantern/systray works
Project type and purpose
• Purpose: Expose a uniform Go API (systray.Run, AddMenuItem, etc.) that works on Windows, macOS, and Linux by delegating to underlying native APIs via cgo and platform-specific code.
Main components
a. Core API layer (systray.go)
– Exports Run(onReady, onExit), SetIcon, AddMenuItem, etc.
– Defines common data structures and interface points.
b. Native bindings / backends
– Windows: systray_windows.go, systray_windows_test.go, systray.h, systray_windows.c
– macOS: systray_darwin.go, systray_darwin.m
– Linux:
• GTK: systray_linux.go, systray_linux.c
• AppIndicator/Ayatana: systray_linux_appindicator.go, systray_linux_ayatana.go
– Build tags and CGO glue control which backend is compiled.
c. Examples (clients)
– Webview example (webview_example/): Combines systray with a webview UI (native WebKit/Edge embedding).
d. External dependencies
– OS frameworks (Win32 Shell API, macOS AppKit NSStatusBar, Linux GTK3/AppIndicator3)
– C compiler and headers (via CGO)
Relationships and interactions
• The client (main.go in examples) invokes the Core API.
• Core API dispatches to a platform-specific implementation, selected at compile time by build tags and CGO.
• Platform backend uses CGO to call native C/Objective-C/Win32 functions.
• On Linux, code may further dispatch between GTK and AppIndicator variants.
• Examples link against the same core + backends; the webview example also pulls in a WebView binding layer.
Architectural patterns and design principles
• Adapter/Bridge pattern: Core Go API delegates to different “adapters” per OS.
• Modularity via build tags: Only one platform backend is built into the final binary.
• Minimal surface area: Core remains platform-agnostic; all OS quirks live in backend files.
• Examples as integration tests: Demonstrate usage and co-existence with other UI libraries.