2017-08-20 03:03:13 -08:00
|
|
|
// Packages
|
2017-11-02 18:51:18 -08:00
|
|
|
const {app, dialog, Menu} = require('electron');
|
2017-06-19 13:02:53 -08:00
|
|
|
|
2017-08-20 03:03:13 -08:00
|
|
|
// Utilities
|
2017-11-02 18:51:18 -08:00
|
|
|
const {getConfig} = require('../config');
|
2017-06-19 13:02:53 -08:00
|
|
|
const {icon} = require('../config/paths');
|
2017-05-25 22:59:02 -08:00
|
|
|
const viewMenu = require('./menus/view');
|
|
|
|
|
const shellMenu = require('./menus/shell');
|
|
|
|
|
const editMenu = require('./menus/edit');
|
|
|
|
|
const pluginsMenu = require('./menus/plugins');
|
|
|
|
|
const windowMenu = require('./menus/window');
|
|
|
|
|
const helpMenu = require('./menus/help');
|
|
|
|
|
const darwinMenu = require('./menus/darwin');
|
2017-11-02 18:51:18 -08:00
|
|
|
const {getDecoratedKeymaps} = require('../plugins');
|
|
|
|
|
const {execCommand} = require('../commands');
|
2017-05-25 22:59:02 -08:00
|
|
|
|
2017-06-19 13:02:53 -08:00
|
|
|
const appName = app.getName();
|
|
|
|
|
const appVersion = app.getVersion();
|
|
|
|
|
|
2017-11-02 18:51:18 -08:00
|
|
|
let menu_ = [];
|
|
|
|
|
|
|
|
|
|
exports.createMenu = (createWindow, getLoadedPluginVersions) => {
|
2017-08-20 03:03:13 -08:00
|
|
|
const config = getConfig();
|
2017-11-02 18:51:18 -08:00
|
|
|
// We take only first shortcut in array for each command
|
|
|
|
|
const allCommandKeys = getDecoratedKeymaps();
|
|
|
|
|
const commandKeys = Object.keys(allCommandKeys).reduce((result, command) => {
|
|
|
|
|
result[command] = allCommandKeys[command][0];
|
|
|
|
|
return result;
|
|
|
|
|
}, {});
|
2017-08-20 03:03:13 -08:00
|
|
|
|
2017-08-30 09:14:28 -08:00
|
|
|
let updateChannel = 'stable';
|
|
|
|
|
|
|
|
|
|
if (config && config.updateChannel && config.updateChannel === 'canary') {
|
|
|
|
|
updateChannel = 'canary';
|
|
|
|
|
}
|
2017-08-20 03:03:13 -08:00
|
|
|
|
2017-06-19 13:02:53 -08:00
|
|
|
const showAbout = () => {
|
|
|
|
|
const loadedPlugins = getLoadedPluginVersions();
|
2017-09-10 05:35:10 -08:00
|
|
|
const pluginList =
|
|
|
|
|
loadedPlugins.length === 0 ? 'none' : loadedPlugins.map(plugin => `\n ${plugin.name} (${plugin.version})`);
|
2017-08-20 03:03:13 -08:00
|
|
|
|
2017-06-19 13:02:53 -08:00
|
|
|
dialog.showMessageBox({
|
|
|
|
|
title: `About ${appName}`,
|
2017-08-20 03:03:13 -08:00
|
|
|
message: `${appName} ${appVersion} (${updateChannel})`,
|
2018-01-17 07:00:13 -09:00
|
|
|
detail: `Plugins: ${pluginList}\n\nCreated by Guillermo Rauch\nCopyright © 2018 ZEIT, Inc.`,
|
2017-06-19 13:02:53 -08:00
|
|
|
buttons: [],
|
|
|
|
|
icon
|
|
|
|
|
});
|
|
|
|
|
};
|
2017-06-02 16:03:47 -08:00
|
|
|
const menu = [
|
2017-11-03 13:06:48 -08:00
|
|
|
...(process.platform === 'darwin' ? [darwinMenu(commandKeys, execCommand, showAbout)] : []),
|
2017-11-02 18:51:18 -08:00
|
|
|
shellMenu(commandKeys, execCommand),
|
|
|
|
|
editMenu(commandKeys, execCommand),
|
|
|
|
|
viewMenu(commandKeys, execCommand),
|
|
|
|
|
pluginsMenu(commandKeys, execCommand),
|
|
|
|
|
windowMenu(commandKeys, execCommand),
|
|
|
|
|
helpMenu(commandKeys, showAbout)
|
2017-06-02 16:03:47 -08:00
|
|
|
];
|
2017-05-25 22:59:02 -08:00
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
};
|
2017-11-02 18:51:18 -08:00
|
|
|
|
|
|
|
|
exports.buildMenu = template => {
|
|
|
|
|
menu_ = Menu.buildFromTemplate(template);
|
|
|
|
|
return menu_;
|
|
|
|
|
};
|