concept computer in category electron

appears as: computer, computers, computer
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.

Over time, that began to change: improvements in web browsers, greater internet speeds and access, and the movement toward open source software resulted in a major shift in how software was created and distributed. The advent of AJAX spawned a new era of delivering software as web apps. These apps didn’t require downloading anything onto the computer, and they could run across multiple OSs. Companies like Google and Facebook signaled the rise of the web as a powerful platform in the industry, and as people became accustomed to using apps online for a monthly fee, traditional software houses adapted and began to offer their software online.

Listing 14.1. The main.js file in the Snake Electron app
'use strict'; const {app, globalShortcut, BrowserWindow} = require('electron'); #1 let mainWindow = null; app.on('window-all-closed', () => { if (process.platform !== 'darwin') app.quit(); }); app.on('ready', () => { mainWindow = new BrowserWindow({ width: 840, height: 470, useContentSize: true }); mainWindow.loadURL(`file://${__dirname}/index.html`); mainWindow.on('closed', () => { mainWindow = null; }); const pauseKey = globalShortcut.register('CommandOrControl+P', () => { #2 mainWindow.webContents.send('togglePauseState'); #3 }); if (!pauseKey) alert('You will not be able to pause the game from the keyboard'); #4 }); app.on('will-quit', () => { globalShortcut.unregister('CommandOrControl+P'); #5 }); #1 - Requires the globalShortcut dependency from Electron #2 - Registers the keyboard shortcut #3 - When keyboard shortcut is triggered, emits event to app window #4 - If you couldn’t register keyboard shortcut, alerts user #5 - When app quits, unregisters keyboard shortcut from computer