Usually we don’t query fonts from fontconfig directly, but from higher-level APIs like Pango.
I don’t know GJS specifically, but here a small example in Python:
import gi
gi.require_version('Pango', '1.0')
gi.require_version('Gtk', '4.0')
from gi.repository import Pango, Gtk
# Here I create a random widget, but preferably use an existing one
# (the font families should be the same for all widgets)
widget = Gtk.Label()
context = widget.get_pango_context()
for family in context.list_families():
print(family.get_name())
for face in family.list_faces():
print("\t", face.describe().to_string())
You can import Pango in GJS the same way you import Gtk or GLib.
Just to test the original code in the link, I created a false directory structure to delete files recursively but getting error.
Unhandled promise rejection. To suppress this warning, add an error handler to your promise chain with .catch() or a try-catch block around your await expression. Stack trace of the failed promise:
_getFonts@file:///usr/local/share/gnome-shell/extensions/gdm-extension@pratap.fastmail.fm/gdmExtension.js:158:24
_subMenuFonts@file:///usr/local/share/gnome-shell/extensions/gdm-extension@pratap.fastmail.fm/gdmExtension.js:155:18
_init@file:///usr/local/share/gnome-shell/extensions/gdm-extension@pratap.fastmail.fm/gdmExtension.js:79:18