Book Image

Cross-platform Desktop Application Development: Electron, Node, NW.js, and React

By : Dmitry Sheiko
Book Image

Cross-platform Desktop Application Development: Electron, Node, NW.js, and React

By: Dmitry Sheiko

Overview of this book

Building and maintaining cross-platform desktop applications with native languages isn’t a trivial task. Since it’s hard to simulate on a foreign platform, packaging and distribution can be quite platform-specific and testing cross-platform apps is pretty complicated.In such scenarios, web technologies such as HTML5 and JavaScript can be your lifesaver. HTML5 desktop applications can be distributed across different platforms (Window, MacOS, and Linux) without any modifications to the code. The book starts with a walk-through on building a simple file explorer from scratch powered by NW.JS. So you will practice the most exciting features of bleeding edge CSS and JavaScript. In addition you will learn to use the desktop environment integration API, source code protection, packaging, and auto-updating with NW.JS. As the second application you will build a chat-system example implemented with Electron and React. While developing the chat app, you will get Photonkit. Next, you will create a screen capturer with NW.JS, React, and Redux. Finally, you will examine an RSS-reader built with TypeScript, React, Redux, and Electron. Generic UI components will be reused from the React MDL library. By the end of the book, you will have built four desktop apps. You will have covered everything from planning, designing, and development to the enhancement, testing, and delivery of these apps.
Table of Contents (9 chapters)

Registering global keyboard shortcuts

Menu in tray is a solution, but actually, we have an option to perform capturing actions even without opening the menu. NW.js allows us to assign global keyboard shortcuts:

  const shortcut = new nw.Shortcut({ 
key: "Shift+Alt+4",
active: () => {}
failed: console.error
});

nw.App.registerGlobalHotKey( shortcut );
appWindow.on( "close", () => nw.App.unregisterGlobalHotKey( shortcut ) );
window.addEventListener( "beforeunload", () => nw.App.unregisterGlobalHotKey( shortcut ), false );

We use nw.Shortcut to create an object representing a shortcut. With nw.App.registerGlobalHotKey, the shortcut is registered. We use nw.App.unregisterGlobalHotKey to unregister the shortcut when the application closes or reloads.

That brings us to the following service:

./js/Service/Shortcut.js

const...