From 43449ae7cbf56aeed6bcf7f861bb1532864d700c Mon Sep 17 00:00:00 2001 From: Morgan Date: Sun, 26 Oct 2025 04:49:36 +0900 Subject: [PATCH] Added custom polling interval just for `wattd`... --- .../extension.js | 13 +++++++++--- .../prefs.js | 20 +++++++++++++++++- ...gnome.shell.extensions.sensors.gschema.xml | 6 ++++++ .../wattdUtil.js | 21 ++++++++++++++++++- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/freon@UshakovVasilii_Github.yahoo.com/extension.js b/freon@UshakovVasilii_Github.yahoo.com/extension.js index 25d48ef..4fd0525 100644 --- a/freon@UshakovVasilii_Github.yahoo.com/extension.js +++ b/freon@UshakovVasilii_Github.yahoo.com/extension.js @@ -129,6 +129,7 @@ class FreonMenuButton extends PanelMenu.Button { this._addSettingChangedSignal('hot-sensors', this._querySensors.bind(this)); this._addSettingChangedSignal('update-time', this._updateTimeChanged.bind(this)); + this._addSettingChangedSignal('wattd-update-time', this._wattdUpdateTimeChanged.bind(this)); this._addSettingChangedSignal('position-in-panel', this._positionInPanelChanged.bind(this)); this._addSettingChangedSignal('panel-box-index', this._positionInPanelChanged.bind(this)); this._addSettingChangedSignal('show-icon-on-panel', this._showIconOnPanelChanged.bind(this)); @@ -369,7 +370,7 @@ class FreonMenuButton extends PanelMenu.Button { _initWattdUtility() { if (this._settings.get_boolean('use-generic-wattd')) - this._utils.wattd = new WattdUtil(); + this._utils.wattd = new WattdUtil(this._settings.get_int('wattd-update-time')); } _destroyWattdUtility() { @@ -386,6 +387,12 @@ class FreonMenuButton extends PanelMenu.Button { this._updateUI(true); } + _wattdUpdateTimeChanged() { + if (this._utils.wattd) + this._utils.wattd.interval = this._settings.get_int('wattd-update-time'); + this._querySensors(); + } + _initNvidiaUtility() { if (this._settings.get_boolean('use-gpu-nvidia')) this._utils.nvidia = new NvidiaUtil(); @@ -837,8 +844,8 @@ class FreonMenuButton extends PanelMenu.Button { icon: _icon, type: 'power', label: power.label, - value: _("%s%.2f%s").format(((power.power >= 0) ? '+' : ''), - power.power, unit)}); + value: _("%.2f%s").format(power.power, unit) + }); } this._fixNames(sensors); diff --git a/freon@UshakovVasilii_Github.yahoo.com/prefs.js b/freon@UshakovVasilii_Github.yahoo.com/prefs.js index 1f6adda..ff34079 100644 --- a/freon@UshakovVasilii_Github.yahoo.com/prefs.js +++ b/freon@UshakovVasilii_Github.yahoo.com/prefs.js @@ -112,7 +112,25 @@ export default class FreonPreferences extends ExtensionPreferences { group.add(this._addSwitch("lm-sensors", "use-generic-lmsensors", "Read sensors from lm-sensors")); group.add(this._addSwitch("liquidctl", "use-generic-liquidctl", "Read sensors from liquidctl (v1.7.0+)")); - group.add(this._addSwitch("wattd", "use-generic-wattd", "Read power data from wattd")); + const wattdSwitch = this._addSwitch("wattd", "use-generic-wattd", "Read power data from wattd"); + group.add(wattdSwitch); + + const wattdInterval = new Adw.SpinRow({ + title: _('Wattd Polling Interval'), + subtitle: _('Seconds between wattd updates'), + adjustment: new Gtk.Adjustment({ + lower: 1, + upper: 300, + value: this._settings.get_int('wattd-update-time'), + step_increment: 1, + }), + }); + this._settings.bind('wattd-update-time', wattdInterval, 'value', Gio.SettingsBindFlags.DEFAULT); + wattdInterval.sensitive = this._settings.get_boolean('use-generic-wattd'); + this._settings.connect('changed::use-generic-wattd', () => { + wattdInterval.sensitive = this._settings.get_boolean('use-generic-wattd'); + }); + group.add(wattdInterval); const freeimpi = new Adw.ComboRow({ title: _('FreeIMPI'), diff --git a/freon@UshakovVasilii_Github.yahoo.com/schemas/org.gnome.shell.extensions.sensors.gschema.xml b/freon@UshakovVasilii_Github.yahoo.com/schemas/org.gnome.shell.extensions.sensors.gschema.xml index 7e30d68..d15166f 100644 --- a/freon@UshakovVasilii_Github.yahoo.com/schemas/org.gnome.shell.extensions.sensors.gschema.xml +++ b/freon@UshakovVasilii_Github.yahoo.com/schemas/org.gnome.shell.extensions.sensors.gschema.xml @@ -111,6 +111,12 @@ Read power sensors exposed by wattd + + 5 + Seconds before wattd update + Seconds between wattd power refreshes + + false Read GPU sensors from NVIDIA driver diff --git a/freon@UshakovVasilii_Github.yahoo.com/wattdUtil.js b/freon@UshakovVasilii_Github.yahoo.com/wattdUtil.js index b3a0de6..fabf759 100644 --- a/freon@UshakovVasilii_Github.yahoo.com/wattdUtil.js +++ b/freon@UshakovVasilii_Github.yahoo.com/wattdUtil.js @@ -3,11 +3,14 @@ import GLib from 'gi://GLib'; export default class WattdUtil { - constructor() { + constructor(intervalSeconds = 5) { this._powerDir = '/run/power'; this._readings = []; this._updated = false; this._available = GLib.file_test(this._powerDir, GLib.FileTest.IS_DIR); + this._intervalUsec = 0; + this._lastUpdateUsec = 0; + this.interval = intervalSeconds; } get available() { @@ -23,6 +26,14 @@ export default class WattdUtil { } execute(callback) { + const nowUsec = GLib.get_monotonic_time(); + const remaining = this._intervalUsec - (nowUsec - this._lastUpdateUsec); + if (this._intervalUsec > 0 && this._lastUpdateUsec !== 0 && remaining > 0) { + if (callback) + callback(); + return; + } + this._updated = false; this._readings = []; @@ -76,6 +87,7 @@ export default class WattdUtil { this._available = false; this._readings = []; } finally { + this._lastUpdateUsec = nowUsec; this._updated = true; if (callback) callback(); @@ -88,6 +100,13 @@ export default class WattdUtil { destroy() { this._readings = []; + this._lastUpdateUsec = 0; + } + + set interval(seconds) { + const clamped = Math.max(1, seconds | 0); + this._intervalUsec = clamped * 1000000; + this._lastUpdateUsec = 0; } _formatLabel(name) {