首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nodejs系统: SysTray不是构造函数

nodejs系统: SysTray不是构造函数
EN

Stack Overflow用户
提问于 2018-07-25 10:51:25
回答 2查看 809关注 0票数 1

当我尝试在npm页面上运行它抛出的示例时,我正在尝试使用nodejs的npm模块-即systray。

TypeError: SysTray不是构造函数

systray似乎是跨平台系统托盘的一个流行模块,但缺少示例,下面是我试图运行的示例代码。

代码语言:javascript
复制
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()
    }
})
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-04-17 21:31:00

以这种方式要求:

代码语言:javascript
复制
const SysTray = require('systray').default;

但是也许使用导入结构和babel (https://babeljs.io/docs/en/babel-preset-typescript)更好。

票数 3
EN

Stack Overflow用户

发布于 2018-07-25 12:11:07

看来,您试图使用的npm包应该与类型记录一起使用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51517121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档