Book Image

NW.js Essentials

Book Image

NW.js Essentials

Overview of this book

Table of Contents (17 chapters)
NW.js Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

The NativeUI layer


As we have done with the application layer, before writing any line of code, we'd better take a look at which features we need the NativeUI layer to implement:

  • Implement a Window menu

  • Implement a Context menu on the to-dos content

  • Restore the Main window position when opening the application

  • Implement an Options window

  • On exit, store the windows position, let the Options window save data and compact the database

  • Open the application smoothly when everything has been loaded

First, we need to call myApp.nativeUI.init() from inside myApp.init() in js/main.js, and then we can open the js/nativeui.js file and add the following code:

myApp.nativeUI = {};
myApp.nativeUI.init = function () {
  // Instance nw.gui
  myApp.gui = require('nw.gui');
  // Globals
  myApp.mainWindow = myApp.gui.Window.get();
  myApp.name = myApp.gui.App.manifest.name;
  // -- Call the other functions here --
};
// -- Declare the other functions here --

In the first two rows, we performed the following actions...