Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

NW.js Essentials
NW.js Essentials
NW.js Essentials
Ebook367 pages2 hours

NW.js Essentials

Rating: 0 out of 5 stars

()

Read preview

About this ebook

About This Book
  • Leverage all the power of well-known web technologies such as Node.js/io.js, HTML5, and CSS to develop desktop applications
  • Develop and deploy modern desktop applications on Microsoft Windows, Mac Os X, and Linux
  • A practical guide that demonstrates how developing applications on NW.js differs from standard server/client programming
Who This Book Is For

If you are an experienced Node.js developer who wants to create amazing desktop applications using NW.js, this is the book for you. Prior knowledge of HTML5, jQuery, and CSS is assumed.

LanguageEnglish
Release dateMay 25, 2015
ISBN9781785287008
NW.js Essentials

Related to NW.js Essentials

Related ebooks

Applications & Software For You

View More

Related articles

Reviews for NW.js Essentials

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    NW.js Essentials - Alessandro Benoit

    Table of Contents

    NW.js Essentials

    Credits

    About the Author

    Acknowledgments

    About the Reviewers

    www.PacktPub.com

    Support files, eBooks, discount offers, and more

    Why subscribe?

    Free access for Packt account holders

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Reader feedback

    Customer support

    Errata

    Piracy

    Questions

    1. Meet NW.js

    NW.js under the hood

    Features and drawbacks of NW.js

    NW.js – usage scenarios

    Popular NW.js applications

    Downloading and installing NW.js

    Installing NW.js on Mac OS X

    Installing NW.js on Microsoft Windows

    Installing NW.js on Linux

    Development tools

    Writing and running your first Hello World app

    Running NW.js applications on Sublime Text 2

    Running NW.js applications on Microsoft Windows

    Running NW.js applications on Mac OS

    Running NW.js applications on Linux

    Summary

    2. NW.js Native UI APIs

    The App API – the core of your applications

    Opening a file in your application natively

    Accessing the application data folder path

    Accessing the manifest file data

    Best practices for closing applications

    Registering system-wide hotkeys

    Other app APIs

    The Window API – working with windows on NW.js

    Instantiating a new window object

    Window – setting size and position of windows

    Changing the window status

    Fullscreen windows and the Kiosk mode

    Frameless windows and drag regions

    The taskbar icon – get the user's attention!

    Closing windows

    Other Window APIs

    The Screen API – screen geometry functions

    The Menu API – handling window and context menus

    The contextual menu

    The window menu

    File dialogs – opening and saving files

    Opening multiple files

    Filtering by file type

    Opening a directory

    Saving files

    Suggesting a default path

    Opening files through file dragging

    The Tray API – hide your application in plain sight

    The Clipboard API – accessing the system clipboard

    The Shell API – platform-dependent desktop functions

    Summary

    3. Leveraging the Power of Node.js

    Routing and templating in NW.js

    Node.js global and process objects

    The window object

    Using NW.js' main module

    Handling paths in NW.js

    NW.js context issues

    Working with Node.js modules

    Internal modules

    Third-party modules written in JavaScript

    Third-party modules with C/C++ add-ons

    Summary

    4. Data Persistence Solutions and Other Browser Web APIs

    Data persistence solutions

    Web storage

    Web SQL Database

    IndexedDB

    XMLHttpRequest and BLOBs

    Handling media files

    Shedding some light on security issues

    The Web Notifications API

    Summary

    5. Let's Put It All Together

    Let's get started!

    A matter of style

    The HTML5 skeleton

    Let's dive deep into the application logic

    The application layer

    Adding a new task

    Loading all the tasks

    Implementing export and sync features

    The NativeUI layer

    Implementing the Window menu

    Implementing the Context menu

    Restoring the window position

    Implementing the Options window

    Closing the application

    Making the application open smoothly

    Summary

    6. Packaging Your Application for Distribution

    The manifest file

    The general logic behind the packaging procedure

    Packaging NW.js applications for Mac OS X

    Associating a file extension with your application

    Packaging NW.js applications for Microsoft Windows

    Registering a file type association on Microsoft Windows

    Packaging NW.js applications for Linux

    Adding icon and file type associations on Linux

    Securing your source code

    About NW.js application licensing

    Summary

    7. Automated Packaging Tools

    Web2Executable

    node-webkit-builder and grunt-node-webkit-builder

    grunt-node-webkit-builder

    generator-node-webkit

    Summary

    8. Let's Debug Your Application

    Remote debugging

    The DevTools API

    Live reloading NW.js

    Troubleshooting common issues

    Summary

    9. Taking Your Application to the Next Level

    NW.js boilerplates

    node-webkit-hipster-seed

    angular-desktop-app

    node-webkit-tomster-seed

    node-webkit-boilerplate

    nw-boilerplate

    Development ideas

    Resources and tutorials

    Summary

    Index

    NW.js Essentials


    NW.js Essentials

    Copyright © 2015 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: May 2015

    Production reference: 1190515

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham B3 2PB, UK.

    ISBN 978-1-78528-086-3

    www.packtpub.com

    Credits

    Author

    Alessandro Benoit

    Reviewers

    Dan Bendell

    Marco Fabbri

    Julio Freitas

    Commissioning Editor

    Amarabha Banerjee

    Acquisition Editor

    Reshma Raman

    Content Development Editor

    Gaurav Sharma

    Technical Editor

    Humera Shaikh

    Copy Editor

    Sarang Chari

    Project Coordinator

    Harshal Ved

    Proofreaders

    Stephen Copestake

    Safis Editing

    Indexer

    Mariammal Chettiyar

    Graphics

    Disha Haria

    Abhinash Sahu

    Production Coordinator

    Alwin Roy

    Cover Work

    Alwin Roy

    About the Author

    Alessandro Benoit is a 31-year-old web developer from Italy. He currently works both with backend and frontend technologies, ranging from PHP development, mostly on WordPress and Laravel, to web design and building open source jQuery plugins. He's also an early adopter of NW.js and the developer of Nuwk!, an open source application that simplifies the building process of NW.js applications on Mac OS X.

    Acknowledgments

    NW.js Essentials is my first attempt at becoming a technical book writer. Writing it has been fun and exciting but also quite harsh. There were moments between work and personal issues when I thought I couldn't make it. But here we are! What I want to do now is thank all the wonderful people who have accompanied me on this journey.

    First of all, I want to thank the whole open source community. These people are the reason I'm in information technology in the first place. I can still remember when I was 14 and some guy on IRC was teaching me about breaking NetBios to gain access to remote hosts of Microsoft Windows (I swear, I've never done any harm); that was the first time I realized how thrilling technology was to me.

    I really can't help being grateful to Roger Wang for all the effort he's taken to make NW.js an easy and stable environment to bring web technologies to our desktops.

    I want to personally thank Reshma Raman and Gaurav Sharma, my editors at Packt Publishing. I have never met them in person, but still they have been positive and supportive during the whole writing process.

    Thanks to Marco Fabbri, Dan Bendell, and Julio Freitas, for the great job they have done in reviewing this book.

    I have to thank Abramo Capozzolo, my employer at Comodolab, for being so open to the use of the latest technologies and for putting people and research above revenues. And of course, I would like to thank my colleague and friend, Christian Pucci, for bringing me in, in the first place.

    Thanks to my life partner, Elisa Rocchi, for being present and always understanding despite my recent mood swings. And thanks to my best friend, Andrea Valli, for still being my friend after months of absence.

    Thanks to my mother, Patrizia Capacci, for loving me unconditionally.

    Finally, I want to dedicate the publication of this book to an old friend who unfortunately is no longer here to share this joy. This is also for you, Andrea Benvenuti.

    About the Reviewers

    Dan Bendell is a budding young developer currently at the University of Plymouth studying computing and game development. He is set to finish his studies in 2016 after completing a year of work in the industry. Upon finishing his academic endeavors, he wishes to pursue his dream of either creating a start-up or working within a game company that will allow him to create games that truly engage his audience and work with a variety of new people on a daily basis.

    Marco Fabbri is an experienced software engineer and former professor of distributed systems (middleware for multi-agent systems, ReST architecture, and Node.js) at the University of Bologna, Italy. He's also an active contributor in NW.js codebase.

    Julio Freitas completed his graduation in computer science with specialization in information systems and technology. He has been a developer of web applications since the year 2000. He worked as a developer and Unix systems administrator in projects of grid computing with Java and PHP for 5 years at the Center for Weather Forecasting and Climate Studies/National Institute for Space Research (CPTEC/INPE), Brazil. He currently resides in England, where he works in a web systems company, and he is now creating his own start-up and acting as a full-stack web developer in projects focused on API development and security and applications for mobile devices using the MEAN stack and Ionic.

    Julio has also reviewed JavaScript Regular Expressions, Loiane Groner, Packt Publishing.

    www.PacktPub.com

    Support files, eBooks, discount offers, and more

    For support files and downloads related to your book, please visit www.PacktPub.com.

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    https://www2.packtpub.com/books/subscription/packtlib

    Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

    Why subscribe?

    Fully searchable across every book published by Packt

    Copy and paste, print, and bookmark content

    On demand and accessible via a web browser

    Free access for Packt account holders

    If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

    Preface

    NW.js is a web app runtime, based on Node.js and the Chromium open source browser project, which enables web developers to build native-like desktop applications for Windows, Mac OS X, or Linux, leveraging all the power of well-known web technologies such as Node.js, HTML5, and CSS.

    In NW.js Essentials, you'll be guided through the full development process, starting from the theoretical basis behind NW.js technology to the realization of a fully working, multiplatform desktop application.

    What this book covers

    Chapter 1, Meet NW.js, provides a presentation of the NW.js technology followed by a brief digression on how NW.js works under the hood, an analysis of the strengths of the library, and eventually a step-by-step tutorial on building a first, simple Hello World application.

    Chapter 2, NW.js Native UI APIs, takes you through a thorough description of Native UI APIs with examples on how to interact with OS windows, work with menus, run shell commands, and much, much more.

    Chapter 3, Leveraging the Power of Node.js, gives an introduction of how NW.js development differs from standard server/client programming and a few interesting hints on how to get the maximum out of Node.js within NW.js applications.

    Chapter 4, Data Persistence Solutions and Other Browser Web APIs, explains more about data handling and takes advantage of Browser Web APIs to build beautiful, usable, and native-like desktop applications.

    Chapter 5, Let's Put It All Together, builds a fully working application based on many of the concepts you've learned in the previous chapters.

    Chapter 6, Packaging Your Application for Distribution, gives a step-by-step tutorial on the packaging process of NW.js applications on Microsoft Windows, Mac OS X, and Linux.

    Chapter 7, Automated Packaging Tools, takes advantage of third-party tools to simplify the packaging process of NW.js applications.

    Chapter 8, Let's Debug Your Application, teaches you different ways to debug your application and a few common issues of NW.js.

    Chapter 9, Taking Your Application to the Next Level, involves a collection of ideas and resources to get the best out of what you've learned in this book.

    What you need for this book

    In order to fully understand the concepts explained in the book, a decent knowledge of the following subjects is mandatory:

    Node.js programming and working with Node.js modules

    Modern web application languages such as HTML5, CSS3, and JavaScript

    Being comfortable with the use of the Unix terminal and the Microsoft Windows command line

    It's not mandatory, but it might be helpful to have previous experience in the use of JavaScript task runners such as Gulp and Grunt.

    Who this book is for

    The book is targeted at experienced Node.js developers with a basic understanding of frontend web development.

    Conventions

    In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

    Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user

    Enjoying the preview?
    Page 1 of 1