GithubHelp home page GithubHelp logo

ctray's Introduction

CTray Logo CTray Logo

CTray

Cross-platform Node.js class to create system trays.

Note: This package does not support macOS. (See issue #2)

Installation

$ npm install ctray

Usage

Simple Example

let Tray = require("ctray");

let tray = new Tray("path/to/icon");

tray.tooltip = "Simple Example Tray"; // Sets the tooltip to display

tray.menu = [ // Sets the tray menu
    "Example",
    "-",
    {text: "Quit", callback: _ => tray.close()}
]

tray.on("close", () => console.log("Tray Closed"));

See the example file for a more complex example.

Constructor new Tray(icon: string) : Tray

Creates the tray's instance displays the icon on the taskbar. Tray extends from EventEmitter, and it emits "close" once it is closed.

tray#close(): void

Requests the tray to close and emits "close".

tray#tooltip: string

Getter/Setter for the tooltip to show over the tray.

tray#icon: string

Getter/Setter for the absolute path to the icon to display.

tray#menu: MenuItem[]

Setter for the menu of the tray. Each element of the array can either be a String or an Object with the following format:

type MenuItem = {
    text:      string,     // Label of the element in the tray. Required
    checked?:  boolean,    // Item starts checked? defaults: false
    disabled?: boolean,    // Item is disabled? defaults: false
    callback?: () => void, // Function without arguments to run on click.
    submenu?:  MenuItem[], // Array With the same rules as menu
}

Note that getting this property will return the menu Array as an Object to prevent Array functions that add/remove elements as they are not supported.

Setting text = '-' creates a MenuItem of type "separator". Its text cannot be changed nor have submenus.

Next steps

  • Improve documentation.
  • Test in other plattforms.
  • Create package.json Scripts.
  • Allow changing the menu dynamically.
  • Test in MacOS
Notes to self
  • Generate ico from svg command: $ convert -density 2048 -background transparent icon.svg -define icon:auto-resize -colors 256 icon.ico

ctray's People

Contributors

diogoalmiro avatar ibandominguez avatar

Stargazers

lmath avatar Edoardo Ridolfi avatar Hugo avatar Kumar Shivendu avatar

Watchers

James Cloos avatar  avatar

ctray's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.