Skip to content

Instantly share code, notes, and snippets.

Defining Interfaces

Custom interfaces can be defined in GJS, although this is rarely done

Interfaces are defined in GJS by inheriting from GObject.Interface and providing the class definition property Requires. The general rules for interfaces defined in GJS are:

const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const ifaceXml = `
<node>
<interface name="org.gnome.SettingsDaemon.Smartcard.Token">
<property name="Name" type="s" access="read"/>
<property name="Driver" type="o" access="read"/>
<property name="IsInserted" type="b" access="read"/>

GJS & SpiderMonkey Garbage Collector Heaps

Generally speaking, SpiderMonkey implements a mark-and-sweep garbage collector, although it employs a number of strategies including generational collection (with nursery and tenured regions), incremental collection, arena compacting and others.

This a brief overview of the structure of SpiderMonkey garbage collector heaps with some additional notes on GJS particulars. This isn't an exhaustive article on garbage collection or SpiderMonkey internals, only a reasonably thorough

@andyholmes
andyholmes / gjs-timeout-and-interval.js
Created January 13, 2019 06:09
Simple ports of setTimeout and setInterval in GJS
#!/usr/bin/env gjs
const GLib = imports.gi.GLib;
/**
* https://developer.mozilla.org/docs/Web/API/WindowOrWorkerGlobalScope/setInterval
* https://developer.mozilla.org/docs/Web/API/WindowOrWorkerGlobalScope/clearInterval
*/
window.setInterval = function(func, delay, ...args) {
@andyholmes
andyholmes / gravatar-gicon.js
Created December 11, 2018 02:14
Gravatar GIcon in GJS
#!/usr/bin/env gjs
// Make sure we get the right Gtk
imports.gi.versions.Gtk = "3.0";
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
'use strict';
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
async function mount() {
try {
// This comes from a 'kdeconnect.sftp' packet
let file = Gio.File.new_for_uri('sftp://192.168.1.68:1748//storage/emulated/0');
@andyholmes
andyholmes / device-channel.js
Created September 18, 2017 18:07
KDEConnect Device Channel in GJS
"use strict";
// Imports
const Lang = imports.lang;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;