Created by Yeonghun Chae
OS | Binary | Supported |
OS X | x64 | 10.9 |
Windows | x86, x64 (arm is not supported) | Windows 7 |
Linux | ia32 (i686) x64 (amd64) arm | Ubuntu 12.04 Fedora 21 Debian 8 |
# Clone the Quick Start repository
git clone https://github.com/electron/electron-quick-start
# Go into the repository
cd electron-quick-start
# Install the dependencies and run
npm install && npm start
electron-quick-startconst {app} = require('electron');
// Handling Events ...
app.on(EVENT, callback);
app.on('window-all-closed', () => {
app.quit();
});
// Methods ...
app.quit()
app.dock.hide()
view more ...// BrowserWindow(options);
const {BrowserWindow} = require('electron')
let win = new BrowserWindow({
width: 500,
height: 500
});
view more options ...let win = new BrowserWindow({width: 800,height: 600,frame: false})
// prevent drag
body(style='-webkit-app-region: no-drag')
// set drag region
nav(style='-webkit-app-region: drag;')
// prevent drag
button(style='-webkit-app-region: no-drag;')
http://electron.atom.io/docs/api/frameless-windowconst {ipcMain} = require('electron');
ipcMain.on('asynchronous-message', (event, arg) => {
event.sender.send('asynchronous-reply', 'pong');
});
ipcMain.on('synchronous-message', (event, arg) => {
event.returnValue = 'pong';
});
// In renderer process (web page).
const {ipcRenderer} = require('electron');
console.log(ipcRenderer.sendSync('synchronous-message', 'ping'));
ipcRenderer.on('asynchronous-reply', (event, arg) => {
console.log(arg); // prints "pong"
});
ipcRenderer.send('asynchronous-message', 'ping');
const {remote} = require('electron');
const {Menu, MenuItem} = remote;
// Context Menu
const menu = new Menu();
menu.append(new MenuItem({label: 'MenuItem1', click() { console.log('item 1 clicked'); }}));
menu.append(new MenuItem({label: 'MenuItem2', type: 'checkbox', checked: true}));
window.addEventListener('contextmenu', (e) => {
e.preventDefault();
menu.popup(remote.getCurrentWindow());
}, false);
// Application Menu
const template = [
// something ...
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
view more ...# for use in npm scripts
npm install electron-packager --save-dev
# for use from cli
npm install electron-packager -g
electron-packager [sourcedir] [appname] --platform=[platform] --arch=[arch] [optional flags...]
electron-packager . --all
https://github.com/electron-userland/electron-packagervar packager = require('electron-packager');
packager({
platform: 'win32',
name: 'electron-quick-start',
arch: 'x64',
dir: './',
out: './dist',
prune: true,
asar: true,
'version-string': {
ProductName: 'electron-quick-start'
}
}, ()=> {
done();
});
# OS X
brew install mono wine
npm install --save-dev electron-winstaller
npm install electron-installer-dmg --save-dev
npm install electron-installer-dmg -g
Windows: electron-winstallervar installer = require('electron-winstaller');
# Promise Object
var winstaller = installer.createWindowsInstaller({
appDirectory: 'dist/electron-quick-start-win32-x64',
outputDirectory: 'dist/',
exe: 'electron-quick-start.exe',
setupExe: 'Setup.exe',
loadingGif: 'loading.gif'
});
winstaller.then(()=> {
console.log('done');
});
var createDMG = require('electron-installer-dmg');
createDMG({
appPath: 'dist/electron-quick-start-darwin-x64/electron-quick-start.app',
name: 'electron-quick-start',
out: 'dist/'
}, ()=> {
console.log('done');
});