Skip to content

Alternative to click even for tray icon with a context menu on OSX? #1975

@trouttdev

Description

@trouttdev

I'm trying to capture the click even on a tray icon click with a context menu on OSX, but according to the docs this is disabled in OSX for some reason:

Platform limitations:

On OS X clicked event will be ignored if the tray icon has context menu.

I'm wondering if there is another way to know when a tray icon with a context menu is interacted with? Clicked/opened, something along those lines.

Relavent code:

var app = require('app');
var path = require('path')
var Menu = require('menu');
var MenuItem = require('menu-item');
var Tray = require('tray');

var appIcon = null;
var menu = null;
app.on('ready', function(){
  appIcon = new Tray(path.join(__dirname, 'images/icon.png'));

  appIcon.on('clicked', function(event, bounds) {
      console.log('clicked');
  });

  menu = new Menu();

  menu.append(new MenuItem({ label: 'Quit', id: 'quit', click: function() { app.quit(); } }));
  appIcon.setContextMenu(menu);

});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions