2015-06-10 11 views
5

Tôi đang cố gắng để nắm bắt những nhấp chuột ngay cả trên một nhấp chuột vào biểu tượng trên khay với một menu ngữ cảnh trên OSX, nhưng theo các tài liệu này bị vô hiệu hóa trong OSX vì một lý do:Trình đơn ngữ cảnh nhấp/mở sự kiện với Atom Shell/Electron?

Platform limitations: 

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

Tôi đã tự hỏi nếu có cách khác để biết khi nào biểu tượng khay có menu ngữ cảnh được tương tác với?

đang relavent:

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); 

}); 

Trả lời

1

Bây giờ nó hoạt động trên OS X (10.11.4).

Vui lòng kiểm tra. main.js:

// Load in dependencies 
var app = require('app'); 
var Tray = require('tray'); 

// When the Electron has loaded 
app.on('ready', function onready() { 
    // Log to the console to verify logging works 
    console.log('Hello World!'); 

    // Create a tray 
    var tray = new Tray(__dirname + '/icon.png'); 

    // When the tray icon is clicked, log to our console 
    tray.on('click', function handleClicked() { 
    console.log('Tray clicked'); 
    }); 
}); 

Run:

electron main.js 
Các vấn đề liên quan