Add a tray icon menu to open the main window

This commit is contained in:
Yuya Ochiai
2016-05-23 23:37:24 +09:00
parent 32b743f98c
commit 91e2346cc3
2 changed files with 22 additions and 11 deletions

View File

@@ -164,8 +164,6 @@ app.on('ready', function() {
// set up tray icon // set up tray icon
trayIcon = new Tray(trayImages.normal); trayIcon = new Tray(trayImages.normal);
trayIcon.setToolTip(app.getName()); trayIcon.setToolTip(app.getName());
var tray_menu = require('./main/menus/tray').createDefault();
trayIcon.setContextMenu(tray_menu);
trayIcon.on('click', function() { trayIcon.on('click', function() {
mainWindow.focus(); mainWindow.focus();
}); });
@@ -227,6 +225,12 @@ app.on('ready', function() {
// and load the index.html of the app. // and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/browser/index.html'); 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. // Open the DevTools.
// mainWindow.openDevTools(); // mainWindow.openDevTools();

View File

@@ -1,18 +1,25 @@
'use strict'; 'use strict';
const electron = require('electron'); const {
const Menu = electron.Menu; app,
const MenuItem = electron.MenuItem; Menu,
MenuItem
} = require('electron');
var createDefault = function() { function createDefault(mainWindow) {
var menu = new Menu(); return Menu.buildFromTemplate([{
menu.append(new MenuItem({ label: 'Open Mattermost',
click: () => {
mainWindow.show();
}
}, {
type: 'separator'
}, {
label: 'Quit', label: 'Quit',
click: function(item) { click: function(item) {
require('app').quit(); app.quit();
} }
})); }]);
return menu;
} }
module.exports = { module.exports = {