Cross-platform Go library to place an icon in the host operating system's taskbar.

Overview

trayhost

Build Status GoDoc

Package trayhost is a cross-platform Go library to place an icon in the host operating system's taskbar.

Platform Support

  • macOS - Fully implemented and supported by @dmitshur.
  • Linux - Partially implemented, but unsupported (needs an owner/maintainer).
  • Windows - Partially implemented, but unsupported (needs an owner/maintainer).

Notes

On macOS, for Notification Center user notifications to work, your Go binary that uses trayhost must be a part of a standard macOS app bundle.

Most other functionality of trayhost will be available if the binary is not a part of app bundle, but you will get a terminal pop up, and you will not be able to configure some aspects of the app.

Here's a minimal layout of an app bundle:

$ tree "Trayhost Example.app"
Trayhost\ Example.app
└── Contents
    ├── Info.plist
    ├── MacOS
    │   └── example
    └── Resources
        └── Icon.icns

Here's a minimal Info.plist file as reference (only the entries that are needed, nothing extra):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleExecutable</key>
	<string>example</string>
	<key>CFBundleIconFile</key>
	<string>Icon</string>
	<key>CFBundleIdentifier</key>
	<string>ExampleApp</string>
	<key>NSHighResolutionCapable</key>
	<true/>
	<key>LSUIElement</key>
	<string>1</string>
</dict>
</plist>
  • CFBundleIdentifier needs to be set to some value for Notification Center to work.
  • The binary must be inside Contents/MacOS directory for Notification Center to work.
  • NSHighResolutionCapable to enable Retina mode.
  • LSUIElement is needed to make the app not appear in Cmd+Tab list and the dock while still being able to show a tooltip in the menu bar.

On macOS, when you run an app bundle, the working directory of the executed process is the root directory (/), not the app bundle's Contents/Resources directory. Change directory to Resources if you need to load resources from there.

ep, err := os.Executable()
if err != nil {
	log.Fatalln("os.Executable:", err)
}
err = os.Chdir(filepath.Join(filepath.Dir(ep), "..", "Resources"))
if err != nil {
	log.Fatalln("os.Chdir:", err)
}

Installation

go get -u github.com/shurcooL/trayhost
Comments
  • Provided example does not work because the default working directory has unexpected value.

    Provided example does not work because the default working directory has unexpected value.

    On OS X, when you run an app bundle, the working directory of the executed process is the root directory (/), and not the app bundle's Example.app/Contents/Resources folder.

    As a result, the provided example is unlikely to work, because the library needs a valid image file as the 2nd parameter to trayhost.Initialize, and if the user places an image like [email protected] in Resources folder and writes code:

    // Tray icon.
    iconData, err := ioutil.ReadFile("[email protected]")
    if err != nil {
        log.Fatalln(err)
    }
    

    They'll get an error like:

    2016/08/01 20:51:47 open [email protected]: no such file or directory
    

    Because /[email protected] file doesn't exist.

    /cc @jacobrosenthal

    opened by dmitshur 5
  • Fix compile error for windows platform

    Fix compile error for windows platform

    ../.go/src/github.com/shurcooL/trayhost/platform/windows/tray.c:72:9: warning: ‘return’ with no value, in function returning non-void
             return;
             ^
    
    opened by tmm1 2
  • platform/darwin: Make NSStatusItem image a template.

    platform/darwin: Make NSStatusItem image a template.

    This removes the need to manually compute and set an alternate image.

    This allows trayhost to work as expected on macOS 10.14 when using Dark Mode.

    References:

    • https://developer.apple.com/documentation/appkit/supporting_dark_mode_in_your_interface
    • https://developer.apple.com/documentation/appkit/images_and_pdf/providing_images_for_different_appearances
    • https://stackoverflow.com/questions/24623559/nsstatusitem-change-image-for-dark-tint/24644754#24644754

    Fixes pavben/InstantShare#32.

    opened by dmitshur 1
  • OS X support to get clipboard files.

    OS X support to get clipboard files.

    This is needed to close https://github.com/pavben/InstantShare/issues/9.

    Updated: Switch to a combined func GetClipboardContent() (ClipboardContent, error) method. It returns the contents of the system clipboard.

    type ClipboardContent struct {
        Text  string
        Image Image
        Files []string
    }
    

    ~~The GetClipboardFiles() []string method returns the filepaths to files that are copied to clipboard, if any.~~

    ~~E.g.,~~

    ~~GetClipboardFiles(): [/Users/Dmitri/Local/OSes/ubuntu-14.04-desktop-amd64.iso /Users/Dmitri/Local/OSes/ubuntu-12.04.2-server-amd64.iso] len(2) <nil>~~

    opened by dmitshur 1
  • Add CONTRIBUTING.md to describe the suggested contribution process.

    Add CONTRIBUTING.md to describe the suggested contribution process.

    A short version:

    I should add a CONTRIBUTING.md but basically if it's non-OS-X implementation, those are not complete and can use work - feel free to take ownership there. As far as OS X stuff goes, bug fixes or obvious improvements are welcome as PRs. If you see a missing feature or want to suggest an API change (improvement), I'm glad to hear it but open an issue first. :simple_smile:

    Make that text nicer and turn it into a CONTRIBUTING.md file.

    opened by dmitshur 0
  • Mac error at runtime

    Mac error at runtime

    shurcooL/trayhost/platform/darwin/tray.m:122:17: warning: 'setImage:' is deprecated: first deprecated in macOS 10.14

    Here: https://github.com/shurcooL/trayhost/blob/master/platform/darwin/tray.m#L122

    opened by gedw99 0
  • Error: does not EnterLoop

    Error: does not EnterLoop

    Platform: macOS Sometimes it just skips EnterLoop and so it closes the program. I have my trayhost.EnterLoop() as the last line in my code, and sometimes it just does not enter the loop and goes to the end of main.

    If I launch the app, it says ***Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'

    opened by 0xfederama 0
  • Image is picky about specific formats

    Image is picky about specific formats

    I tried running trayhost with an arbitrary png I found online. It panicked because it decoded to image.Palletted rather than image.NRGBA.

    Perhaps the invert routine could be relaxed to work more generally.

    Or maybe https://godoc.org/github.com/disintegration/imaging would be a good alternative. They have a simple invert function that works on any image.

    thinking 
    opened by captncraig 1
  • Exit app from separate goroutine

    Exit app from separate goroutine

    Hello again,

    I was curious if there was a way to exit the gui thread from a separate thread? Since the "main" thread is stuck in the C loop the bulk of the application is running in one or more goroutines. However if something happens and the app needs to exit, the best I can do is tell the user, and when the other goroutines quit/exit/return the main loop gets stuck and cannot exit without user intervention (the rest of the app being "dead" at this point).

    A workaround is to call os.Exit after some delay to allow defered functions in the other goroutines a chance to run, but that doesn't seem very good. I'm using lxn/walk for the Windows version and it has a Synchronize function https://godoc.org/github.com/lxn/walk#WindowBase.Synchronize to call funcs from the main thread/goroutine, is something like this possible? Thanks

    enhancement help wanted 
    opened by iaburton 1
Owner
null
An experimental Go cross platform UI library.

GXUI - A Go cross platform UI library. Notice: Unfortunately due to a shortage of hours in a day, GXUI is no longer maintained. If you're looking for

Google 4.5k Nov 10, 2022
Tiny cross-platform webview library for C/C++/Golang. Uses WebKit (Gtk/Cocoa) and Edge (Windows)

webview A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. Also, there are Rust bindings, Python bindings, Ni

webview 10.7k Nov 23, 2022
Go cross-platform library for displaying dialogs and input boxes

dlgs dlgs is a cross-platform library for displaying dialogs and input boxes. Installation go get -u github.com/gen2brain/dlgs Documentation Document

Milan Nikolic 367 Nov 9, 2022
Tiny cross-platform webview library for C/C++/Golang. Uses WebKit (Gtk/Cocoa) and Edge (Windows)

webview A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. Also, there are Rust bindings, Python bindings, Ni

webview 10.7k Nov 21, 2022
Cross-platform Go/Golang GUI library.

中文 | English GoVCL Cross-platform Golang GUI library, The core binding is liblcl, a common cross-platform GUI library created by Lazarus. GoVCL is a n

不在乎y 1.7k Nov 19, 2022
Built Virtual Operating System and integrated application like calculator, gallery app , weather app, and text editor.

Virtual Operating System Built Virtual Operating System and integrated application like calculator, gallery app , weather app, and text editor. Langua

null 0 Nov 2, 2021
Cross platform GUI in Go based on Material Design

About Fyne is an easy to use UI toolkit and app API written in Go. It is designed to build applications that run on desktop and mobile devices with a

Fyne.io 18.8k Nov 22, 2022
Build cross-platform modern desktop apps in Go + HTML5

Lorca A very small library to build modern HTML5 desktop apps in Go. It uses Chrome browser as a UI layer. Unlike Electron it doesn't bundle Chrome in

Serge Zaitsev 7.5k Nov 24, 2022
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by Electron)

Thanks to go-astilectron build cross platform GUI apps with GO and HTML/JS/CSS. It is the official GO bindings of astilectron and is powered by Electr

Quentin Renard 4.6k Nov 18, 2022
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs)

gowd Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs) How to use this library: Download and install nwjs Install this library g

Danny 385 Nov 16, 2022
RobotGo, Go Native cross-platform GUI automation @vcaesar

Robotgo Golang Desktop Automation. Control the mouse, keyboard, bitmap, read the screen, Window Handle and global event listener. RobotGo supports Mac

vgo 8k Nov 22, 2022
Cross-platform GUI for go is never this easy and clean.

gimu Strongly suggest NOT to use this project anymore, the auto-generated cgo wrapper of Nuklear has a random crash issue which is hard to fix (becaus

Allen Dang 66 Jul 12, 2022
A cross-platform app-development module for Go.

The cross-platform Go module for building apps (pronounced klo-va-seed). Usecases As a lightweight alternative to Electron Write your frontend and nat

Qlova Limited 102 Nov 12, 2022
pure go, cross-platform, MIT-licensed ui toolkit for developers

duit - developer ui toolkit WARNING: this library is work in progress. backwards incompatible changes will be made. details duit is a pure go (*), cro

Mechiel Lukkien 868 Nov 14, 2022
Cross platform rapid GUI framework for golang based on Dear ImGui.

giu Cross platform rapid GUI framework for golang based on Dear ImGui and the great golang binding imgui-go. Any contribution (features, widgets, tuto

Allen Dang 1.6k Nov 20, 2022
Cross-Platform GUI Framework for Go

⚠️ I'm currently working on this project as part of my master's thesis at the Berlin University of Applied Sciences and Technology. It is under active

Jannis Rieger 3 Oct 31, 2022
Kita is a declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase

Kita is a declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase. Inspired by Flutter, React. S

zhuah 106 Apr 18, 2022
UIKit - A declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase

UIKit - A declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase

zhuah 106 Apr 18, 2022
Platform-native GUI library for Go.

ui: platform-native GUI library for Go This is a library that aims to provide simple GUI software development in Go. It is based on my libui, a simple

Pietro Gagliardi 8.2k Nov 28, 2022