Skip to content

Commit

Permalink
Refactoring code for menu for easier changes (#791)
Browse files Browse the repository at this point in the history
* added menu changes

* removed unused variable

* removed unused variable

* fixed typos

* eslint pass

* removed app to use local

* changed platform

* added flow pragma

* added types

* added flow to main.dev

* added lint fix
  • Loading branch information
axsaucedo authored and amilajack committed Mar 11, 2017
1 parent feaa6e9 commit e607318
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 216 deletions.
224 changes: 8 additions & 216 deletions app/main.development.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { app, BrowserWindow, Menu, shell } from 'electron';
// @flow
import { app, BrowserWindow } from 'electron';
import MenuBuilder from './menu';

let menu;
let template;
let mainWindow = null;

if (process.env.NODE_ENV === 'production') {
Expand Down Expand Up @@ -53,6 +53,9 @@ app.on('ready', async () => {
mainWindow.loadURL(`file://${__dirname}/app.html`);

mainWindow.webContents.on('did-finish-load', () => {
if (!mainWindow) {
throw new Error('"mainWindow" is not defined');
}
mainWindow.show();
mainWindow.focus();
});
Expand All @@ -61,217 +64,6 @@ app.on('ready', async () => {
mainWindow = null;
});

if (process.env.NODE_ENV === 'development') {
mainWindow.openDevTools();
mainWindow.webContents.on('context-menu', (e, props) => {
const { x, y } = props;

Menu.buildFromTemplate([{
label: 'Inspect element',
click() {
mainWindow.inspectElement(x, y);
}
}]).popup(mainWindow);
});
}

if (process.platform === 'darwin') {
template = [{
label: 'Electron',
submenu: [{
label: 'About ElectronReact',
selector: 'orderFrontStandardAboutPanel:'
}, {
type: 'separator'
}, {
label: 'Services',
submenu: []
}, {
type: 'separator'
}, {
label: 'Hide ElectronReact',
accelerator: 'Command+H',
selector: 'hide:'
}, {
label: 'Hide Others',
accelerator: 'Command+Shift+H',
selector: 'hideOtherApplications:'
}, {
label: 'Show All',
selector: 'unhideAllApplications:'
}, {
type: 'separator'
}, {
label: 'Quit',
accelerator: 'Command+Q',
click() {
app.quit();
}
}]
}, {
label: 'Edit',
submenu: [{
label: 'Undo',
accelerator: 'Command+Z',
selector: 'undo:'
}, {
label: 'Redo',
accelerator: 'Shift+Command+Z',
selector: 'redo:'
}, {
type: 'separator'
}, {
label: 'Cut',
accelerator: 'Command+X',
selector: 'cut:'
}, {
label: 'Copy',
accelerator: 'Command+C',
selector: 'copy:'
}, {
label: 'Paste',
accelerator: 'Command+V',
selector: 'paste:'
}, {
label: 'Select All',
accelerator: 'Command+A',
selector: 'selectAll:'
}]
}, {
label: 'View',
submenu: (process.env.NODE_ENV === 'development') ? [{
label: 'Reload',
accelerator: 'Command+R',
click() {
mainWindow.webContents.reload();
}
}, {
label: 'Toggle Full Screen',
accelerator: 'Ctrl+Command+F',
click() {
mainWindow.setFullScreen(!mainWindow.isFullScreen());
}
}, {
label: 'Toggle Developer Tools',
accelerator: 'Alt+Command+I',
click() {
mainWindow.toggleDevTools();
}
}] : [{
label: 'Toggle Full Screen',
accelerator: 'Ctrl+Command+F',
click() {
mainWindow.setFullScreen(!mainWindow.isFullScreen());
}
}]
}, {
label: 'Window',
submenu: [{
label: 'Minimize',
accelerator: 'Command+M',
selector: 'performMiniaturize:'
}, {
label: 'Close',
accelerator: 'Command+W',
selector: 'performClose:'
}, {
type: 'separator'
}, {
label: 'Bring All to Front',
selector: 'arrangeInFront:'
}]
}, {
label: 'Help',
submenu: [{
label: 'Learn More',
click() {
shell.openExternal('http://electron.atom.io');
}
}, {
label: 'Documentation',
click() {
shell.openExternal('https://github.com/atom/electron/tree/master/docs#readme');
}
}, {
label: 'Community Discussions',
click() {
shell.openExternal('https://discuss.atom.io/c/electron');
}
}, {
label: 'Search Issues',
click() {
shell.openExternal('https://github.com/atom/electron/issues');
}
}]
}];

menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
} else {
template = [{
label: '&File',
submenu: [{
label: '&Open',
accelerator: 'Ctrl+O'
}, {
label: '&Close',
accelerator: 'Ctrl+W',
click() {
mainWindow.close();
}
}]
}, {
label: '&View',
submenu: (process.env.NODE_ENV === 'development') ? [{
label: '&Reload',
accelerator: 'Ctrl+R',
click() {
mainWindow.webContents.reload();
}
}, {
label: 'Toggle &Full Screen',
accelerator: 'F11',
click() {
mainWindow.setFullScreen(!mainWindow.isFullScreen());
}
}, {
label: 'Toggle &Developer Tools',
accelerator: 'Alt+Ctrl+I',
click() {
mainWindow.toggleDevTools();
}
}] : [{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click() {
mainWindow.setFullScreen(!mainWindow.isFullScreen());
}
}]
}, {
label: 'Help',
submenu: [{
label: 'Learn More',
click() {
shell.openExternal('http://electron.atom.io');
}
}, {
label: 'Documentation',
click() {
shell.openExternal('https://github.com/atom/electron/tree/master/docs#readme');
}
}, {
label: 'Community Discussions',
click() {
shell.openExternal('https://discuss.atom.io/c/electron');
}
}, {
label: 'Search Issues',
click() {
shell.openExternal('https://github.com/atom/electron/issues');
}
}]
}];
menu = Menu.buildFromTemplate(template);
mainWindow.setMenu(menu);
}
const menuBuilder = new MenuBuilder(mainWindow);
menuBuilder.buildMenu();
});
Loading

0 comments on commit e607318

Please sign in to comment.