Javascript, the GNOME way (JSConf EU 2011)

36 %
64 %
Information about Javascript, the GNOME way (JSConf EU 2011)
Technology

Published on March 19, 2014

Author: igalia

Source: slideshare.net

Description

By Eduardo Lima.

GNOME, the free desktop environment, has embraced Javascript. Starting from version 3.0, Javascript is at the core of the user experience delivered to tens of thousands of GNOME users out there. We call it the gnome-shell, but the real beauty lies within.

This presentation will give you a brief tour around the great technology behind the shell, a technology that GNOME hackers use to have automatic reflection of their core libraries into Javascript. Yes, you read well, automatic! It is called gobject-introspection and gives you the super-powers of Javascript-ing most of the hardcore C libraries that powers GNOME, from multimedia, web browsing, accelerated 2D and 3D graphics, communications, UX, hardware interaction, and many more.

During the talk, a couple of examples will be discussed, some demos dropped, and we might hack the shell on-the-fly as well!

Javascript, the GNOME way Berlin, October 2nd, 2011 (follow the talk at http://10.109.2.56:8080)

A bit about of me Eduardo Lima Mitev <elima@igalia.com> Web apps developer, GNOME developer, eventdance, hildon-input-methods, libmeegotouch, filetea, ... Not a gnome-shell/G-I/GJS core hacker myself, just a messenger...

What is GNOME? http://bethesignal.org/blog/2011/03/12/thoughts-on-gnome/

GNOME is people http://www.flickr.com/photos/lucasrocha/3913631234/sizes/l/in/photostream/

A full-featured desktop environment

A collection of libraries and programs libgpg-error libgcrypt libxslt gnome-common intltool rarian gnome-doc-utils gtk-doc glib cairo gobject-introspection atk pango gdk-pixbuf shared-mime-info gtk+ vala dconf libgnome-keyring expat polkit gudev NetworkManager libproxy cantarell-fonts gtk+-2 gtk-engines librsvg gnome-themes-standard gsettings-desktop-schemas glib-networking libsoup gconf libgweather libgdata gstreamer liboil gst-plugins-base enchant WebKit p11-kit gnome-keyring libnotify librest json-glib gnome-online-accounts evolution- data-server colord libdaemon avahi libatasmart libunique gnome-disk-utility gvfs gnome-desktop gnome-menus iso-codes libxklavier libgnomekbd upower gnome-settings-daemon libgtop sound-theme-freedesktop accountsservice gnome-control-center gnome- bluetooth hicolor-icon-theme gnome-icon-theme gnome-icon-theme-symbolic gnome-icon-theme-extras PackageKit gnome- packagekit gnome-screensaver gnome-session pygobject cogl clutter libgee caribou telepathy-glib folks js185 gjs zenity metacity mutter telepathy-logger gnome-shell mousetweaks network-manager-applet telepathy-mission-control meta-gnome-core-shell gnome-backgrounds nautilus gnome-user-share vino itstool yelp-xsl yelp-tools gnome-user-docs meta-gnome-core-extras gmime poppler gtkhtml evolution libgsf tracker totem-pl-parser brasero libnice farsight2 telepathy-farsight clutter-gtk libchamplain empathy epiphany gnome-js-common seed libpeas eog evince gcalctool gnome-contacts libwnck mm-common libsigc++2 glibmm cairomm pangomm atkmm gtkmm gnome-system-monitor vte gnome-terminal gnome-utils gucharmap libdiscid libmusicbrainz clutter-gst gtksourceview sushi yelp meta-gnome-core-utilities gnome-panel notification-daemon dbus-python polkit-gnome ... ... ... ... all free software

GNOME 3 was released in April 2011 http://www.gnome.org/gnome-3/

GNOME 3 was released in April 2011 A major breakthrough in design HW acceleration for graphics Tons of cleaning up and restructuring of the stack The gnome-shell to be the default UX ... and GNOME met Javascript

The gnome-shell A modern, integrated user experience Acts as a compositing manager for the desktop Handles application launching, window switching, multiple desktops, and much more Interfaces GNOME libraries using Javascript as glue 29,497 lines of Javascript code (39,538 of C)

the gnome-shell https://live.gnome.org/GnomeShell/Technology

what is gobject-introspection? http://www.flyingdisk.com/badges.htm

what is gobject-introspection? A set of tools for extracting and accessing the metadata of a library's API in a convenient way for other programs to use it. library APIs must be "annotated" and designed to be "introspection friendly"

gobject-introspection goals Enable two level applications: C and <your favorite runtime>; Share binding infrastructure work; Other uses like API verification, improving documentation tools, etc

the big picture (with GJS)

the big picture (with Seed)

GIR file An XML description of a library API Can include documentation Example: ZLibCompressor class from GIO's GIR <class name="ZlibCompressor" c:symbol-prefix="zlib_compressor" c:type="GZlibCompressor" parent="GObject.Object" glib:type-name="GZlibCompressor" glib:get-type="g_zlib_compressor_get_type" glib:type-struct="ZlibCompressorClass"> <doc xml:whitespace="preserve">Zlib decompression</doc> <implements name="Converter"/> <constructor name="new" c:identifier="g_zlib_compressor_new" version="2.24"> <doc xml:whitespace="preserve">Creates a new #GZlibCompressor.</doc> <return-value transfer-ownership="full"> <doc xml:whitespace="preserve">a new #GZlibCompressor</doc>

Typelib file A binary representation of the GIR file for faster access during run-time.

GIRepository: API for retrieving library info from a typelib file http://moodleman.moodle.com.au/archives/202

libffi: fantasy fiction foreign function interface http://moodleman.moodle.com.au/archives/202

Annotations Go inline in the code (normally in the .c files) Complement the API description with semantic information Normally "guessed" correctly by the scanner Documented at https://live.gnome.org/GObjectIntrospection/Annotations

Annotations example (I)

Annotations example (II)

Javascript, at last!

Two engines: GJS and Seed

GJS vs. Seed GJS wraps Mozilla's Spidermonkey engine while Seed wraps Apple's JavascriptCore GJS supports language features from ES-Harmony (let, const, etc), Seed doesn't (as of now) GJS is more mature, it powers gnome-shell at the moment Other minor differences (i.e module extensions, etc) both have a fairly good G-I support

Oh wait! what about node-gir?

node-gir G-I support for Node early stage of development written by Tim Caswell code at https://github.com/creationix/node-gir Why not use Seed or GJS? "Because they are nice, but not what I'm looking for. Node is really popular and it would be nice to be able to use it for desktop tools and applications.", Tim Caswell

Writing Javascript in GJS/Seed

Show time!

Importing modules No 'require', sorry The 'imports' keyword Importing is an assignment, not a function call The full module's global scope is imported 'imports.searchPath' similar to 'require.paths' Only synchronous

Importing a Javascript module // this will import file 'path/to/my/module.js' var MyModule = imports.path.to.my.module; // this will import 'lib/Http.js' var Http = imports.lib.Http; // using 'const' here is nice but only works in GJS :) const Promise = imports.lib.Promise;

Importing a module from the G-I repository // this will import GLib library namespace var GLib = imports.gi.GLib; // this will import GTK+ library namespace // for API version 3.0 var Gtk = imports.gi.Gtk-3.0; // in recent versions of GJS you can do var Gtk = imports.gi.Gtk = 3.0;

Importing modules There are also native Javascript modules for more convenient APIs, i.e: mainloop, dbus, lang, signals.

Importing a native JS module // built-in JS modules are always accessible // from the root importer var Mainloop = imports.mainloop; var DBus = imports.dbus;

Using G-I APIs There are "well defined" rules for mapping the C symbols to their corresponding Javascript syntax

Using G-I APIs: Functions Library functions are mapped to Namespace.function: g_timeout_add(...) becomes GLib.timeout_add(...)

Using G-I APIs: GObject methods GObject methods are mapped to Namespace.Class.method: gtk_button_new_with_label(...) becomes Gtk.Button.new_with_label(...)

Using G-I APIs: Enums Enums are mapped to Namespace.EnumName.VALUE: GST_STATE_PLAYING becomes Gst.State.PLAYING, CLUTTER_STAGE_STATE_FULLSCREEN becomes Clutter.StageState.FULLSCREEN

Using G-I APIs: GObject properties GObject properties are mapped to normal Javascript Object members replacing '-' by '_': Property 'use-markup' of a GtkLabel becomes obj.use_markup

Using G-I APIs: GObject signals GJS obj.connect(signalName, callback) method is used to connect to GObject signals: obj.connect('destroy', callback); Seed: A bit different: obj.signal["signal name"].connect(callback) obj.signal['destroy'].connect(callback);

What about documentation? http://cdblog.centraldesktop.com/2010/05/is_your_technical_documentatio/

Documentation No official documentation for Javascript bindings yet Unofficial documentation at http://www.roojs.org/index.php/projects/gnome/introspection-docs.html A hot topic right now

What about development tools? http://blog.doomby.com/blog,7-of-the-best-free-website-development-tools,311404.html

Development tools No specific developer tools for Javascript at the moment Still too early: remains unclear what the needs will be

GNOME Javascript and CommonJS? There is certain interest in the GNOME community, but Not all CommonJS specs could make sense More discussion and bridging is needed node-gir? gjs-commonjs?

gjs-commonjs Wraps GJS to add CommonJS APIs Just an experiment, not the way to go Code at https://gitorious.org/gjs-commonjs (LGPL) Only Modules 1.1 and Promises/D (partially) at the moment

Current issues and challenges To complete introspection support in GNOME libraries To complete introspection support in GJS/Seed To have official documentation To make GJS and Seed code fully compatible To align with CommonJS for what makes sense

Final thoughts An elegant and efficient combination of low-level and high-level languages JS opened to a platform with 10+ years of evolution Very convenient for fast prototyping and gluing Expands the frontiers of JS in the desktop

An awesome stack! your Javascript programs GJS (Spidermonkey) Seed (JSC) node-gir (V8) ... gobject introspection Core GIO GLib GObject User interface GTK+ Cairo Clutter ATK Pango Webkit Multimedia gstreamer Canberra Pulseaudio Communication Telepathy Avahi GUPnP Data storage EDS GDA Tracker Utilities Champlain Enchant Poppler GeoClue Desktop integration PackageKit libnotify seahorse System integration upower udisks policykit

Thank you! Questions?

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

Javascript, the GNOME way (JSConf EU 2011) - YouTube

Slides at http://www.slideshare.net/igalia/edua.... GNOME, the free desktop environment, has embraced Javascript. Starting from version 3.0 ...
Read more

[JSConfEU 2011] Eduardo Lima Mitev: Javascript, the GNOME way

This talk is from 2011 jsconf.eu. For reuse of this video under a more permissive license please get in touch with us. The speakers retain the ...
Read more

JSConf - Conferences for the JavaScript community.

JSConf ™ Conferences for the JavaScript community. JSConf US. JSConf EU. JSConf AU. JSConf AR. ... JSConf does not focus on what is popular or cool now, ...
Read more

a schemer at jsconf.eu -- wingolog

I am just back from JSConf.eu, ... Still, though way to raise the bar, JSConf.eu! ... my Igalia colleague Eduardo Lima's talk on JavaScript in GNOME was ...
Read more

Going to JSConf.eu 2011 - Bless the uncertainty » Blog ...

Going to JSConf.eu 2011 ... Javascript, the GNOME way” in which I will discuss the relationship between GNOME 3 and Javascript, the technologies behind ...
Read more

JSConf EU 2015

JSConf EU, the labour-of-love ... turned out this way and we hope we can bring JSConf to ... at JSConf EU. We are inviting the JavaScript community to ...
Read more

JSConf.eu Video Roundup | Badass JavaScript

JSConf.eu Video Roundup The videos from JSConf.eu have started to come out, and they are some really fantastic talks. If you missed the actual event a few ...
Read more

jsconf.eu 2011 | qmx::weblog

jsconf.eu 2011. posted by qmx on 17 ... (at least way cleaner than Brazil’s). ... This guys rocked the boat explaining why it’s so hard to optimize ...
Read more

Bless the uncertainty » 2011 » September - Planet Igalia

Going to JSConf.eu 2011. ... I will be giving a talk titled “Javascript, the GNOME way” in which I will discuss the relationship between GNOME 3 and ...
Read more