How to work GNOME's Looking Glass?
Asked Answered
K

1

14

I want to step into extension development for Gnome Shell, but I can't seem to understand how I do a few tasks in Looking Glass lg to actually debug my stuff.

  1. When I type global.log("hi"); into LG, it throws me back r(...) = undefined. Why?
  2. When I want to debug an extensions that doesn't load, how do I do that?
    It would be nice to see why an extension can't be loaded.
    I tried Main.ExtensionSystem.loadExtension() but it returns undefined no matter if I give it the extension's name string or the extension's object.
  3. Where do I find documentation for classes, objects and member methods?
    (The LG inspector does not seem to be able to inspect functions.)

If I had these resources I could at least start to work on updating some extensions for newer Gnome versions. I would not ask these simple questions if they would be nicely explained somewhere but getting all the info seems really tough (I've googled for hours).

Koren answered 26/1, 2013 at 18:17 Comment(1)
Good point, did you make any progress on this?Easing
B
8

6 years after edit:
I recently got a notification about this post again (thanks for the upvote, I suppose) and would like to preface this answer with a note about the availability of the listed resources. It's still a decent place to start, and the logging info is still mostly accurate. That said, MathematicalCoffee's blog hasn't been updated since years before I posted this and the last generator run for the RooJS docs seems to have been in 2023, if the footer is to be believed. Although they do seem to have gjs covered by now, which is a nice step up!
As for the baznga devdocs, I've not seen them come online the few times I checked in the past years (which has been almost never) and doubt they're still up at this point. The user-built reference I linked reports the last repo update to have been in 2022, but the last commit was in 2017 and I see no responses or activity on any of the user's repos. All in all, this answer now serves as a brief "how to log" guide rather than being a useful resource. Sorry about that!

Considering I am no longer working on anything with GNOME and that I've personally switched over to KDE a couple years back, I will not be maintaining this answer. If someone else wants to, feel free to recycle (parts of) it for a community post to help beginning shell extension developers on their way. Knowing GNOME, their official docs aren't any better than they were back then, if they're even linked anywhere.


1: LookingGlass is basically a GJS console. It allows you to execute and test lines of GJS, grab and manipulate objects and use r(...) to use results in following commands. The reason you get r(...) = undefined is because log(String); does not return anything, thus the result is undefined.

2: Either log throughout init() and enable(), then check where it breaks and try to pinpoint the breaking line using log or commenting out lines of code (although the culprit is probably defined in the general logging, described in the section at the bottom).

3: There is no official documentation. They have some outdated tutorials for GNOME Shell 3.4 with a small difference explanation to 3.6, a few pages on the C(++) ends of the libraries you use (most of the functions, variables and constants use the same names though), but for any real info you'd need experience, digging through other GNOME and shell extension code or some unofficial sources. Unofficial sources aren't always up to date, however.

I recommend checking the official extensions website and go through whatever interesting extensions' source code you can get, as that is your best bet to learn anything.

Generally Debugging gnome can be done in several ways.

  • use the log() function and follow journalctl in a commandline, check either GNOME or JS, use journalctl -f | grep -i js (or use grep -i gnome). You will see some warnings no matter what, but most mention what extension they're from. This is nice and works on all distros implementing systemd
  • Or log a specific process that is a part of GNOME like journalctl /usr/bin/gnome-session -f -o cat, just beware that some distros and versions log to different files and old GNOME versions often log to whatever your display manager logs to.
  • use the official (albeit tricky) manner of logging: GNOME on debugging. I personally couldn't get this to work.
Behead answered 9/7, 2018 at 8:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.