SlideShare a Scribd company logo
1 of 39
Download to read offline
Get that Corner Office
with Angular 2 and Electron
Get acquainted with how to
build native, desktop
applications using Electron
and Angular 2
Agenda
Running Electron
Adding Angular 2
Notifications
IPC
Packaging Electron
The Demo Application
• An Instagram style application that allows us to select
an image, apply a filter and then save it to our computer
• Feel free to use the existing code as a reference point
• Please explore! Don't be afraid to try new things!
http://bit.ly/ng-electrogram
Hello Electron
The Elevator Pitch
• Use HTML, CSS, and JavaScript with Chromium and
Node.js to build your app.
• Electron is open source; maintained by GitHub and an
active community.
• Electron apps build and run on Mac, Windows, and
Linux.
The Elevator Pitch Pt. 2
• Automatic updates
• Crash reporting
• Windows installers
• Debugging & profiling
• Native menus & notifications
http://electron.atom.io/docs/latest/tutorial/quick-start/
➜ npm install electron-prebuilt --save-dev
Install Electron
"scripts": {

"start": "electron main.js"

},
package.json
'use strict';



const electron = require('electron');

// Module to control application life.

const app = electron.app;

// Module to create native browser window.

const BrowserWindow = electron.BrowserWindow;



// Keep a global reference of the window object, if you don't, the window will

// be closed automatically when the JavaScript object is garbage collected.

let mainWindow;



let createWindow = () => {

// Create the browser window.

mainWindow = new BrowserWindow({width: 800, height: 600});



// and load the index.html of the app.

mainWindow.loadURL('file://' + __dirname + '/index.html');



// Open the DevTools.

// mainWindow.webContents.openDevTools();



// Emitted when the window is closed.

mainWindow.on('closed', () => {

// Dereference the window object, usually you would store windows

// in an array if your app supports multi windows, this is the time

// when you should delete the corresponding element.

mainWindow = null;

});

}



// This method will be called when Electron has finished

// initialization and is ready to create browser windows.

app.on('ready', createWindow);



// Quit when all windows are closed.

app.on('window-all-closed', () => {

// On OS X it is common for applications and their menu bar

// to stay active until the user quits explicitly with Cmd + Q

if (process.platform !== 'darwin') {

app.quit();

}

});



app.on('activate', () => {

// On OS X it's common to re-create a window in the app when the

// dock icon is clicked and there are no other windows open.

if (mainWindow === null) createWindow();

});

main.js
01-hello-electron-start
Challenges
• Install electron-prebuilt
• Create a main.js file
• Run electron
• In the package.json file, create a start task to run
electron
Adding Angular 2
Adding Angular 2
• Your Angular app generally goes into a sub-folder like
src or app
• If you are using a build system, you may have to tweak
file references to get everything working
• We need target attribute to the webpack config that is
set to electron-renderer. This gave us the ability to
import node and electron modules without breaking.
• Finally, the Angular app is in TypeScript, so we need to
install the electron typings to use electron packages in
our code.
02-adding-angular
Notifications
Notifications
• All three operating systems provide means for
applications to send notifications to the user.
• Electron conveniently allows developers to send
notifications with the HTML5 Notification API, using the
currently running operating system’s native notification
APIs to display it.
let myNotification = new Notification('Title', {

body: 'Lorem Ipsum Dolor Sit Amet'

});
Notification
03-notifications-start
Challenges
• In the saveFileCallback method in the app.ts file, create
an error notification and a success notification
IPC
IPC
• Inter-process communication (IPC) is handled by two
different modules
• ipcMain in the main process
• ipcRenderer in the renderer process
• You can also use webContents to send messages to
your renderer process
const BrowserWindow = electron.BrowserWindow;
mainWindow = new BrowserWindow({width: 800, height: 600});
fileMenu.submenu

.find(item => item.label === 'Open')

.click = () => mainWindow.webContents.send('open-file')
webContents.send
import { remote, ipcRenderer } from 'electron';
ipcRenderer.on('open-file', this.open.bind(this));

ipcRenderer.on('save-file', this.save.bind(this));
ipcRenderer.on
04-ipc-start
Challenges
• In the main.js file, complete the save and open click
handlers in the setMenu method
• Use app.ts file, add save and open handlers to the App
constructor
Packaging Electron
Packaging Electron
• We used to have to worry about all of packaging for
each OS ourselves
• Fortunately, electron-packager abstracts most of the
tedium away and allows us to run a one script to build
for our OS
➜ npm i -g electron-packager
Install electron-packager
➜ electron-packager . <appName>
--platform=<platform>
--arch=<architecture>
--out=<outputDirectory>
--overwrite
--icon=path/to/custom/icon
--asar
Run electron-packager
05-packaging-start
Challenges
• In the package.json file, create a distribute task that
uses electron-packager to package the app for your OS
Thanks!

More Related Content

What's hot

Debugging IE Performance Issues with xperf, ETW and NavigationTiming
Debugging IE Performance Issues with xperf, ETW and NavigationTimingDebugging IE Performance Issues with xperf, ETW and NavigationTiming
Debugging IE Performance Issues with xperf, ETW and NavigationTiming
Nicholas Jansma
 

What's hot (20)

JavaScript and Desktop Apps - Introduction to Electron
JavaScript and Desktop Apps - Introduction to ElectronJavaScript and Desktop Apps - Introduction to Electron
JavaScript and Desktop Apps - Introduction to Electron
 
Building desktop applications with web technologies - ELECTRON the easy way
Building desktop applications with web technologies - ELECTRON the easy wayBuilding desktop applications with web technologies - ELECTRON the easy way
Building desktop applications with web technologies - ELECTRON the easy way
 
Electron
ElectronElectron
Electron
 
Native Desktop App with Node.js Webkit (HTML, CSS & Javascript)
Native Desktop App with Node.js Webkit (HTML, CSS & Javascript)Native Desktop App with Node.js Webkit (HTML, CSS & Javascript)
Native Desktop App with Node.js Webkit (HTML, CSS & Javascript)
 
electron for emberists
electron for emberistselectron for emberists
electron for emberists
 
Debugging IE Performance Issues with xperf, ETW and NavigationTiming
Debugging IE Performance Issues with xperf, ETW and NavigationTimingDebugging IE Performance Issues with xperf, ETW and NavigationTiming
Debugging IE Performance Issues with xperf, ETW and NavigationTiming
 
iOS Parallel Automation - Viktar Karanevich - Mobile Test Automation Meetup (...
iOS Parallel Automation - Viktar Karanevich - Mobile Test Automation Meetup (...iOS Parallel Automation - Viktar Karanevich - Mobile Test Automation Meetup (...
iOS Parallel Automation - Viktar Karanevich - Mobile Test Automation Meetup (...
 
iOS Parallel Automation: run faster than fast — Viktar Karanevich — SeleniumC...
iOS Parallel Automation: run faster than fast — Viktar Karanevich — SeleniumC...iOS Parallel Automation: run faster than fast — Viktar Karanevich — SeleniumC...
iOS Parallel Automation: run faster than fast — Viktar Karanevich — SeleniumC...
 
Rick Blalock: Your Apps are Leaking - Controlling Memory Leaks
Rick Blalock: Your Apps are Leaking - Controlling Memory LeaksRick Blalock: Your Apps are Leaking - Controlling Memory Leaks
Rick Blalock: Your Apps are Leaking - Controlling Memory Leaks
 
Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...
Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...
Mobile Web Test Automation: to the Desktop! - Alexander Bayandin - Mobile Tes...
 
The current state of web
The current state of webThe current state of web
The current state of web
 
React Native: The Development Flow
React Native: The Development FlowReact Native: The Development Flow
React Native: The Development Flow
 
The Gist of React Native
The Gist of React NativeThe Gist of React Native
The Gist of React Native
 
Deploy Node.js application in Heroku using Eclipse
Deploy Node.js application in Heroku using EclipseDeploy Node.js application in Heroku using Eclipse
Deploy Node.js application in Heroku using Eclipse
 
Titanium appcelerator best practices
Titanium appcelerator best practicesTitanium appcelerator best practices
Titanium appcelerator best practices
 
Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San Francisco
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatGrand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
 
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and PuppeteerE2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
 
Selenium Automation at Incapsula
Selenium Automation at IncapsulaSelenium Automation at Incapsula
Selenium Automation at Incapsula
 

Similar to Get that Corner Office with Angular 2 and Electron

15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
felicidaddinwoodie
 
[OWASP Poland Day] A study of Electron security
[OWASP Poland Day] A study of Electron security[OWASP Poland Day] A study of Electron security
[OWASP Poland Day] A study of Electron security
OWASP
 
Native client
Native clientNative client
Native client
zyc901016
 

Similar to Get that Corner Office with Angular 2 and Electron (20)

Electron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyElectron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easy
 
The Mobile ToolChain with Fastlane - Code Red Talk at RedBlackTree
The Mobile ToolChain with Fastlane - Code Red Talk at RedBlackTreeThe Mobile ToolChain with Fastlane - Code Red Talk at RedBlackTree
The Mobile ToolChain with Fastlane - Code Red Talk at RedBlackTree
 
Electron Firenze 2020: Linux, Windows o MacOS?
Electron Firenze 2020: Linux, Windows o MacOS?Electron Firenze 2020: Linux, Windows o MacOS?
Electron Firenze 2020: Linux, Windows o MacOS?
 
Electron: Linux, Windows or Macos?
Electron: Linux, Windows or Macos?Electron: Linux, Windows or Macos?
Electron: Linux, Windows or Macos?
 
SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...
SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...
SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...
 
Ignite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and FirebaseIgnite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and Firebase
 
Java microservicesspringbootcasestudy2
Java microservicesspringbootcasestudy2Java microservicesspringbootcasestudy2
Java microservicesspringbootcasestudy2
 
Android programming-basics
Android programming-basicsAndroid programming-basics
Android programming-basics
 
ExtJS: La piattaforma vincente (multiple screens)
ExtJS: La piattaforma vincente (multiple screens)ExtJS: La piattaforma vincente (multiple screens)
ExtJS: La piattaforma vincente (multiple screens)
 
Electron presentation
Electron presentationElectron presentation
Electron presentation
 
Learn Electron for Web Developers
Learn Electron for Web DevelopersLearn Electron for Web Developers
Learn Electron for Web Developers
 
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
 
Ios - Introduction to platform & SDK
Ios - Introduction to platform & SDKIos - Introduction to platform & SDK
Ios - Introduction to platform & SDK
 
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
 
Electron - Solving our cross platform dreams?
Electron - Solving our cross platform dreams?Electron - Solving our cross platform dreams?
Electron - Solving our cross platform dreams?
 
[OWASP Poland Day] A study of Electron security
[OWASP Poland Day] A study of Electron security[OWASP Poland Day] A study of Electron security
[OWASP Poland Day] A study of Electron security
 
MattsonTutorialSC14.pdf
MattsonTutorialSC14.pdfMattsonTutorialSC14.pdf
MattsonTutorialSC14.pdf
 
Cross-platform Desktop Apps development using HTML, CSS, JS with Electron
Cross-platform Desktop Apps development using HTML, CSS, JS with ElectronCross-platform Desktop Apps development using HTML, CSS, JS with Electron
Cross-platform Desktop Apps development using HTML, CSS, JS with Electron
 
Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)
 
Native client
Native clientNative client
Native client
 

More from Lukas Ruebbelke

More from Lukas Ruebbelke (12)

Components Are the New Thin Client
Components Are the New Thin ClientComponents Are the New Thin Client
Components Are the New Thin Client
 
ng-conf 2017: Angular Mischief Maker Slides
ng-conf 2017: Angular Mischief Maker Slidesng-conf 2017: Angular Mischief Maker Slides
ng-conf 2017: Angular Mischief Maker Slides
 
Embrace the Angular 2 Ethos in Angular 1.x
Embrace the Angular 2 Ethos in Angular 1.xEmbrace the Angular 2 Ethos in Angular 1.x
Embrace the Angular 2 Ethos in Angular 1.x
 
Go Beast Mode with Realtime Reactive Interfaces in Angular 2 and Firebase
Go Beast Mode with Realtime Reactive Interfaces in Angular 2 and FirebaseGo Beast Mode with Realtime Reactive Interfaces in Angular 2 and Firebase
Go Beast Mode with Realtime Reactive Interfaces in Angular 2 and Firebase
 
The REAL Angular Keynote
The REAL Angular KeynoteThe REAL Angular Keynote
The REAL Angular Keynote
 
Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015
 
Turn Your Designers Into Death Stars with Angular
Turn Your Designers Into Death Stars with AngularTurn Your Designers Into Death Stars with Angular
Turn Your Designers Into Death Stars with Angular
 
Badges? We don't need no stinkin' badges!
Badges? We don't need no stinkin' badges!Badges? We don't need no stinkin' badges!
Badges? We don't need no stinkin' badges!
 
ngAnimate crash course
ngAnimate crash coursengAnimate crash course
ngAnimate crash course
 
Ionic Crash Course! Hack-a-ton SF
Ionic Crash Course! Hack-a-ton SFIonic Crash Course! Hack-a-ton SF
Ionic Crash Course! Hack-a-ton SF
 
ngEurope 2014: Become a Realtime Cage Dragon with Firebase and AngularJS
ngEurope 2014: Become a Realtime Cage Dragon with Firebase and AngularJSngEurope 2014: Become a Realtime Cage Dragon with Firebase and AngularJS
ngEurope 2014: Become a Realtime Cage Dragon with Firebase and AngularJS
 
AngularJS Directives - DSL for your HTML
AngularJS Directives - DSL for your HTMLAngularJS Directives - DSL for your HTML
AngularJS Directives - DSL for your HTML
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 

Get that Corner Office with Angular 2 and Electron

  • 1. Get that Corner Office with Angular 2 and Electron
  • 2. Get acquainted with how to build native, desktop applications using Electron and Angular 2
  • 3. Agenda Running Electron Adding Angular 2 Notifications IPC Packaging Electron
  • 4. The Demo Application • An Instagram style application that allows us to select an image, apply a filter and then save it to our computer • Feel free to use the existing code as a reference point • Please explore! Don't be afraid to try new things!
  • 5.
  • 6.
  • 9. The Elevator Pitch • Use HTML, CSS, and JavaScript with Chromium and Node.js to build your app. • Electron is open source; maintained by GitHub and an active community. • Electron apps build and run on Mac, Windows, and Linux.
  • 10. The Elevator Pitch Pt. 2 • Automatic updates • Crash reporting • Windows installers • Debugging & profiling • Native menus & notifications
  • 11.
  • 12.
  • 14. ➜ npm install electron-prebuilt --save-dev Install Electron
  • 15. "scripts": {
 "start": "electron main.js"
 }, package.json
  • 16. 'use strict';
 
 const electron = require('electron');
 // Module to control application life.
 const app = electron.app;
 // Module to create native browser window.
 const BrowserWindow = electron.BrowserWindow;
 
 // Keep a global reference of the window object, if you don't, the window will
 // be closed automatically when the JavaScript object is garbage collected.
 let mainWindow;
 
 let createWindow = () => {
 // Create the browser window.
 mainWindow = new BrowserWindow({width: 800, height: 600});
 
 // and load the index.html of the app.
 mainWindow.loadURL('file://' + __dirname + '/index.html');
 
 // Open the DevTools.
 // mainWindow.webContents.openDevTools();
 
 // Emitted when the window is closed.
 mainWindow.on('closed', () => {
 // Dereference the window object, usually you would store windows
 // in an array if your app supports multi windows, this is the time
 // when you should delete the corresponding element.
 mainWindow = null;
 });
 }
 
 // This method will be called when Electron has finished
 // initialization and is ready to create browser windows.
 app.on('ready', createWindow);
 
 // Quit when all windows are closed.
 app.on('window-all-closed', () => {
 // On OS X it is common for applications and their menu bar
 // to stay active until the user quits explicitly with Cmd + Q
 if (process.platform !== 'darwin') {
 app.quit();
 }
 });
 
 app.on('activate', () => {
 // On OS X it's common to re-create a window in the app when the
 // dock icon is clicked and there are no other windows open.
 if (mainWindow === null) createWindow();
 });
 main.js
  • 18. Challenges • Install electron-prebuilt • Create a main.js file • Run electron • In the package.json file, create a start task to run electron
  • 20. Adding Angular 2 • Your Angular app generally goes into a sub-folder like src or app • If you are using a build system, you may have to tweak file references to get everything working • We need target attribute to the webpack config that is set to electron-renderer. This gave us the ability to import node and electron modules without breaking. • Finally, the Angular app is in TypeScript, so we need to install the electron typings to use electron packages in our code.
  • 23. Notifications • All three operating systems provide means for applications to send notifications to the user. • Electron conveniently allows developers to send notifications with the HTML5 Notification API, using the currently running operating system’s native notification APIs to display it.
  • 24. let myNotification = new Notification('Title', {
 body: 'Lorem Ipsum Dolor Sit Amet'
 }); Notification
  • 26. Challenges • In the saveFileCallback method in the app.ts file, create an error notification and a success notification
  • 27. IPC
  • 28. IPC • Inter-process communication (IPC) is handled by two different modules • ipcMain in the main process • ipcRenderer in the renderer process • You can also use webContents to send messages to your renderer process
  • 29. const BrowserWindow = electron.BrowserWindow; mainWindow = new BrowserWindow({width: 800, height: 600}); fileMenu.submenu
 .find(item => item.label === 'Open')
 .click = () => mainWindow.webContents.send('open-file') webContents.send
  • 30. import { remote, ipcRenderer } from 'electron'; ipcRenderer.on('open-file', this.open.bind(this));
 ipcRenderer.on('save-file', this.save.bind(this)); ipcRenderer.on
  • 32. Challenges • In the main.js file, complete the save and open click handlers in the setMenu method • Use app.ts file, add save and open handlers to the App constructor
  • 34. Packaging Electron • We used to have to worry about all of packaging for each OS ourselves • Fortunately, electron-packager abstracts most of the tedium away and allows us to run a one script to build for our OS
  • 35. ➜ npm i -g electron-packager Install electron-packager
  • 36. ➜ electron-packager . <appName> --platform=<platform> --arch=<architecture> --out=<outputDirectory> --overwrite --icon=path/to/custom/icon --asar Run electron-packager
  • 38. Challenges • In the package.json file, create a distribute task that uses electron-packager to package the app for your OS