当我尝试在npm页面上运行它抛出的示例时,我正在尝试使用nodejs的npm模块-即systray。
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()
}
})发布于 2019-04-17 21:31:00
以这种方式要求:
const SysTray = require('systray').default;但是也许使用导入结构和babel (https://babeljs.io/docs/en/babel-preset-typescript)更好。
发布于 2018-07-25 12:11:07
看来,您试图使用的npm包应该与类型记录一起使用。
https://stackoverflow.com/questions/51517121
复制相似问题