Abhishek Yadav
ப்ரோக்ராமர்
Co-organizer: Chennai.js
Electron
const { app, BrowserWindow } = require('electron');
app.on('ready', () => {
var mainWindow = new BrowserWindow()
mainWindow.loadURL('http://chennai-js.org')
}
Electron
my-app
|
|-- index.js
|
|-- package.json
|
|-- index.html
{
"name" : "my-app",
"version" : "0.1.0",
"main" : "index.js"
}
electron .
Electron
Electron
Electron
Electron
const { app, BrowserWindow } = require('electron');
app.on('ready', () => {
var mainWindow = new BrowserWindow()
mainWindow.loadURL('http://chennai-js.org')
}
1. node.js require
2. app has events
3. window opens here
4. window can open a url
Electron
Credit: http://jlord.us/essential-electron/#how-even-
Electron
Electron
const { app, BrowserWindow } = require('electron');
let mainWindow;
app.on('ready', () => {
mainWindow = new BrowserWindow()
mainWindow.loadURL('file://' + __dirname + '/index.html')
}
Electron
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<div id='the-size'></div>
<script>
const fs = require('fs');
var size = fs.statSync('./index.html').size;
var el = document.getElementById('the-size');
el.innerHTML = "The size is: " + size;
</script>
</body>
</html>
Electron
Electron
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<div id='the-size'></div>
<script>
const fs = require('fs');
var size = fs.statSync('./index.html').size;
var el = document.getElementById('the-size');
el.innerHTML = "The size is: " + size;
</script>
</body>
</html>
node.js in browser
DOM manipulation
Electron
node.js in browser
Cmd Shift i
Electron
Electron
Renderer
HTML CSS JS
Renderer
HTML CSS JS
Renderer
HTML CSS JS
Main
Native API
IPC
IPC
IPC
Electron
Electron
Electron
const { app, BrowserWindow } = require('electron');
let windows = [];
function createWindow(url, shift){
var rand = Math.floor(Math.random()*500);
const w = new BrowserWindow({x: rand, y: rand})
w.loadURL(url)
windows.push(w)
}
app.on('ready', () => {
createWindow('file://' + __dirname + '/index.html')
createWindow('http://www.chennai-js.org')
});
Electron
Electron
win.webContents.debugger.sendCommand('Network.enable')
Electron
Electron
Electron
Electron
<header class="toolbar toolbar-header">
<h1 class="title">Header with actions</h1>
<div class="toolbar-actions">
<div class="btn-group">
<button class="btn btn-default">
<span class="icon icon-home"></span>
</button>
<button class="btn btn-default">
<span class="icon icon-folder"></span>
</button>
<button class="btn btn-default active">
<span class="icon icon-cloud"></span>
</button>
<button class="btn btn-default">
<span class="icon icon-popup"></span>
</button>
<button class="btn btn-default">
<span class="icon icon-shuffle"></span>
</button>
</div>
<button class="btn btn-default btn-dropdown pull-right">
<span class="icon icon-megaphone"></span>
</button>
</div>
</header>
Electron
Electron
React PhotonKit | Photon components built with React. |
React Desktop | UI toolkit for macOS and Windows built with React. |
chrome-tabs | Chrome like tabs. |
electron-positioner | Position windows at common spots. |
electron-drag | Improved dragging |
Electron
Electron
The following extensions work -
Electron
debug-menu | Chrome like 'inspect element' |
electron-debug | keyboard shortcuts for devtools |
electron-is-dev | check if we are in dev mode |
electron-detach | Restart an Electron app as a detached process. |
electron-log | Logging |
Electron
Electron
electron-packager | Package and distribute |
electron-builder | Create installers |
electron-gh-release | Auto-update by releasing on GitHub |
electron-release | Publish a new release to GitHub |
electron-updater | Auto-updater leveraging npm to deploy updates |
nuts | Releases server with auto-updater |
electron-release-server | Self-hosted release server with front-end |
electron-installer-debian | Create a Debian package |
electron-installer-redhat | Create a Red Hat package |
electron-installer-windows | Create a Windows package |
Electron
Electron
it('opens a window', function () {
return this.app.client.waitUntilWindowLoaded()
.getWindowCount().should.eventually.equal(1)
.browserWindow.isMinimized().should.eventually.be.false
.browserWindow.isDevToolsOpened().should.eventually.be.false
.browserWindow.isVisible().should.eventually.be.true
.browserWindow.isFocused().should.eventually.be.true
.browserWindow.getBounds().should.eventually.have.property('width').and.be.above(0)
.browserWindow.getBounds().should.eventually.have.property('height').and.be.above(0)
})
spectron - example
Electron
electron-dl | manage downloads (without boilerplate) |
electron-localshortcut | shortcuts without menu |
auto-launch | Auto launch the app at startup |
NeDB | Embedded persistent or in memory database. |
menubar | Create menubar apps with ease |
Electron
var menubar = require('menubar')
var mb = menubar()
mb.on('ready', function ready () {
console.log('app is ready')
})
Electron
Electron