Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Desktop Apps with Node Webkit

Desktop Apps with Node Webkit

This is a talk I gave at LNUG June 2014 about building desktop applications with Node Webkit

Paul Jensen

June 26, 2014
Tweet

More Decks by Paul Jensen

Other Decks in Technology

Transcript

  1. Node Webkit is an app runtime that lets you make

    desktop apps with HTML, CSS, and JavaScript.
  2. But not only that, you can build native executables of

    your app for Windows, Mac and Linux
  3. Integrating them requires the following: • Using the same V8

    engine instance • Main loop integration • Context Bridging
  4. Use the same V8 engine instance • Both Chromium and

    Node use the V8 engine instance (Node use’s Chromium’s instance) • The objects of Node and Chromium are in separate contexts, in order to keep the namespace clean.
  5. Main loop integration • The author says that it would

    take “some efforts” to merge both Node and Chromium’s main loops. • Node uses libuv for the events loop, but Chromium uses MessageLoop and MessagePump for its events loop. • The author integrates these at the browser render process level, by making Chromium use a custom version of the MessagePump class, built on top of libuv
  6. Context Bridging • It’s a tricky but important part of

    integrating Node into Chromium • The first step is to initialise Node’s context first • Next, once Webkit’s DOM context is installed, Node’s context is moved into Webkit’s context • After that, Node’s start function is split into parts so that it can run within the context of Webkit’s render process
  7. And we could iterate on this example further… • We

    could turn the list items into links for exploring folders • We could use front-end libraries like jQuery-ui or Bootstrap to improve the UI and make it display better • We could make the file names (and possibly even contents) searchable using Lunr.js or an embedded database. • We could stream those files to a server for file synchronisation (build your own Dropbox!)
  8. Window Rendering • Node Webkit allows you to control how

    you want the Window rendering to work • You can specify set dimensions, whether full- screen is allowed, and even if there’s a window frame at all!
  9. Kiosk Mode • Useful for creating fullscreen applications that run

    in public places (Banks, Retail, Venues) • Access to the operating system is disabled on Mac, but you can gain access on Windows via Ctrl-Alt-Del keys (otherwise it’s blocked by AV Software as it looks like a virus to them) • Its dangerous - if you don’t implement the javascript call to leave kiosk mode anywhere in your app, you’ll have to reboot your computer to regain access
  10. You can add native menu items to your app, both

    in the main menu, and in the app area
  11. HTML5 APIs • Canvas (drawing, games) • WebGL (3D, games)

    • WebRTC (video/audio chat, P2P) • CSS3 (games, animations) • LocalStorage (offline editing) • Audio/Video (video players, music streaming)
  12. Every year, we run the web site for a health

    conference run by the BMJ and IHI
  13. As part of our service, we also produce a desktop

    app that lets people view recorded sessions, posters, and file attachments.
  14. Disadvantages • To use it, the person would have to

    have Flash installed on their computer • Once they had installed the app onto the computer, they would then be prompted to locate the application’s content on the USB stick. • Adobe Air is a declining platform (Linux no longer supported, Flash is dying)
  15. A couple of weeks after the event, we shipped the

    desktop app, using Node Webkit
  16. The app’s tech stack • Node Webkit, with ffmpeg dependency

    added in for video • Bootstrap 3 for the UI • jQuery and Backbone for the front-end app • Lunr.js for the search functionality • Stylus, and Jade for creating the HTML and CSS files • Hogan.js for templating • Gulp for the building of the app’s files
  17. Benefits • Users no longer had to install Flash or

    select the USB from a Folder Dialog. A simpler, better user experience. • We were able to reuse some of the code from the web application in the desktop application. • It allowed us to standardise around a Node tech stack within the company more.
  18. 2 - Add a CSS class to the video tag,

    which has properties that make the element take the full dimensions of the window
  19. The dev tools will help to spot slow points in

    front-end rendering and performance
  20. It’s so good, that Intel replaced their use of Java

    and Chrome in their IDE with Node Webkit
  21. There is still so much I still haven’t covered about

    Node Webkit. ! I recommend reading more about it at the Github repo and online
  22. I hope you get a chance to play with it

    and create something amazing!