import { Extension, InjectionManager } from 'resource:///org/gnome/shell/extensions/extension.js';
import {BaseIcon} from 'resource:///org/gnome/shell/ui/iconGrid.js';
import Shell from 'gi://Shell';
import Clutter from 'gi://Clutter';
import St from 'gi://St';
import * as Params from 'resource:///org/gnome/shell/misc/params.js';
export default class SizeChanger extends Extension {
constructor (metadata) {
super(metadata);
this._injectionManager = new InjectionManager();
}
enable () {
console.log("Hi runs: mousin");
this._injectionManager.overrideMethod(BaseIcon.prototype, '_init', () => {
return function (label, params) {
params = Params.parse(params, {
createIcon: null,
setSizeManually: false,
showLabel: true,
});
let styleClass = 'overview-icon';
if (params.showLabel)
styleClass += ' overview-icon-with-label';
this._box = new St.BoxLayout({
vertical: true,
x_expand: true,
y_expand: true,
});
this.set_child(this._box);
this.iconSize = 48;
this._iconBin = new St.Bin({x_align: Clutter.ActorAlign.CENTER});
this._box.add_child(this._iconBin);
if (params.showLabel) {
this.label = new St.Label({text: label});
this.label.clutter_text.set({
x_align: Clutter.ActorAlign.CENTER,
y_align: Clutter.ActorAlign.CENTER,
});
this._box.add_child(this.label);
} else {
this.label = null;
}
if (params.createIcon)
this.createIcon = params.createIcon;
this._setSizeManually = params.setSizeManually;
this.icon = null;
let cache = St.TextureCache.get_default();
cache.connectObject(
'icon-theme-changed', this._onIconThemeChanged.bind(this), this);
}
});
this._injectionManager.overrideMethod(BaseIcon.prototype, 'vfunc_style_changed', () => {
return function () {
let node = this.get_theme_node();
let size;
if (this._setSizeManually) {
size = this.iconSize;
} else {
const {scaleFactor} =
St.ThemeContext.get_for_stage(global.stage);
let [found, len] = node.lookup_length('icon-size', false);
size = found ? len / scaleFactor : 48;
}
if (this.iconSize === size && this._iconBin.child)
return;
this._createIconTexture(size);
}
});
console.log("runs here: mousin")
}
disable () {
this._injectionManager.clear();
}
}
I have this code, but i want to also manage super._init() calls in those methods. I don’t know how to do that because writing super._init() as if i was refering to the target classes’s parent, gives errors. Is there an alternate way of doing this. If a method has super.parentmethod() like calls in it, how do we use that functionality in the injection manager?
Without the super calls, it won’t work