mirror of
https://github.com/morgan9e/gnome-shell-extension-freon
synced 2026-04-14 00:14:14 +09:00
Added custom polling interval just for wattd...
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -111,6 +111,12 @@
|
||||
<description>Read power sensors exposed by wattd</description>
|
||||
</key>
|
||||
|
||||
<key type="i" name="wattd-update-time">
|
||||
<default>5</default>
|
||||
<summary>Seconds before wattd update</summary>
|
||||
<description>Seconds between wattd power refreshes</description>
|
||||
</key>
|
||||
|
||||
<key type="b" name="use-gpu-nvidia">
|
||||
<default>false</default>
|
||||
<summary>Read GPU sensors from NVIDIA driver</summary>
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user