Created
May 24, 2015 12:52
-
-
Save anonymous/1235e141c3def4507a78 to your computer and use it in GitHub Desktop.
Electron App demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////// 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