GNOME Shell Extension Install possible without Restart?
Asked Answered
C

1

9

I have written a small GNOME Shell extension, that I want to distribute to some collegues.

For this I created a RPM. After the installation a restart of GNOME-Shell is needed to make the extension visible, so it can be enabled. Either by using <ALT-F2> followed by r when using X11 or log out and in when using Wayland.

Only after this restart the extension is visible in GNOME-Tweaks or can be activated using gnome-extensions enable ....

I was told that there might be a way to make the extension known to GNOME-Shell without restart. I searched around, but didn't find anything.

So: Can a GNOME-Shell extension be installed in a way that no restart is needed before it can be activated?

Environment is GNOME-Shell 3.34 & 3.36 on Fedora 31 & 32.

Cafard answered 8/6, 2020 at 15:28 Comment(1)
This is a good question, but maybe a better fit for Super User, or discourse.gnome.org?Evers
T
2

This will enable the extension as if it was coming from ego. Replace global.userdatadir with global.datadir and PER_USER with SYSTEM if the extension is in /usr/share/gnome-shell/extensions/.

const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;

const ExtensionUtils = imports.misc.extensionUtils;
const Main = imports.ui.main;

// Here, the directory must be in ~/.local/share/gnome-shell/extensions.
function installFromLocal(uuid) {
    let dir = Gio.File.new_for_path(GLib.build_filenamev([global.userdatadir, 'extensions', uuid]));
    let manager = Main.extensionManager;
    
    try {
        let extension = manager.createExtensionObject(uuid, dir, ExtensionUtils.ExtensionType.PER_USER);
        manager.loadExtension(extension);
        if (!manager.enableExtension(uuid))
            throw new Error('Cannot add %s to enabled extensions gsettings key'.format(uuid));
    } catch (e) {
        let extension = Main.extensionManager.lookup(uuid);
        if (extension)
            Main.extensionManager.unloadExtension(extension);
        throw new Error('Error while installing %s: %s (%s)'.format(uuid, 'LoadExtensionError', e));
    }
}
Tight answered 8/10, 2020 at 20:39 Comment(3)
Looks interesting, but how would I execute this during my RPM install?Cafard
I think it is possible to run the script through the GNOME Shell DBus service. But I don't know how to call DBus during RPM install.Tight
This worked for me after running it inside looking glass debugging util. It doesn't work if I run it with the gjs command. It will probably work with sending the JS code through gdbus callZinnia

© 2022 - 2024 — McMap. All rights reserved.