Skip to content

Commit

Permalink
Fix try context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok committed Jan 11, 2017
1 parent 24af81b commit 0b9ac2f
Showing 1 changed file with 38 additions and 23 deletions.
61 changes: 38 additions & 23 deletions src/scripts/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import { remote } from 'electron';
import path from 'path';

var Tray = remote.Tray;
var Menu = remote.Menu;
const { Tray, Menu } = remote;

let mainWindow = remote.getCurrentWindow();
const mainWindow = remote.getCurrentWindow();

var icons = {
const icons = {
win32: {
dir: 'windows'
},
Expand All @@ -23,39 +22,55 @@ var icons = {
}
};

let _iconTray = path.join(__dirname, 'images', icons[process.platform].dir, icons[process.platform].icon || 'icon-tray.png');
let _iconTrayAlert = path.join(__dirname, 'images', icons[process.platform].dir, icons[process.platform].iconAlert || 'icon-tray-alert.png');
const _iconTray = path.join(__dirname, 'images', icons[process.platform].dir, icons[process.platform].icon || 'icon-tray.png');
const _iconTrayAlert = path.join(__dirname, 'images', icons[process.platform].dir, icons[process.platform].iconAlert || 'icon-tray-alert.png');

function createAppTray () {
let _tray = new Tray(_iconTray);
var contextMenu = Menu.buildFromTemplate([{
const _tray = new Tray(_iconTray);
const contextMenuShow = Menu.buildFromTemplate([{
label: 'Show',
click () {
mainWindow.show();
}
}, {
label: 'Quit',
click: function () {
click () {
remote.app.quit();
}
}]);

const contextMenuHide = Menu.buildFromTemplate([{
label: 'Hide',
click () {
mainWindow.hide();
}
}, {
label: 'Quit',
click () {
remote.app.quit();
}
}]);

_tray.setToolTip(remote.app.getName());
if (!mainWindow.isMinimized() && !mainWindow.isVisible()) {
_tray.setContextMenu(contextMenuShow);
} else {
_tray.setContextMenu(contextMenuHide);
}

_tray.on('right-click', function (e, b) {
_tray.popUpContextMenu(contextMenu, b);
mainWindow.on('show', () => {
_tray.setContextMenu(contextMenuHide);
});

_tray.on('click', function (e, b) {
if (e.ctrlKey === true) {
_tray.popUpContextMenu(contextMenu, b);
return;
}
mainWindow.on('hide', () => {
_tray.setContextMenu(contextMenuShow);
});

if (mainWindow.isVisible()) {
mainWindow.hide();
} else {
mainWindow.show();
}
_tray.setToolTip(remote.app.getName());

_tray.on('right-click', function (e, b) {
_tray.popUpContextMenu(undefined, b);
});

mainWindow = mainWindow;
mainWindow.tray = _tray;
}

Expand Down

0 comments on commit 0b9ac2f

Please sign in to comment.