1

from this link https://wiki.gnome.org/Projects/GnomeShell/Extensions/StepByStepTutorial if we search for inject, we notice "prototype"

But I am looking to extend/ overwrite this part, I cant user prototype in this case which is mentioned in above link/guide. So how to achieve this?

for example, I want to overwrite DEFAULT_BACKGROUND_COLOR with 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

PRATAP
  • 127
  • 3
  • 17
  • Why not just call `set_color()` with your desired color? PS, you don't have to ping me on questions, I already get emailed. – andy.holmes Oct 30 '20 at 08:37
  • I've answered your original question, but overriding a prototype function doesn't seem to be the problem you're trying to solve. I'd recommend opening a new question if you're having problems using that specific class. – andy.holmes Nov 21 '20 at 00:47

1 Answers1

1

_init() is a function like any other, and can be overridden on the prototype of a class the same way:

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
};
andy.holmes
  • 3,383
  • 17
  • 28
  • Sir Can you go through the comments below this answer. https://stackoverflow.com/questions/67784073/gjs-gnome-shell-exception-error-how-to-overcome-this-error/67799355?noredirect=1#comment119888397_67799355 – PRATAP Jun 04 '21 at 07:15
  • can you help me with this Question please https://unix.stackexchange.com/q/663538/383311 – PRATAP Aug 06 '21 at 05:40