How to open gnome-extensions preferences window from a gnome-extension on gnome-shell version 45

rite now my code is like below

I have gone through the porting guidelines for v45 from this link Port Extensions to GNOME Shell 45 | GNOME JavaScript but got stuck how to implement it.

any help is much appriciated.

here is the GObject

const ActivitiesButton = GObject.registerClass(
    class ActivitiesButton extends PanelMenu.Button {
        vfunc_event(event) {
            if (event.type() === Clutter.EventType.BUTTON_RELEASE && event.get_button() === 3 && this._boolean) {
                let appPath = '/usr/bin/gnome-extensions';
                if (GLib.file_test(appPath, GLib.FileTest.EXISTS)) {
                    MyExtension.openPreferences(); // need help on this please

here is the extension

export default class MyExtension extends Extension {
    enable() {
        this._settings = this.getSettings();

        let rightClick = this._settings.get_boolean('right-click');
        this._activitiesButton = new ActivitiesButton(rightClick);


        Main.panel.addToStatusArea('activities-icon-button', this._activitiesButton, 0, 'left');

If you don’t want to pass around the extension object, you can look it up like this:

const extension = Extension.lookupByURL(import.meta.url);

Thank you @fmuellner for your quick response, I tried it and it did not work. I tried to show what is the result of extension by Main.notify(JSON.stringify(extension)) and I got null


if you can help me, here is the code for gnome-shell v44 of the extension Review "Replace Activities Text" version 20 - GNOME Shell Extensions

That is expected.

Here is what’s going on:

  1. gnome-shell imports the extension.js file from your extension
  2. when loading the module, the result of lookupByURL() is assigned to a global variable (the return value is null because there is no such extension yet. The file is only being imported by gnome-shell at the moment)
  3. gnome-shell looks up the default import and instantiates it
  4. the new extension is added to the extensionManager (from now on, lookupByURL() will return the expected extension)
  5. when the extension should be enabled, gnome-shell calls the extension object’s enable() method

That is, don’t try to store the extension in a global variable. Either do the lookup locally (it’s cheap), do it in the ActivitiesButton constructor, or pass the extension object (this) as parameter in enable().

Unrelated, but what is the check for? I don’t see your prefs.js using it (and why would it?), so all the check does is artificially breaking your prefs when the tool is installed in a different location or not installed at all.

Thanks @fmuellner , I have put the lookup extension by url in ActivitiesButton’s constructor and it is working.
Also thanks for the info on check for the tool, I understood that and removed that check.

can you help me with one more thing please, if needs, I will raise a new topic. How to control the width of the extensions preferences window, rite now It is opening like a half the width what I wanted.

window width control

Below is some of the code from prefs.js file

export default class MyExtensionPreferences extends ExtensionPreferences {
    fillPreferencesWindow(window) {
        this._settings = this.getSettings();
        const page = new Adw.PreferencesPage();
        const group = new Adw.PreferencesGroup({
            title: 'Change Activities Text with Logo and Your Preferred Text',
            description: new Date().toLocaleString()

        this._textColorButton = new Gtk.ColorButton();
        this._iconColorButton = new Gtk.ColorButton();
        this.setButtonColor(this._iconColorButton, 'icon-color');
        this.setButtonColor(this._textColorButton, 'text-color');
        this._noTextButton = new Gtk.Button({ margin_start: 5 });

        this.widget = new Gtk.Box({
            orientation: Gtk.Orientation.VERTICAL,
            margin_top: 10,
            margin_bottom: 10,
            margin_start: 10,
            margin_end: 10,
            hexpand: true,


You can call window.set_default_size(...) on the window, or the default-width property individually.

However I would strongly recommend to take a good look at the design guidelines.

The window is extremely overloaded, and there is no alignment between widgets from different settings, which gives the whole thing a very chaotic feeling.

You should be able to do a lot better using the existing list row widgets in libadwaita, with probably less code.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.