Skip to content

A cross-platform systray library for node.js with precompiled binaries.

License

Notifications You must be signed in to change notification settings

Edgar-P-yan/node-systray-v2

Repository files navigation

node-systray-v2

Continuous Integrations License NPM Badge install size

node-systray-v2 is a very simple cross-platform systray library for node.js with precompiled binaries. It is a successor of the now unmaintained library node-systray. It picks and uses precompiled executables under the hood based on what OS it's running on and communicates with them through stdin/stdout, so it works just out of the box.

No need to compile ANYTHING. No headaces with those native addons, compilation or anything like that. Just add the module and use.

Installation

npm install --save https://github.com/Edgar-P-yan/node-systray-v2

# For Yarn, use the command below.
yarn add https://github.com/Edgar-P-yan/node-systray-v2

Preview

Source code of this preview is at ./examples/preview/.

Quick example

import SysTray from 'systray';

const systray = new SysTray({
  menu: {
    // you should using .png icon in macOS/Linux, but .ico format in windows
    icon: '<base64 png/ico string>',
    title: '标题',
    tooltip: 'Tips',
    items: [
      {
        title: 'aa',
        tooltip: 'bb',
        // checked is implement by plain text in linux
        checked: true,
        enabled: true,
      },
      {
        title: 'aa2',
        tooltip: 'bb',
        checked: false,
        enabled: true,
      },
      {
        title: 'Exit',
        tooltip: 'bb',
        checked: false,
        enabled: true,
      },
    ],
  },
  debug: false,
  copyDir: true, // copy go tray binary to outside directory, useful for packing tool like pkg.
});

systray.onClick((action) => {
  if (action.seq_id === 0) {
    systray.sendAction({
      type: 'update-item',
      item: {
        ...action.item,
        checked: !action.item.checked,
      },
      seq_id: action.seq_id,
    });
  } else if (action.seq_id === 1) {
    // open the url
    console.log('open the url', action);
  } else if (action.seq_id === 2) {
    systray.kill();
  }
});

Examples

Take a look at the examples.

API Documentation

Documentation generated from source files by Typedoc.

TODO

  • Add more examples and docs with screenshots
  • Submenus, dividers, fixes, most of which can be taken from awesome but now unmaintained fork felixhao28/node-systray
  • Write some tests (maybe even e2e)

License

Released under MIT License.

About

A cross-platform systray library for node.js with precompiled binaries.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published