Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
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
₹799 ₹2919.99
Paperback
₹3649.99
Subscription
Free Trial
Renews at ₹800p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
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
Estimated delivery fee Deliver to India

Premium delivery 5 - 8 business days

₹630.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to India

Premium delivery 5 - 8 business days

₹630.95
(Includes tracking information)

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
₹800 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
₹4500 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 ₹400 each
Feature tick icon Exclusive print discounts
₹5000 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 ₹400 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 11,396.97
Node Cookbook
₹4096.99
Progressive Web Apps with React
₹3649.99
Cross-platform Desktop Application Development: Electron, Node, NW.js, and React
₹3649.99
Total 11,396.97 Stars icon
Banner background image

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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela