简体   繁体   中英

System tray icon in node.js application

This is what I need in my node.js application:

  • System tray icon
  • changing this icon during application work
  • menu after clicking on icon
  • creation of windows with fields for login / password and confirmation buttons

This is what I found:

Do you have any recommendations? I need something reliable , easy to install and as cross-system as possible.

//edit

Since 6th November Appjs has basic tray icon support.

For anyone else that lands up here, check out https://github.com/rogerwang/node-webkit - a great package that allows you to create desktop applications using your favourite tools like JavaScript, with support for native shell access, tray icons and a lot more.

Update: The app has moved to NWjs.io but it's the same brilliant concept.

Take a look at Node-QT ( https://github.com/arturadib/node-qt ) maybe that can help.

I've used systray on Linux. It is promised to work on macOS and Windows too. But I didn't tested it.

Example from official docs:

import SysTray from 'systray'

const systray = new SysTray({
    menu: {
        // you should using .png icon in macOS/Linux, but .ico format in windows
        icon: "<base64 image 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()
    }
})

It does not provide

creation of windows with fields for login / password and confirmation buttons

But this task is a separate one in my opinion. So this answer can be helpful for other people who just want systray icon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM