Using Electron and NW.js Paul B. Jensen F Cheng Zhao OREWORD BY M A N N I N G Cross-Platform Desktop Applications Using Electron and NW.js Cross-Platform Desktop Applications USING ELECTRON AND NW.JS PAUL JENSEN MANNING SHELTER ISLAND For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email: [email protected] ©2017 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. Development editor: Cynthia Kane 20 Baldwin Road Technical development editor: Kathleen Estrada PO Box 761 Project editor: Karen Gulliver Shelter Island, NY 11964 Copyeditor: Corbin Collins Proofreader: Katie Tennant Technical proofreader: Clive Harber Typesetter: Dennis Dalinnik Cover designer: Marija Tudor ISBN: 9781617292842 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – EBM – 22 21 20 19 18 17 To Fiona brief contents PART 1 WELCOME TO NODE.JS DESKTOP APPLICATION DEVELOPMENT ..............................................................1 1 ■ Introducing Electron and NW.js 3 2 ■ Laying the foundation for your first desktop application 31 3 ■ Building your first desktop application 54 4 ■ Shipping your first desktop application 75 PART 2 DIVING DEEPER...........................................................89 5 ■ Using Node.js within NW.js and Electron 91 6 ■ Exploring NW.js and Electron’s internals 108 PART 3 MASTERING NODE.JS DESKTOP APPLICATION DEVELOPMENT ..........................................................119 7 ■ Controlling how your desktop app is displayed 121 8 ■ Creating tray applications 143 9 ■ Creating application and context menus 153 10 ■ Dragging and dropping files and crafting the UI 176 vii viii BRIEF CONTENTS 11 ■ Using a webcam in your application 187 12 ■ Storing app data 199 13 ■ Copying and pasting contents from the clipboard 210 14 ■ Binding on keyboard shortcuts 219 15 ■ Making desktop notifications 234 PART 4 GETTING READY TO RELEASE......................................243 16 ■ Testing desktop apps 245 17 ■ Improving app performance with debugging 264 18 ■ Packaging the application for the wider world 291 contents foreword xvii preface xix acknowledgments xxi about this book xxiii about the author xxvii about the cover xxviii PART 1 WELCOME TO NODE.JS DESKTOP APPLICATION DEVELOPMENT ....................................................1 1 Introducing Electron and NW.js 3 1.1 Why build Node.js desktop applications? 4 Desktop to web and back 4 ■ What Node.js desktop apps offer over web apps 6 1.2 The origins of NW.js and Electron 7 1.3 Introducing NW.js 9 A Hello World app in NW.js 9 ■ What features does NW.js have? 14 1.4 Introducing Electron 17 How does Electron work and differ from NW.js? 17 A Hello World app in Electron 18 ■ What features does Electron have? 23 ix
Description: