繁体   English   中英

node.js 应用程序中的系统托盘图标

[英]System tray icon in node.js application

这是我在我的 node.js 应用程序中需要的:

  • 系统托盘图标
  • 在应用程序工作期间更改此图标
  • 点击图标后的菜单
  • 创建带有登录/密码字段和确认按钮的窗口

这是我发现的:

你有什么建议? 我需要可靠易于安装且尽可能跨系统的东西。

//编辑

自 11 月 6 日以来,Appjs 具有基本的托盘图标支持。

对于来到这里的任何其他人,请查看https://github.com/rogerwang/node-webkit - 一个很棒的包,允许您使用您喜欢的工具(如 JavaScript)创建桌面应用程序,支持本机 shell 访问、托盘图标还有更多。

更新:该应用程序已移至NWjs.io ,但它是同样出色的概念。

看看 Node-QT ( https://github.com/arturadib/node-qt ) 也许会有帮助。

我在 Linux 上使用过系统托盘 它承诺也可以在 macOS 和 Windows 上运行。 但我没有测试它。

来自官方文档的示例:

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()
    }
})

它不提供

创建带有登录/密码字段和确认按钮的窗口

但在我看来,这项任务是一个单独的任务。 所以这个答案对其他只想要系统托盘图标的人有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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