@fmuellner thank you for the reply. It seems to work. Sorry for my late reply, late is due to I was trying all the ways how to figure out monkey-patch. I tried online how to do monkey-patching but those posts seems bit old like 2011, 2015. I tried the code like below
import { Extension, InjectionManager } from 'resource:///org/gnome/shell/extensions/extension.js';
import * as UnlockDialog from 'resource:///org/gnome/shell/ui/unlockDialog.js';
import ModifiedClock from './ModifiedClock.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import Shell from 'gi://Shell';
export default class CustomizeClockOnLockScreenExtension extends Extension {
enable() {
this._injectionManager = new InjectionManager();
this._injectionManager.overrideMethod(UnlockDialog.UnlockDialog.prototype, '_init',
originalMethod => {
return function (...args) {
originalMethod.call(this, ...args);
// monkey-patch 'this._clock'
let oldFn = this._clock._updateHint;
this._clock._updateHint = () => {
this._clock._hint.text = 'PRATAP KUMAR'
Main.notify(JSON.stringify(this._clock._hint.text));
}
return oldFn.apply(this, ...args);
}
})
}
disable() {
this._injectionManager.clear();
this._injectionManager = null;
}
}
And another code like below
import { Extension, InjectionManager } from 'resource:///org/gnome/shell/extensions/extension.js';
import * as UnlockDialog from 'resource:///org/gnome/shell/ui/unlockDialog.js';
import ModifiedClock from './ModifiedClock.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import Shell from 'gi://Shell';
export default class CustomizeClockOnLockScreenExtension extends Extension {
enable() {
this._injectionManager = new InjectionManager();
this._injectionManager.overrideMethod(UnlockDialog.UnlockDialog.prototype, '_init',
originalMethod => {
return function (...args) {
originalMethod.call(this, ...args);
this._clock = new ModifiedClock;
}
})
}
disable() {
this._injectionManager.clear();
this._injectionManager = null;
}
}
// ModifiedClock.js
import St from 'gi://St';
import GObject from 'gi://GObject';
import GnomeDesktop from 'gi://GnomeDesktop';
import Clutter from 'gi://Clutter';
import Shell from 'gi://Shell';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import { formatDateWithCFormatString } from 'resource:///org/gnome/shell/misc/dateUtils.js';
const ModifiedClock = GObject.registerClass(
class ModifiedClock extends St.BoxLayout {
_init() {
super._init({ style_class: 'unlock-dialog-clock', vertical: true });
this._time = new St.Label({
style_class: 'unlock-dialog-clock-time',
x_align: Clutter.ActorAlign.CENTER,
});
this._date = new St.Label({
style_class: 'unlock-dialog-clock-date',
x_align: Clutter.ActorAlign.CENTER,
});
this._hint = new St.Label({
style_class: 'unlock-dialog-clock-hint',
x_align: Clutter.ActorAlign.CENTER,
opacity: 0,
});
this.add_child(this._time);
this.add_child(this._date);
this.add_child(this._hint);
this._wallClock = new GnomeDesktop.WallClock({ time_only: true });
this._wallClock.connect('notify::clock', this._updateClock.bind(this));
this._seat = Clutter.get_default_backend().get_default_seat();
this._seat.connectObject('notify::touch-mode',
this._updateHint.bind(this), this);
this._monitorManager = global.backend.get_monitor_manager();
this._monitorManager.connectObject('power-save-mode-changed',
() => (this._hint.opacity = 0), this);
this._idleMonitor = global.backend.get_core_idle_monitor();
this._idleWatchId = this._idleMonitor.add_idle_watch(4 * 1000, () => {
this._hint.ease({
opacity: 255,
duration: 300,
});
});
this._updateClock();
this._updateHint();
}
_updateClock() {
this._time.text = this._wallClock.clock;
let date = new Date();
let dateFormat = Shell.util_translate_time_string('%A %B %-d');
this._date.text = formatDateWithCFormatString(date, dateFormat);
}
_updateHint() {
this._hint.text = this._seat.touch_mode
? 'Swipe up to unlock'
: 'Click or press a key to unlock'
}
_onDestroy() {
this._wallClock.run_dispose();
this._idleMonitor.remove_watch(this._idleWatchId);
}
}
)
export default ModifiedClock;
I got stuck on how to implement a monkey-patch in originalMethod
function.
can you please guide me on this by referencing some examples or documentation please.
Thanks