In a gnome-extension, about disable function when only 'unlock-dialog' session-modes is used

I have recently created an extension on gnome-shell v45. Customize Clock on Lock Screen - GNOME Shell Extensions

I am not able to catch up how to work on disable function. Since the extension is using only ‘unlock-dialog’ session mode, the extension works only on lock-screen. I did several trail and errors on disable function like below

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;

        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._clock.destroy();
        // this._dialog._clock = null;
        // this._dialog = null;
        // Main.screenShield._dialog._stack.add_child(this._originalClock);
        this._settings = null;
    }
}

In my several trails with disable function empty, I found the extension is working very well rather than removing childs adding childs nulling destroying etc. Also when I disable this extension via command line with gnome-extensions disable seems everthing is fine.

So my question is, Can I ignore those removing childs, adding childs, nulling (except this._settings), destroying etc and leave the extensions disable function empty?

Thanks

No, if you don’t cleanup in disable() your extension will not pass review on extensions.gnome.org. It’s the basic expectation of all extensions.

EDIT: in you commented-out disable() function, you are not replacing the dialog at Main.screenShield._dialog. Maybe that was the problem?

In my trails, I found that there are no side effects if I leave the disable() function with empty other than nulling the settings, if I replace the things back, there is a small bug that is the time is shown for a fraction of second after entering the password on lockscreen. My main point is since this extension is using only on [unlock-dialog] session mode, there is no effect on [user-mode] even if we keep something on disable() function.

Well, the answer to your question is that you can not omit or skip disable() if you want to distribute your extension on extensions.gnome.org.

If you just want to use it on your own system, you can do whatever you want :slightly_smiling_face:

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