Aun Rizvi
Aun Rizvi

Reputation: 519

nodejs systray: SysTray is not a constructor

I am trying to use npm module for nodejs called systray, when I try to run the example given on the npm page it throws

TypeError: SysTray is not a constructor

systray seems to be a popular module for a crossplatform system tray but it lacks in examples, below is the sample code that I am trying to run

var SysTray = require("systray")

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

Upvotes: 1

Views: 1014

Answers (2)

Michael Yurin
Michael Yurin

Reputation: 1060

Require it in this way:

const SysTray = require('systray').default;

But probably it is better to use import constructions and babel (https://babeljs.io/docs/en/babel-preset-typescript)

Upvotes: 3

Abinash Gupta
Abinash Gupta

Reputation: 321

Seems that the npm package you are trying to use is meant to be used with typescript.

Upvotes: 0

Related Questions