Skip to content

Instantly share code, notes, and snippets.

/mdpreview.js

Created May 24, 2015
Embed
What would you like to do?
Electron App demo
////////////////////////////// context.js //////////////////////////////
'use strict';
var remote = require('remote');
var Menu = remote.require('menu');
var MenuItem = remote.require('menu-item');
var menu = new Menu();
menu.append(new MenuItem({
label: 'ping',
click: function() {
console.log('ping');
}
}));
menu.append(new MenuItem({
type: 'separator'
}));
menu.append(new MenuItem({
label: 'pong',
type: 'checkbox', checked: true,
click: function() {
console.log('pong');
}
}));
window.addEventListener('contextmenu', function (e) {
e.preventDefault();
menu.popup(remote.getCurrentWindow());
}, false);
////////////////////////////// app.js //////////////////////////////
'use strict';
var app = require('app');
var BrowserWindow = require('browser-window');
var Menu = require('menu');
var mainWindow = null;
app.on('window-all-closed', function() {
if (process.platform != 'darwin')
app.quit();
});
app.on('ready', function() {
createApplicationMenu();
openWindow();
});
var openWindow = function(){
mainWindow = new BrowserWindow({width: 800, height: 600});
mainWindow.loadUrl('file://' + __dirname + '/index.html');
mainWindow.on('closed', function() {
mainWindow = null;
});
}
var createApplicationMenu = function() {
var menuTemplate = [
{
label: 'Mdpreview',
submenu: [
{
label: 'Quit',
accelerator: 'Ctrl+Q',
click: function () {app.quit();}
}
]
}, {
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Ctrl+R',
click: function() {
BrowserWindow.getFocusedWindow().reloadIgnoringCache();
}
},
{
label: 'Toggle DevTools',
accelerator: 'Alt+Ctrl+I',
click: function() {
BrowserWindow.getFocusedWindow().toggleDevTools();
}
}
]
}
];
var menu = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(menu)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment