Few months ago I had made two posts “Making Fancy GNOME Apps with NodeJS, MongoDB and WebKit!” and “Run GNOME + HTML5 Applications over Network” that were using GtkWebkit on the top of a NodeJS instance. Furthermore I was illustrating how we can create Apps that can be Client/Server at the same time, and connected between them with WebSockets.
That means that you can pass an event from the local side to the remote side, the remote will execute a “Gnomish” process, and when done it will return a message to the local. By “Gnomish” process I mean a process of a Gnome Library, but it can be any library available under Linux.
Today, I will totally escape the GNOME Dependencies (as GTK) , and I’ll shortly point out the way of doing things just with Node-Webkit.
Get started with an App
Before we get started writing an application, we need to analyze the requirements and choose our development tools. Unfortunately “tools” and “requirements” are very relevant each other, and many times we have to use certain frameworks for certain tasks. For instance, if you want to write a Utility for Gnome, Node-Webkit won’t be the most optimal way, although it will be possible.
Portability is one of the most significant requirements for any (but Utilities) application. While so far we were thinking portability as something that will work with the minimum effort in Mac/Win/Linux platforms things seems to have changed.
Linux Desktop fragmentation (mostly –but not only– with Ubuntu and everyone else), the many Desktops (Unity, KDE, GNOME, XFCE, Cinnamon etc), the different versions of libs that distros package, and many many more factors (as patching the upstream) has gave a new meaning in “portability”.
Perfect scenario. Write something ONCE, that works EVERYWHERE. NodeJs is almost there.
Rapid Application Development (RAD)
~200 lines of JS code using OpenWeatherMap API
That is what Node-Webkit is about. You can use all Web-Technologies in desktop -hybrid- native applications, and at the same time you can call NodeJS and some of the hundreds of existent plugins directly from DOM!
I guess you all know the possibilities of HTML 5, you are using them daily ;)
Performance should be okay, Node and WebKit runs in the same thread and function calls are made straightforward. However V8 run in a Virtual Machine and such things are always memory hungry. In reality “performance” won’t be an issue in most common cases.
Wouldn’t be awesome if we can package and distribute our application for any Linux Distro, in a matter of few minutes? Node-WebKit does that by shipping the run-time environment into your App.
Authentication and connection with services like Google, Twitter etc is really trivial. What makes things even better is the amazing async I/O, and how easily can we organize a queue with our tasks.
Speaking of files handling, NodeJS also does awesome with databases like MongoDB and key-values data store like Redis (if we don’t need ACID), which are two great solutions for storing and retrieving App data.
But then again, if you want your App to run everywhere that isn’t even a concern. If you want your App to target GNOME, again the advantages of WebKit maybe overtaken the disadvantage of a good integration. It is all about what are you going to build.
A real world example (-not open source-) is a an application that you drag image files on the browser window and it does real time cropping while displays the status (%) on browser. You can actually keep adding images on browser and start as many threads as you like.
So such kind of Apps are possible with NodeJS. The trick here is that we use NodeJS as interface, while in background we run a C++ program, that does all the dirty work and passes messages to our server and therefore to client at real time.
Basically the same way that you can write multi-threads apps with GJS and GIO Async C API (I think this, since I haven’t used GIO), the same way you can do this with Node-Webkit.
The Spring Seed Example
Spring Seed is an application that syncs your notes with Drop Box. If you visit their page they only give an Ubuntu client. Of course if you unzip the .deb package there, you can run it from any distro. What all those apps do, is to ship the Node-Webkit environment in a single package.
Because NodeJS evolves awesomely fast, it is impossible to use it a system wide version of it. Every App you make, needs its very own NodeJS Version. Yes we are talking about bundles, that just run ..and run everywhere!
Spring Seed looks really great ..and is really fast. Notice that it uses its own Window Controls.
Oh yes, we can easily add our usual Mutter Controls. However I think that we don’t want that. Specially when GNOME will port everything under Client Side Decorations and Wayland. Which we can mimic easily with some CSS. Or make them even better!
Well, this is about Webkit so why don’t add a URL bar? We might want to check if Note Sync actually works, by visiting Drop Box site ;)
What if we replace GTK/Qt with WebKit?
First of, I used Node-Webkit (NW) for first time yesterday and I just spend 5-6 hours on it. Secondly I don’t have any serious Desktop Programming experience. I can’t really reckon that Node-Webkit is a superior way to do things over GTK and Qt. Possible it depends from what are you going to build. If is something Cloudy, NW is the way to go!
However I am pretty sure that the impact of NW will be huge in Linux Desktop!
I am wondering what would happen if GNOME had an JS/CSS framework for creating native looking Gnome Web Apps, and some Node modules to communicate with things like GNOME Notifications. One thing I bet on, it would have had many many ..many more contributors ;)
Because NW is developed from Intel and keeping on mind the close relationships between GNOME and Intel developers ..who knows ..maybe a day ..not far from now ;)
Yesterday was my first touch with NW and what I am trying to do is an App similar to GNOME Docs, that will sync with Google Drive and let you store the files in your disk, by popping a GNOME Notification “You successfully saved a file”. The funny part is that the hard part ..is the notification part ;)
So next post about Node Webkit will be this as an example ;)
To dive into these cool things you don’t need nothing but ..
Happy Hacking ;)