当我尝试运行npm页面上给出的示例时,我试图将npm模块用于名为systray的nodejs
TypeError:SysTray不是构造函数
systray似乎是跨平台系统托盘的流行模块,但缺少示例,以下是我尝试运行的示例代码
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()
}
})
答案 0 :(得分:0)
您尝试使用的npm软件包似乎应该与打字稿一起使用。
答案 1 :(得分:0)
以这种方式要求它:
const SysTray = require('systray').default;
但使用 import 构造和babel(https://babeljs.io/docs/en/babel-preset-typescript)
可能更好