无需重新启动即可安装 GNOME Shell 扩展?

Ral*_*alf 5 gnome-shell gnome-shell-extensions gjs

我写了一个小的 GNOME Shell 扩展,我想分发给一些同事。

为此,我创建了一个 RPM。安装后需要重新启动 GNOME-Shell 才能使扩展可见,因此可以启用它。使用 X11 时使用<ALT-F2>后跟r或使用 Wayland 时注销并登录。

只有在重新启动后,扩展才在 GNOME-Tweaks 中可见,或者可以使用gnome-extensions enable ....

有人告诉我,可能有一种方法可以让 GNOME-Shell 知道该扩展程序而无需重新启动。我四处寻找,但没有找到任何东西。

那么:GNOME-Shell 扩展是否可以以无需重新启动即可激活的方式安装?

Fedora 31 和 32 上的环境是 GNOME-Shell 3.34 和 3.36。

aba*_*kkk 2

这将启用扩展,就好像它来自自我一样。如果扩展名是 . 则替换为global.userdatadir和global.datadirwith 。PER_USERSYSTEM/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));
    }
}
Run Code Online (Sandbox Code Playgroud)