【问题标题】:Electron: Add app icon to bottom right of the taskbarElectron:将应用程序图标添加到任务栏的右下角
【发布时间】:2020-10-03 19:41:51
【问题描述】:

我刚刚开发了一个电子应用程序,一个用户建议在任务栏的右下角添加一个图标,以便轻松打开并访问它。我想在下图中的区域添加一个图标:

我查看了电子docs,但找不到任何东西。

这可能吗?如果可以,怎么做?

【问题讨论】:

标签: javascript node.js windows electron taskbar


【解决方案1】:

该区域称为“系统托盘”,您可以使用 Electron 的托盘 API 为您的电子应用添加系统托盘图标。您可以找到documentation for the Tray class here,也可以查看this tutorial

【讨论】:

    【解决方案2】:

    // 电子任务栏

    const {app, Tray, Menu} = require('electron')
    
    app.on('ready', () => {
      tray = new Tray(path.join(__dirname, 'icon/favicon.ico'))
    
      if (process.platform === 'win32' ) {
        tray.on('click', tray.popUpContextMenu)
      }
    
      const menu = Menu.buildFromTemplate ([
        {
          label: 'Exit',
          click() { app.quit()}
        },
    
        {  label: 'Help',
        click() { null; }}
      ])
    
      tray.setToolTip('AppName')
      tray.setContextMenu(menu)
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-22
      • 1970-01-01
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 2020-02-03
      • 1970-01-01
      相关资源
      最近更新 更多