Skip to content

purescript-gjs/purescript-gjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

purescript-gjs

GNOME JavaScript bindings for PureScript.

Use this library to write GJS programs.

Project using purescript-gjs:

Usage

Checkout the examples in the ./test/ directory.

Gio.Async

The library provides high level functions using the Aff type to escape callback hell. For example, to read a file, a raw gio usage looks like this:

import Gio.Raw.File as File
import GJS (log)

printFile :: String -> Effect Unit
printFile path = do
  file <- File.new_for_path path
  File.load_contents_async file Nothing $ \obj res -> do
    content <- File.load_contents_finish obj res
    log content

Instead, the higher level Gio.File module provides a convenient readFile function:

import Gio.File as File

printFile :: String -> Aff Unit
printFile path = do
  content <- File.readFile path
  liftEffect $ log content

The GJS does not provides a native setTimeout function which is required by Aff to handle errors. Use the Gio.Async.init function to install compatibility functions.

This blog post is a good read to learn more about Aff: Asynchronous PureScript.

For command line application, use GLib.MainLoop.withLoop, checkout the Test.Gio example for a parallel async demo.

For graphical application, checkout the Test.Gtk4 example for custom glib loop lifecycle.

Contribute

Contributions are most welcome.

The project needs help to complete the APIs bindings:

  • add missing binding manually, or checkout the work in progress codgen.
  • add higher level functions (e.g. in Gio.File or Gio.Subprocess) by following existing conventions (such as Data.Text.IO or SimpleCmd).

You will need a PureScript toolchain and the gnome developper tool.

Run test, for example:

$ make test
$ make test-gtk4

If you experience any difficulties, please don't hesistate to raise an issue.

References

Here are a collection of pointers to navigate the GNOME ecosystem.

GJS

GJS provides bindings to the GNOME ecosystem.

Use the gjs command instead of node

GObject

GObject is the base upon which most of the GNOME platform is built.

GLib

GLib is a general-purpose utility library.

Gio

GNOME input/output library:

DBus

D-Bus is a message bus for sending messages between various applications.

Cairo

Cairo is a 2D graphics library.

Gtk

GTK is a library for creating graphical user interfaces.

Clutter

Clutter is an free and open source software library for creating portable, dynamic, compelling and fast graphical user interfaces.

Clutter widgets are called Actors.

Changes

0.1

  • Initial release.