github.com/shurcool/trayhost@v0.0.0-20181020202213-114974ef9e16/README.md (about)

     1  trayhost
     2  ========
     3  
     4  [![Build Status](https://travis-ci.org/shurcooL/trayhost.svg?branch=master)](https://travis-ci.org/shurcooL/trayhost) [![GoDoc](https://godoc.org/github.com/shurcooL/trayhost?status.svg)](https://godoc.org/github.com/shurcooL/trayhost)
     5  
     6  Package trayhost is a cross-platform Go library to place an icon
     7  in the host operating system's taskbar.
     8  
     9  Platform Support
    10  ----------------
    11  
    12  -	macOS - Fully implemented and supported by [@dmitshur](https://github.com/dmitshur).
    13  -	Linux - Partially implemented, but unsupported (needs an owner/maintainer).
    14  -	Windows - Partially implemented, but unsupported (needs an owner/maintainer).
    15  
    16  Notes
    17  -----
    18  
    19  On macOS, for Notification Center user notifications to work, your Go binary that
    20  uses `trayhost` must be a part of a standard macOS app bundle.
    21  
    22  Most other functionality of `trayhost` will be available if the binary is not a part
    23  of app bundle, but you will get a terminal pop up, and you will not be able to
    24  configure some aspects of the app.
    25  
    26  Here's a minimal layout of an app bundle:
    27  
    28  ```
    29  $ tree "Trayhost Example.app"
    30  Trayhost\ Example.app
    31  └── Contents
    32      ├── Info.plist
    33      ├── MacOS
    34      │   └── example
    35      └── Resources
    36          └── Icon.icns
    37  ```
    38  
    39  Here's a minimal `Info.plist` file as reference (only the entries that are needed,
    40  nothing extra):
    41  
    42  ```XML
    43  <?xml version="1.0" encoding="UTF-8"?>
    44  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    45  <plist version="1.0">
    46  <dict>
    47  	<key>CFBundleExecutable</key>
    48  	<string>example</string>
    49  	<key>CFBundleIconFile</key>
    50  	<string>Icon</string>
    51  	<key>CFBundleIdentifier</key>
    52  	<string>ExampleApp</string>
    53  	<key>NSHighResolutionCapable</key>
    54  	<true/>
    55  	<key>LSUIElement</key>
    56  	<string>1</string>
    57  </dict>
    58  </plist>
    59  ```
    60  
    61  -	`CFBundleIdentifier` needs to be set to some value for Notification Center to work.
    62  -	The binary must be inside `Contents/MacOS` directory for Notification Center to work.
    63  -	`NSHighResolutionCapable` to enable Retina mode.
    64  -	`LSUIElement` is needed to make the app not appear in Cmd+Tab list and the dock
    65  while still being able to show a tooltip in the menu bar.
    66  
    67  On macOS, when you run an app bundle, the working directory of the executed process
    68  is the root directory (`/`), not the app bundle's `Contents/Resources` directory.
    69  Change directory to `Resources` if you need to load resources from there.
    70  
    71  ```Go
    72  ep, err := os.Executable()
    73  if err != nil {
    74  	log.Fatalln("os.Executable:", err)
    75  }
    76  err = os.Chdir(filepath.Join(filepath.Dir(ep), "..", "Resources"))
    77  if err != nil {
    78  	log.Fatalln("os.Chdir:", err)
    79  }
    80  ```
    81  
    82  Installation
    83  ------------
    84  
    85  ```bash
    86  go get -u github.com/shurcooL/trayhost
    87  ```