diff --git a/src/main.js b/src/main.js index cdeeb037..7296a9cf 100644 --- a/src/main.js +++ b/src/main.js @@ -164,8 +164,6 @@ app.on('ready', function() { // set up tray icon trayIcon = new Tray(trayImages.normal); trayIcon.setToolTip(app.getName()); - var tray_menu = require('./main/menus/tray').createDefault(); - trayIcon.setContextMenu(tray_menu); trayIcon.on('click', function() { mainWindow.focus(); }); @@ -227,6 +225,12 @@ app.on('ready', function() { // and load the index.html of the app. mainWindow.loadURL('file://' + __dirname + '/browser/index.html'); + // set up context menu for tray icon + if (shouldShowTrayIcon()) { + const tray_menu = require('./main/menus/tray').createDefault(mainWindow); + trayIcon.setContextMenu(tray_menu); + } + // Open the DevTools. // mainWindow.openDevTools(); diff --git a/src/main/menus/tray.js b/src/main/menus/tray.js index 58e70e08..68eeaa4d 100644 --- a/src/main/menus/tray.js +++ b/src/main/menus/tray.js @@ -1,18 +1,25 @@ 'use strict'; -const electron = require('electron'); -const Menu = electron.Menu; -const MenuItem = electron.MenuItem; +const { + app, + Menu, + MenuItem +} = require('electron'); -var createDefault = function() { - var menu = new Menu(); - menu.append(new MenuItem({ +function createDefault(mainWindow) { + return Menu.buildFromTemplate([{ + label: 'Open Mattermost', + click: () => { + mainWindow.show(); + } + }, { + type: 'separator' + }, { label: 'Quit', click: function(item) { - require('app').quit(); + app.quit(); } - })); - return menu; + }]); } module.exports = {