Merge pull request #184 from Razzeee/improve-tray-menu

Improve tray menu
This commit is contained in:
Yuya Ochiai 2016-07-06 22:15:18 +09:00 committed by GitHub
commit cbecbfbc16
4 changed files with 50 additions and 51 deletions

View file

@ -31,6 +31,7 @@
- Ctrl+{1-9} (Window -> *Team name*): Open the *n*-th tab.
- Ctrl+Tab or Alt+Command+Right (Window -> Select Next Team): Open the right tab.
- Ctrl+Shift+Tab or Alt+Command+Left (Window -> Select Previous Team): Open the left tab.
- Right click on the tray item, to see an overview of all your teams. You can also select one and jump right into it.
- Added **Add** button next to the "Teams" label on the Setting page.
- Added **Edit** button on the team list on the Setting page.
- Added **Help** menu to indicate the application version.

View file

@ -364,23 +364,22 @@ app.on('ready', function() {
ipcMain.on('update-menu', (event, config) => {
var app_menu = appMenu.createMenu(mainWindow, config);
Menu.setApplicationMenu(app_menu);
// set up context menu for tray icon
if (shouldShowTrayIcon()) {
const tray_menu = require('./main/menus/tray').createMenu(mainWindow, config);
trayIcon.setContextMenu(tray_menu);
if (process.platform === 'darwin') {
// store the information, if the tray was initialized, for checking in the settings, if the application
// was restarted after setting "Show icon on menu bar"
if (trayIcon)
mainWindow.trayWasVisible = true;
else
mainWindow.trayWasVisible = false;
}
}
});
ipcMain.emit('update-menu', true, config);
// set up context menu for tray icon
if (shouldShowTrayIcon()) {
const tray_menu = require('./main/menus/tray').createDefault(mainWindow);
trayIcon.setContextMenu(tray_menu);
if (process.platform === 'darwin') {
// store the information, if the tray was initialized, for checking in the settings, if the application
// was restarted after setting "Show icon on menu bar"
if (trayIcon)
mainWindow.trayWasVisible = true;
else
mainWindow.trayWasVisible = false;
}
}
// Open the DevTools.
// mainWindow.openDevTools();

View file

@ -21,17 +21,13 @@ var createTemplate = function(mainWindow, config) {
message: `${app_name} Desktop ${electron.app.getVersion()}`
});
}
}, {
type: 'separator'
}, {
}, separatorItem, {
label: 'Preferences...',
accelerator: 'CmdOrCtrl+,',
click: function(item, focusedWindow) {
mainWindow.loadURL('file://' + __dirname + '/browser/settings.html');
}
}, {
type: 'separator'
}, {
}, separatorItem, {
label: 'Hide ' + app_name,
accelerator: 'Command+H',
selector: 'hide:'
@ -42,9 +38,7 @@ var createTemplate = function(mainWindow, config) {
}, {
label: 'Show All',
selector: 'unhideAllApplications:'
}, {
type: 'separator'
}, {
}, separatorItem, {
label: 'Quit ' + app_name,
accelerator: 'CmdOrCtrl+Q',
click: function(item, focusedWindow) {
@ -56,9 +50,7 @@ var createTemplate = function(mainWindow, config) {
click: function(item, focusedWindow) {
mainWindow.loadURL('file://' + __dirname + '/browser/settings.html');
}
}, {
type: 'separator'
}, {
}, separatorItem, {
label: 'Quit',
accelerator: 'CmdOrCtrl+Q',
click: function(item, focusedWindow) {
@ -82,9 +74,7 @@ var createTemplate = function(mainWindow, config) {
label: 'Redo',
accelerator: 'Shift+CmdOrCtrl+Z',
role: 'redo'
}, {
type: 'separator'
}, {
}, separatorItem, {
label: 'Cut',
accelerator: 'CmdOrCtrl+X',
role: 'cut'
@ -192,9 +182,7 @@ var createTemplate = function(mainWindow, config) {
focusedWindow.close();
}
}
}, {
type: 'separator'
}, ...config.teams.slice(0, 9).map((team, i) => {
}, separatorItem, ...config.teams.slice(0, 9).map((team, i) => {
return {
label: team.name,
accelerator: `CmdOrCtrl+${i + 1}`,

View file

@ -6,28 +6,39 @@ const {
MenuItem
} = require('electron');
function createDefault(mainWindow) {
return Menu.buildFromTemplate([{
label: `Open ${app.getName()}`,
click: () => {
mainWindow.show();
mainWindow.isHidden = false;
function createTemplate(mainWindow, config) {
var template = [
...config.teams.slice(0, 9).map((team, i) => {
return {
label: team.name,
accelerator: `CmdOrCtrl+${i + 1}`,
click: (item, focusedWindow) => {
mainWindow.show(); // for OS X
mainWindow.webContents.send('switch-tab', i);
mainWindow.isHidden = false;
if (process.platform === 'darwin') {
app.dock.show();
mainWindow.focus();
if (process.platform === 'darwin') {
app.dock.show();
mainWindow.focus();
}
}
};
}), {
type: 'separator'
}, {
label: 'Quit',
click: function(item) {
app.quit();
}
}
}, {
type: 'separator'
}, {
label: 'Quit',
click: function(item) {
app.quit();
}
}]);
];
return template;
}
module.exports = {
createDefault: createDefault
var createMenu = function(mainWindow, config) {
return Menu.buildFromTemplate(createTemplate(mainWindow, config));
};
module.exports = {
createMenu: createMenu
};