Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Cross-platform Desktop Application Development: Electron, Node, NW.js, and React
Cross-platform Desktop Application Development: Electron, Node, NW.js, and React

Cross-platform Desktop Application Development: Electron, Node, NW.js, and React: Build desktop applications with web technologies

eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

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

Creating a File Explorer with NW.js – Enhancement and Delivery

Well, we have a working version of File Explorer that can be used to navigate the filesystem and open files with the default associated program. Now we will extend it for additional file operations, such as deleting and copy pasting. These options will keep in a dynamically built context menu. We will also consider the capabilities of NW.js to transfer data between diverse applications using the system clipboard. We will make the application respond to command-line options. We will also provide support for multiple languages and locales. We will protect the sources by compiling them into native code. We will consider packaging and distribution. At the end, we will set up a simple release server and make the File Explorer auto-update.

Internationalization and localization

Internationalization, often abbreviated as i18n, implies a particular software design capable of adapting to the requirements of target local markets. In other words, if we want to distribute our application to markets other than the USA, we need to take care of translations, formatting of datetime, numbers, addresses, and such.

Date format by country

Internationalization is a cross-cutting concern. When you are changing the locale, it usually affects multiple modules. So, I suggest going with the observer pattern that we already examined while working on DirService:
./js/Service/I18n.js

const EventEmitter = require( "events" ); 

class I18nService extends EventEmitter {
constructor...

Context menu

Well, with our application, we can already navigate through the filesystem and open files, yet one might expect more of a File Explorer. We can add some file-related actions, such as delete and copy/paste. Usually, these tasks are available via the context menu, which gives us a good opportunity to examine how to make it with NW.js. With the environment integration API, we can create an instance of system menu (http://docs.nwjs.io/en/latest/References/Menu/). Then, we compose objects representing menu items and attach them to the menu instance (http://docs.nwjs.io/en/latest/References/MenuItem/). This menu can be shown in an arbitrary position:

const menu = new nw.Menu(), 
menutItem = new nw.MenuItem({
label: "Say hello",
click: () => console.log( "hello!" )
});

menu.append( menu );
menu.popup( 10, 10 );

Yet, our...

System clipboard

Usually, the copy/paste functionality involves system clipboard. NW.js provides an API to control it (http://docs.nwjs.io/en/latest/References/Clipboard/). Unfortunately, it's quite limited; we cannot transfer an arbitrary file between applications, which you may expect of a file manager. Yet, some things are still available to us.

Transferring text

In order to examine text transferring with the clipboard, we modify the method copy of FileService:

copy( file ){ 
this.copiedFile = this.dir.getFile( file );
const clipboard = nw.Clipboard.get();
clipboard.set( this.copiedFile, "text" );
}

What does it do? As soon as we obtain the file full path, we create an instance of nw.Clipboard...

Menu in the system tray

All three platforms available for our application have a so-called system notification area, which is also known as the system tray. That's a part of the user interface (in the bottom-right corner on Windows and top-right corner on other platforms) where you can find the application icon even when it's not present on the desktop. Using the NW.js API (http://docs.nwjs.io/en/latest/References/Tray/), we can provide our application with an icon and drop-down menu in the tray, but we do not have any icon yet. So, I have created the icon.png image with the text Fe and saved it in the application root in the size of 32x32px. It is supported on Linux, Windows, and macOS. However, in Linux, we can go with a better resolution, so I have placed the 48x48px version next to it.

Our application in the tray will be represented by TrayService:

./js/View/Tray...

Command-line options

Other file managers usually accept command-line options. For example, you can specify a folder when launching Windows Explorer. It also responds to various switches. Let's say that you can give it switch /e, and Explorer will open the folder in expanded mode.

NW.js reveals command-line options as an array of strings in nw.App.argv. So, we can change the code of the DirService initialization in the main module:

./js/app.js

const dirService = new DirService( nw.App.argv[ 0 ] );

Now, we can open a specified folder in the File Explorer straight from the command line:

npm start ~/Sandbox

In UNIX-based systems, the tilde means user home directory. The equivalent in Windows will be as follows:

npm start %USERPROFILE%Sandbox

What else can we do? Just for a showcase, I suggest implementing the --minimize and --maximize options that switch the application window...

Native look and feel

Nowadays, one can find plenty of native desktop applications with semi-transparent background or with round corners. Can we achieve such fancy look with NW.js? Sure we can! First, we shall edit our application manifest file:

./package.json

... 
"window": {
"frame": false,
"transparent": true,
...
},
...

By setting the frame field to false, we instruct NW.js to not show the window frame, but its contents. Fortunately, we have already implemented custom windowing controls as the default ones will not be available anymore. With a transparent field, we remove the opacity of the application window. To see it in action, we edit the CSS definitions module:

./assets/css/Base/definitions.css

:root { 
--titlebar-bg-color: rgba(45, 45, 45, 0.7);
--titlebar-fg-color: #dcdcdc;
--dirlist- bg-color: rgba(222, 222, 222, 0...

Source code protection

Unlike in native applications, our source code isn't compiled and is therefore open to everybody. If you have any commercial use of this fact in mind, it is unlikely to suit you. The least you can do is to obfuscate the source code, for example, using Jscrambler (https://jscrambler.com/en/). On the other hand, we can compile our sources into native code and load it with NW.js instead of JavaScript. For that, we need to separate JavaScript from the application bundle. Let's create the app folder and move everything except js there. The js folder will be moved into a newly created directory, src:

    .
├── app
│ └── assets
│ └── css
│ ├── Base
│ └── Component
└...

Packaging

Well, we have completed our application and that is the time to think about distribution. As you understand, asking our users to install Node.js and type npm start from the command line will not be friendly. Users will expect a package that can be started as simply as any other software. So, we have to bundle our application along with NW.js for every target platform. Here, nwjs-builder comes in handy (https://github.com/evshiron/nwjs-builder).

So, we install the npm i -D nwjs-builder tool and add a task to the manifest:

./package.json

//... 
"scripts": {
"package": "nwb nwbuild -v 0.21.3-sdk ./app -o ./dist -p linux64, win32,osx64",
//...
},
//...

Here, we specified three target platforms (-p linux64, win32,osx64) at once and thus, after running this task (npm run package), we get platform-specific subfolders in the dist...

Autoupdate

In the era of continuous deployment, new releases are issued pretty often. As developers, we have to ensure that users receive the updates transparently, without going through the download/install routine. With the traditional web application, it's taken for granted. Users hit the page and the latest version gets loaded. With desktop applications, we need to deliver the update. Unfortunately, NW.js doesn't provide any built-in facilities to handle autoupdates, but we can trick it; let's see how.

First of all, we need a simple release server. Let's give it a folder (for example, server) and create the manifest file there:

./server/package.json

{ 
"name": "release-server",
"version": "1.0.0",
"packages": {
"linux64": {
"url": "http://localhost:8080/releases/file...

Summary

In the beginning of this chapter, our File Explorer could only navigate the filesystem and open files. We extended it to show a file in the folder, and to copy/paste and delete files. We exploited the NW.js API to provide the files with the dynamically-built context menu. We learned to exchange text and images between applications using system clipboard. We made our File Explorer support diverse command-line options. We provided support for internalization and localization, and examined the protection of the sources through compilation in the native code. We went through the packaging process and prepared for distribution. Finally, we set up a release server and extended the File Explorer with a service for autoupdating.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Build different cross-platform HTML5 desktop applications right from planning, designing, and deployment to enhancement, testing, and delivery
  • Forget the pain of cross-platform compatibility and build efficient apps that can be easily deployed on different platforms.
  • Build simple to advanced HTML5 desktop apps, by integrating them with other popular frameworks and libraries such as Electron, Node.JS, Nw.js, React, Redux, and TypeScript

Description

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.

Who is this book for?

This book has been written for developers interested in creating desktop applications with HTML5. The first part requires essential web-master skills (HTML, CSS, and JavaScript). The second demands minimal experience with React. And finally for the third it would be helpful to have a basic knowledge of React, Redux, and TypeScript.

What you will learn

  • ? Plan, design, and develop different cross-platform desktop apps
  • ? Application architecture with React and local state
  • ? Application architecture with React and Redux store
  • ? Code design with TypeScript interfaces and specialized types
  • ? CSS and component libraries such as Photonkit, Material UI, and React MDL
  • ? HTML5 APIs such as desktop notifications, WebSockets, WebRTC, and others
  • ? Desktop environment integration APIs of NW.js and Electron
  • ? Package and distribute for NW.JS and Electron

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 27, 2017
Length: 300 pages
Edition : 1st
Language : English
ISBN-13 : 9781788295697
Vendor :
GitHub
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jul 27, 2017
Length: 300 pages
Edition : 1st
Language : English
ISBN-13 : 9781788295697
Vendor :
GitHub
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 115.97
Cross-platform Desktop Application Development: Electron, Node, NW.js, and React
€36.99
Progressive Web Apps with React
€36.99
Node Cookbook
€41.99
Total 115.97 Stars icon

Table of Contents

8 Chapters
Creating a File Explorer with NW.js-Planning, Designing, and Development Chevron down icon Chevron up icon
Creating a File Explorer with NW.js – Enhancement and Delivery Chevron down icon Chevron up icon
Creating a Chat System with Electron and React – Planning, Designing, and Development Chevron down icon Chevron up icon
Creating a Chat System with Electron and React – Enhancement, Testing, and Delivery Chevron down icon Chevron up icon
Creating a Screen Capturer with NW.js, React, and Redux – Planning, Design, and Development Chevron down icon Chevron up icon
Creating a Screen Capturer with NW.js: Enhancement, Tooling, and Testing Chevron down icon Chevron up icon
Creating RSS Aggregator with Electron, TypeScript , React, and Redux: Planning, Design, and Development Chevron down icon Chevron up icon
Creating RSS Aggregator with Electron, TypeScript, React, and Redux: Development Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
(1 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 100%
moml mohmmed Oct 14, 2020
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Too many typos, wrong codes, terrible formattingPlease save your money
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.