UnlockDialog.UnlockDialogClock.prototype is undefined

The following should mostly work:

import {Extension, InjectionManager} from 'resource:///org/gnome/shell/extensions/extension.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';

export default class CustomizeClockOnLockScreenExtension extends Extension {
    enable() {
        this._injectionManager = new InjectionManager();
        this._injectionManager.overrideMethod(Main.screenShield, '_ensureUnlockDialog',
            originalMethod => {
                return allowCancel => {
                    const ret = originalMethod.call(Main.screenShield, allowCancel);
                    this._maybeModifyClock();
                    return ret;
                };
            });
        this._maybeModifyClock();
    }

    disable() {
        this._injectionManager.clear();
        this._injectionManager = null;
    }

    _maybeModifyClock() {
        const clock = Main.screenShield._dialog?._clock;
        if (this._clockModified || !clock)
            return;

        this._clockModified = true;
        this._injectionManager.overrideMethod(Object.getPrototypeOf(clock), '_updateHint',
            () => {
                return function () {
                    this._hint.text = 'Hello World!!!';
                };
            });
        clock._updateHint();
    }
}

That should cover both the case where the dialog is created before the extension is enabled (explicit lock) and where the extension is enabled first (automatic lock on idle).

It still has the issue pointed out by GdH: If the seat’s touch-mode changes, the original _updateHint() method will run (because it was bound before the extension replaced it).

Hi @fmuellner

I tried to understand your above code, it worked for ‘Hello World!!!’ text. As I have much planning for tweaking the content on lock screen, my trails were not working. So I have gone with the ModifiedClock.js file.

I would like to learn more from you in the future about what you have mentioned ‘leaking’, If I get some more knowledge , I will tweak my extensions in future.

Here is the extension that is uploaded for review from gnome developer
https://extensions.gnome.org/review/44291

Thanks

Hello @fmuellner, I tried to refactor the code to work only on unlock-dialog. I am in doubt on disable function and there is a internal disable switch with the prefs.js. I am not sure is that a rite way. In enable.js I am using the condition if (this._dialog && !disable) like below.

    enable() {
        this._settings = this.getSettings();
        this._dialog = Main.screenShield._dialog;
        const disable = this._settings.get_boolean('disable-extension');
        if (this._dialog && !disable) {
            this._dialog._stack.remove_child(this._dialog._clock);
            this._dialog._clock = new ModifiedClock(this._settings);
            this._dialog._clock.set_pivot_point(0.5, 0.5);
            this._dialog._stack.add_child(this._dialog._clock);
        }
    }

Can you help me on this please.

// metadata.json
{
  "name": "test",
  "description": "test",
  "uuid": "test",
  "settings-schema": "org.gnome.shell.extensions.lockscreen",
  "shell-version": [
    "45"
  ],
  "session-modes": [
    "unlock-dialog"
  ]
}
// extension.js
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';

import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import ModifiedClock from './ModifiedClock.js';

export default class CustomizeClockOnLockScreenExtension extends Extension {
    enable() {
        this._settings = this.getSettings();
        this._dialog = Main.screenShield._dialog;
        this._originalClock = this._dialog._clock;
        const disable = this._settings.get_boolean('disable-extension');
        if (this._dialog && !disable) {
            this._dialog._stack.remove_child(this._dialog._clock);
            this._dialog._clock = new ModifiedClock(this._settings);
            this._dialog._clock.set_pivot_point(0.5, 0.5);
            this._dialog._stack.add_child(this._dialog._clock);
        }
    }

    // unlock-dialog is used in session-modes because this extension purpose is
    // to tweak the clock on lock screen itself.
    disable() {
        this._dialog._stack.remove_child(this._dialog._clock)
        this._dialog._stack.add_child(this._originalClock);
        this._dialog._clock.destroy();
        this._dialog._clock = null;
        this._dialog = null;
        this._settings = null;
    }
}

This is the customized clock on lock screen. Extension seems to work properly with the prefs.

Preferences Window

Why?

Sorry for being blunt, but what is the use case for enabling the extension, and then configuring it to do nothing?

It is not. You are only reading the setting once (when the extension is enabled), so if the setting changes later, it won’t do anything.

You’d have to do something like

    enable() {
        this._settings = this.getSettings();
        this._settings.connectObject('changed::disable-extension',
            () => this._disabledChanged(), this);
        if (!this._settings.get_boolean('disable-extension')
            this._realEnable();
    }

    disable() {
        this._settings.disconnectObject(this);
        this._settings = null;

        this._realDisable();
    }

    _disabledChanged() {
        if (this._settings.get_boolean('disable-extension'))
            this._realDisable();
       else
            this._realEnable();
    }

But again, what’s the use case here? There already is a setting to enable or disable extensions, and the enable() and disable() methods are called accordingly. Why make things more complicated by duplicating the whole thing?

Also please try to be more sparse with personal mentions. Answering a question doesn’t turn a person into a personal assistant that is responsible for assisting with all future questions.

1 Like

Hi @fmuellner, I am sorry if I did wrong regarding your last message. I understand what you mean.

regarding disable switch in the preferences is because:
Since its using unlock-dialog session mode only, user cant enable or disable this extension at all.
If user wants to temporarily disable the extension there is no way. Only way is user has to remove the extension.

image

When I turn on this Disable this Extension switch, it is like disabling the extension, this is what I was trying.

Thanks for your above code,
I will try that.

That’s a bug in the Extensions app, and should be fixed.

gnome-extensions disable still works by the way.

Oh ok noted.

I tried to use gnome-extensions disable command line, it is working but it too have a bug may be linked to original bug. The bug I noticed is the command line cant work with Tab Completion. means user have to copy paste the uuid of the extension handy while running the command.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.