Files
mattermostest/src/main/menus/tray.js
2017-03-06 23:43:27 +09:00

61 lines
1.3 KiB
JavaScript

'use strict';
const {
app,
Menu
} = require('electron');
function createTemplate(mainWindow, config, isDev) {
const settingsURL = isDev ? 'http://localhost:8080/browser/settings.html' : `file://${app.getAppPath()}/browser/settings.html`;
var template = [
...config.teams.slice(0, 9).map((team, i) => {
return {
label: team.name,
click: () => {
showOrRestore(mainWindow);
mainWindow.webContents.send('switch-tab', i);
if (process.platform === 'darwin') {
app.dock.show();
mainWindow.focus();
}
}
};
}), {
type: 'separator'
}, {
label: process.platform === 'darwin' ? 'Preferences...' : 'Settings',
click: () => {
mainWindow.loadURL(settingsURL);
showOrRestore(mainWindow);
if (process.platform === 'darwin') {
app.dock.show();
mainWindow.focus();
}
}
}, {
type: 'separator'
}, {
role: 'quit'
}
];
return template;
}
function createMenu(mainWindow, config, isDev) {
return Menu.buildFromTemplate(createTemplate(mainWindow, config, isDev));
}
function showOrRestore(window) {
if (window.isMinimized()) {
window.restore();
} else {
window.show();
}
}
module.exports = {
createMenu
};