Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNOME Shell Extension Install possible without Restart?

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.

like image 787
Ralf Avatar asked Jun 08 '20 15:06

Ralf


People also ask

Can install Gnome Shell Extensions?

To install Gnome shell extensions from your browser, you will need a browser extension (add-on). Hit “Click here to install browser extension”. When the following prompt appears, click Continue to Installation. Then click Add.

Are Gnome Shell Extensions safe?

Are GNOME Shell Extensions safe? The code in a GNOME Shell extension becomes part of the core operating system. For this reason, the potential exists for an extension to cause system misbehavior, crashes, or even to have malicious behavior like spying on the user or displaying unwanted advertisements.


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));
    }
}
like image 57
abakkk Avatar answered Oct 22 '22 04:10

abakkk