如何为只有_init{}的gnome-shell写函数

问题描述

通过此链接https://wiki.gnome.org/Projects/GnomeShell/Extensions/StepByStepTutorial,如果我们搜索注入,则会注意到“原型”

但是我希望扩展/覆盖这一部分,在这种情况下,我无法提供用户原型,以上链接/指南中已提及。那么如何实现呢?

例如,我想用DEFAULT_BACKGROUND_COLOR覆盖clutter.Color.from_string('#00ff00')

let _systemBackground;

var SystemBackground = GObject.registerClass({
    Signals: { 'loaded': {} },},class SystemBackground extends Meta.BackgroundActor {
    _init() {
        if (_systemBackground == null) {
            _systemBackground = new Meta.Background({ Meta_display: global.display });
            _systemBackground.set_color(DEFAULT_BACKGROUND_COLOR);
        }

        super._init({
            Meta_display: global.display,monitor: 0,});
        this.content.background = _systemBackground;

        let id = GLib.idle_add(GLib.PRIORITY_DEFAULT,() => {
            this.emit('loaded');
            return GLib.soURCE_REMOVE;
        });
        GLib.source.set_name_by_id(id,'[gnome-shell] SystemBackground.loaded');
    }
});

OS Arch Linux,gnome-shell --version 3.38.1

编辑:

我的目标是能够忽略上述问题而更改DEFAULT_BACKGROUND_COLOR可用的解决方案。

解决方法

_init()和其他函数一样,可以用相同的方法在类的原型上覆盖:

const Background = imports.ui.background;

Background.SystemBackground.prototype._init = function() {
    // Chaining-up to the super-class
    super._init({
        meta_display: global.display,monitor: 0,});

    // Whatever custom code you want to exectute
};