GNOME Shell Extension Install possible without Restart?

Viewed 736

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.

1 Answers

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));
    }
}
Related