concept Mac OS in category electron

appears as: Mac OS, Mac OS
Cross-Platform Desktop Applications: Using Node, Electron, and NW.js

This is an excerpt from Manning's book Cross-Platform Desktop Applications: Using Node, Electron, and NW.js.

Listing 1.2. main.js file for the Hello World Electron app
'use strict'; const electron = require('electron'); #1 const app = electron.app; #2 const BrowserWindow = electron.BrowserWindow; #3 let mainWindow = null; #4 app.on('window-all-closed', () => { if (process.platform !== 'darwin') app.quit(); #5 }); app.on('ready', () => { #6 mainWindow = new BrowserWindow(); mainWindow.loadURL(`file://${__dirname}/index.html`); #7 mainWindow.on('closed', () => { mainWindow = null; }); #8 }); #1 - Loads Electron module from npm #2 - Creates reference to Electron’s application object #3 - Creates reference to Electron’s Browser-Window class #4 - mainWindow variable stores reference to app’s window #5 - Add event listener that quits the app when all windows are closed (except in Mac OS) #6 - Creates new app window and assigns it to main window variable to prevent it being closed by Node.js garbage collection #7 - Loads index.html file in app window #8 - When app window is closed, unassigns app window from main window variable

In this chapter, we’ll explore those options and show how to package your app as executable binaries for Mac OS, Microsoft Windows, and Linux (Ubuntu), including creating Windows installers for your Electron apps.

Figure 18.14. Running appdmg on Mac OS. If all goes well, you can expect to see an itemized breakdown of the tasks being performed to create the .dmg file, and they should all be green.

18.3.2. Creating an Electron app executable for Mac OS

Electron offers a number of npm modules that can take care of creating the app executable on Mac OS, including electron-builder, mentioned earlier. You’ll use the electron-builder module because it provides a good UX for creating packaged app builds of Electron apps.