egekhter
egekhter

Reputation: 2225

Prevent multiple tray icons in Node Webkit?

Is there a way to check if a tray icon already exists for given app in Node Webkit (on OSX)?

My problem looks like this: multiple tray icons created for node webkit app

Code used to create tray icon:

// Create a tray icon
if (os_platform === 'darwin'){ //better icon for windows, correct size for mac
    var tray = new gui.Tray({ title: '', icon: 'icon-mac.png', tooltip:    'R' });
}
else {
    var tray = new gui.Tray({ title: '', icon: 'icon-win.png', tooltip: 'R' });
}

Upvotes: 0

Views: 437

Answers (2)

SchizoDuckie
SchizoDuckie

Reputation: 9401

I have just fixed this by using this:

win.on('restore', function() {
     console.log('removing tray.');
     tray.remove();
});

After analyzing the behavior I noticed that you can unminimize the app by clicking it on the taskbar. This listens for that as well.

Upvotes: 0

egekhter
egekhter

Reputation: 2225

This does the trick.

window.onbeforeunload = function(){
   tray.remove();
};

Upvotes: 2

Related Questions