Set end session timer in seconds
Note: Binary files aren't shown on the web site. To see all files, please download the extension zipfile.
Version | Status |
---|---|
13 | Active |
12 | Inactive |
11 | Rejected |
10 | Rejected |
9 | Rejected |
8 | Active |
7 | Active |
6 | Rejected |
5 | Inactive |
4 | Inactive |
3 | Inactive |
2 | Inactive |
1 | Rejected |
What's the reason for not removing line 56?
I tried to remove it, GLib.source_remove() rite? you mean to remove `GLib.Source.set_name_by_id(this._timerId, '[gnome-shell] this._confirm');` this?
Yes, please remove this line: ```js GLib.Source.set_name_by_id(this._timerId, '[gnome-shell] this._confirm'); ```
Ok doing now sir. Thank You.
Hi @JustPerfection, I found a bug if `this._timerId` in the extensions override method `_startTimer` is changed to global. Reference resource file `endSessionDialog.js` When users cancel the endSession, the timer will continue and the next time users choose to endSession, it immediately ends. This is because the `cancel` button is tied up with `this._timerId`. Since it is an override function. Is it still required to clear this timeout? If yes, how can it be figured out? Thanking You
Is this extension only wants to change the `this._totalSecondsToStayOpen` in the original code?
If that's the case you can do this instead of rewriting the whole function again: ```js EndSessionDialog.prototype._startTimerOld = EndSessionDialog._startTimer; this._injectionManager.overrideMethod(EndSessionDialog.prototype, '_startTimer', () => { const settings = this.getSettings(); return function () { this._totalSecondsToStayOpen = settings.get_int('timeout'); this._startTimerOld(); }; } ); ``` then you can remove it on disable: ```js EndSessionDialog.prototype._startTimerOld = null; ```
Yes, That is the case. I have tried your suggestion in several ways. in the `_sync` method let `displayTime` is needed to be tweaked as well. This whole function needs to be rewritten. I came up with below. Please have a review. ```js enable() { this._injectionManager = new InjectionManager(); EndSessionDialog.prototype._timerId = null; // override _startTimer method this._injectionManager.overrideMethod(EndSessionDialog.prototype, '_startTimer', () => { const settings = this.getSettings(); return function () { this._totalSecondsToStayOpen = settings.get_int('timeout'); let startTime = GLib.get_monotonic_time(); this._secondsLeft = this._totalSecondsToStayOpen; ... ``` ```js disable() { // clear timeout if (EndSessionDialog.prototype._timerId) { GLib.Source.remove(EndSessionDialog.prototype._timerId); EndSessionDialog.prototype._timerId = null; } this._injectionManager.clear(); // clear override methods this._injectionManager = null; } ``` Thanking You
`prototype` doesn't get you the value and `EndSessionDialog.prototype._timerId` doesn't get you the value from the actual instance. The instance is here if you wanna do that: https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/main.js#L290
Sir, I came up with below. The main change is I used the arrow function instead of the regular function and thus the value of `this` is now the instance of the extension for the `_startTimer` method. And the `timerId` is removed at disable. I have tested the extension and is working without problems. ```js import GLib from 'gi://GLib'; import * as ModalDialog from 'resource:///org/gnome/shell/ui/modalDialog.js'; import * as Main from 'resource:///org/gnome/shell/ui/main.js'; import {EndSessionDialog} from 'resource:///org/gnome/shell/ui/endSessionDialog.js'; import {Extension, InjectionManager} from 'resource:///org/gnome/shell/extensions/extension.js'; import DialogContent from './DialogContent.js'; export default class EndSessionTimer extends Extension { enable() { this._injectionManager = new InjectionManager(); this._esd = Main.endSessionDialog; // override _startTimer method this._injectionManager.overrideMethod(EndSessionDialog.prototype, '_startTimer', () => { const settings = this.getSettings(); return () => { this._esd._totalSecondsToStayOpen = settings.get_int('timeout'); let startTime = GLib.get_monotonic_time(); this._esd._secondsLeft = this._esd._totalSecondsToStayOpen; this._esd._timerId = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, () => { let currentTime = GLib.get_monotonic_time(); let secondsElapsed = (currentTime - startTime) / 1000000; this._esd._secondsLeft = this._esd._totalSecondsToStayOpen - secondsElapsed; if (this._esd._secondsLeft > 0) { this._esd._sync(); return GLib.SOURCE_CONTINUE; } let dialogContent = DialogContent[this._esd._type]; let button = dialogContent.confirmButtons[dialogContent.confirmButtons.length - 1]; this._esd._confirm(button.signal).catch(logError); this._esd._timerId = 0; return GLib.SOURCE_REMOVE; }); }; } ); // override _sync method this._injectionManager.overrideMethod(EndSessionDialog.prototype, '_sync', () => { return function () { let open = this.state === ModalDialog.State.OPENING || this.state === ModalDialog.State.OPENED; if (!open) return; let dialogContent = DialogContent[this._type]; let subject = dialogContent.subject; if (dialogContent.subjectWithUpdates && this._checkBox.checked) subject = dialogContent.subjectWithUpdates; this._batteryWarning.visible = this._shouldShowLowBatteryWarning(dialogContent); let description; let displayTime = Math.ceil(this._secondsLeft); if (this._user.is_loaded) { let realName = this._user.get_real_name(); if (realName != null) { if (dialogContent.subjectWithUser) subject = dialogContent.subjectWithUser.format(realName); if (dialogContent.descriptionWithUser) description = dialogContent.descriptionWithUser(realName, displayTime); } } if (dialogContent.upgradeDescription) { const {name, version} = this._updateInfo.PreparedUpgrade; if (name != null && version != null) description = dialogContent.upgradeDescription(name, version); } if (!description) description = dialogContent.description(displayTime); this._messageDialogContent.title = subject; this._messageDialogContent.description = description; let hasApplications = this._applications.length > 0; let hasSessions = this._sessions.length > 0; this._applicationSection.visible = hasApplications; this._sessionSection.visible = hasSessions; }; } ); } disable() { // clear timeout if (this._esd._timerId) { GLib.Source.remove(this._esd._timerId); this._esd._timerId = null; } this._esd = null; this._injectionManager.clear(); // clear override methods this._injectionManager = null; } } ``` Thank you for your extended support.
Ok, please send the package.