Convert Figma logo to code with AI

getlantern logosystray

a cross platfrom Go library to place an icon and menu in the notification area

3,357
466
3,357
108

Top Related Projects

2,723

Share a terminal session over WebRTC

14,736

Lantern官方版本下载 蓝灯 翻墙 代理 科学上网 外网 加速器 梯子 路由 - Быстрый, надежный и безопасный доступ к открытому интернету - lantern proxy vpn censorship-circumvention censorship gfw accelerator پراکسی لنترن، ضدسانسور، امن، قابل اعتماد و پرسرعت

18,830

Share your terminal as a web application

Quick Overview

Systray is a cross-platform Go library for creating system tray icons and menus. It provides a simple API to create and manage system tray applications, supporting Windows, macOS, and Linux platforms.

Pros

  • Cross-platform compatibility (Windows, macOS, Linux)
  • Simple and easy-to-use API
  • Supports both icon and menu creation
  • Actively maintained with regular updates

Cons

  • Limited customization options for advanced UI requirements
  • Dependency on external libraries for some platforms
  • Potential performance overhead for complex menus
  • Limited documentation for advanced use cases

Code Examples

Creating a basic system tray icon:

package main

import (
    "github.com/getlantern/systray"
)

func main() {
    systray.Run(onReady, onExit)
}

func onReady() {
    systray.SetIcon(getIcon())
    systray.SetTitle("My App")
    systray.SetTooltip("My App Tooltip")
}

func onExit() {
    // Cleanup code
}

Adding menu items to the system tray:

func onReady() {
    systray.SetIcon(getIcon())
    systray.SetTitle("My App")

    mQuit := systray.AddMenuItem("Quit", "Quit the app")
    go func() {
        <-mQuit.ClickedCh
        systray.Quit()
    }()
}

Updating menu items dynamically:

func onReady() {
    systray.SetIcon(getIcon())
    systray.SetTitle("My App")

    mToggle := systray.AddMenuItem("Toggle", "Toggle state")
    go func() {
        for {
            <-mToggle.ClickedCh
            if mToggle.Checked() {
                mToggle.Uncheck()
                mToggle.SetTitle("Toggled Off")
            } else {
                mToggle.Check()
                mToggle.SetTitle("Toggled On")
            }
        }
    }()
}

Getting Started

  1. Install the library:

    go get github.com/getlantern/systray
    
  2. Import the library in your Go code:

    import "github.com/getlantern/systray"
    
  3. Implement the onReady and onExit functions:

    func onReady() {
        systray.SetIcon(getIcon())
        systray.SetTitle("My App")
        systray.AddMenuItem("Quit", "Quit the app")
    }
    
    func onExit() {
        // Cleanup code
    }
    
  4. Run the systray in your main function:

    func main() {
        systray.Run(onReady, onExit)
    }
    

Competitor Comparisons

2,723

Share a terminal session over WebRTC

Pros of webtty

  • Focuses on terminal sharing over the web, enabling remote access and collaboration
  • Lightweight and easy to set up for quick terminal sharing sessions
  • Supports secure connections using WebRTC

Cons of webtty

  • Limited to terminal sharing functionality, not a general-purpose system tray utility
  • May require additional setup for WebRTC connections and firewall configurations
  • Less actively maintained compared to systray (fewer recent updates)

Code comparison

systray (Go):

systray.Run(onReady, onExit)

func onReady() {
    systray.SetIcon(icon.Data)
    systray.SetTitle("My App")
    mQuit := systray.AddMenuItem("Quit", "Quit the app")
}

webtty (Go):

s := webtty.New(webtty.Options{
    Address: *addr,
    Command: *command,
})
log.Fatal(s.Run(context.Background()))

Summary

systray is a cross-platform system tray library for Go applications, providing a way to create system tray icons and menus. webtty, on the other hand, is a tool for sharing terminal sessions over the web using WebRTC. While systray offers more general-purpose functionality for desktop applications, webtty focuses specifically on terminal sharing and remote access. The choice between the two depends on the specific requirements of your project.

14,736

Lantern官方版本下载 蓝灯 翻墙 代理 科学上网 外网 加速器 梯子 路由 - Быстрый, надежный и безопасный доступ к открытому интернету - lantern proxy vpn censorship-circumvention censorship gfw accelerator پراکسی لنترن، ضدسانسور، امن، قابل اعتماد و پرسرعت

Pros of Lantern

  • Comprehensive censorship circumvention tool with a full-featured application
  • Includes advanced features like peer-to-peer networking and traffic obfuscation
  • Actively maintained with regular updates and improvements

Cons of Lantern

  • Larger codebase and more complex architecture
  • Requires more resources to run and maintain
  • May have a steeper learning curve for contributors

Code Comparison

Systray (Go):

func main() {
    systray.Run(onReady, onExit)
}

func onReady() {
    systray.SetIcon(icon.Data)
    systray.SetTitle("Systray Example")
    mQuit := systray.AddMenuItem("Quit", "Quit the app")
    go func() {
        <-mQuit.ClickedCh
        systray.Quit()
    }()
}

Lantern (Go):

func main() {
    cfg := config.NewConfig()
    client := client.NewClient(cfg)
    ui.Start(cfg, client)
    <-make(chan struct{})
}

The Systray code focuses on creating a system tray icon and menu, while the Lantern code initializes the configuration, client, and user interface components of the application. Systray is more focused on providing a simple system tray functionality, whereas Lantern encompasses a broader range of features for its censorship circumvention tool.

18,830

Share your terminal as a web application

Pros of GoTTY

  • Provides web-based terminal access, enabling remote command-line interaction
  • Supports various authentication methods for secure access
  • Offers customizable UI options and command-line flags for flexibility

Cons of GoTTY

  • Limited to terminal-based applications, not suitable for general GUI interactions
  • Requires more setup and configuration compared to systray's simplicity
  • May have higher resource usage due to web server functionality

Code Comparison

GoTTY (main.go):

func main() {
    app := cli.NewApp()
    app.Name = "gotty"
    app.Version = Version
    app.Usage = "Share your terminal as a web application"
    app.HideHelp = true
    app.Flags = flags
    app.Action = action
    app.Run(os.Args)
}

systray (example/main.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")
    go func() {
        <-mQuit.ClickedCh
        systray.Quit()
    }()
}

The code comparison shows that GoTTY focuses on creating a CLI application for terminal sharing, while systray provides a simple API for creating system tray applications with icons and menus.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

systray

systray is a cross-platform Go library to place an icon and menu in the notification area.

Features

  • Supported on Windows, macOS, and Linux
  • Menu items can be checked and/or disabled
  • Most functions may be called from any goroutine

API

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
}

See full API as well as CHANGELOG.

Note: this package requires cgo, so make sure you set CGO_ENABLED=1 before building.

Try the example app!

Have go v1.12+ or higher installed? Here's an example to get started on macOS:

git clone https://github.com/getlantern/systray
cd systray/example
env GO111MODULE=on go build
./example

On Windows, you should build like this:

env GO111MODULE=on go build -ldflags "-H=windowsgui"

Now look for Awesome App in your menu bar!

Awesome App screenshot

The Webview example

The code under webview_example is to demostrate how it can co-exist with other UI elements. Note that the example doesn't work on macOS versions older than 10.15 Catalina.

Platform notes

Linux

  • Building apps requires gcc as well as the gtk3 and libayatana-appindicator3 development headers to be installed. For Debian or Ubuntu, you may install these using:
sudo apt-get install gcc libgtk-3-dev libayatana-appindicator3-dev

On Linux Mint, libxapp-dev is also required.

If you need to support the older libappindicator3 library instead, you can pass the build flag legacy_appindicator when building. For example:

go build -tags=legacy_appindicator

To build webview_example, you also need to install libwebkit2gtk-4.0-dev and remove webview_example/rsrc.syso which is required on Windows.

Windows

  • To avoid opening a console at application startup, use these compile flags:
go build -ldflags -H=windowsgui

macOS

On macOS, you will need to create an application bundle to wrap the binary; simply folders with the following minimal structure and assets:

SystrayApp.app/
  Contents/
    Info.plist
    MacOS/
      go-executable
    Resources/
      SystrayApp.icns

When running as an app bundle, you may want to add one or both of the following to your Info.plist:

<!-- avoid having a blurry icon and text -->
	<key>NSHighResolutionCapable</key>
	<string>True</string>

	<!-- avoid showing the app on the Dock -->
	<key>LSUIElement</key>
	<string>1</string>

Consult the Official Apple Documentation here.

On macOS, it's possible to set the underlying NSStatusItemBehavior with systray.SetRemovalAllowed(true). When enabled, the user can cmd-drag the icon off the menu bar.

Credits