Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cool project, hopefully I can add to that with this new widget type.
Essentially, this new temp widget shows temperature data reported by the internal hardware temperature sensors. To do this, it uses gopsutil/host.
The temp widget is essentially a copy of the top widget, so it displays the current sensor value as a bar graph, difference being that the max value is configurable (default is 100°C). The only annoying thing is figuring out the identifiers for the sensors, but I tried to explain it at least for Linux systems in the README section for the widget.
When I tested the widget, I found one little inefficiency (bug?) with the update interval handling in combination with the top widget (and my new temp widget). The RequiresUpdate function checks if enough time has passed since the widget was last updated based on the widget's
lastUpdate
time. This one is only updated in the widget render function.The top (and temp) widgets both return early out of the
Update
function if the value to display hasn't changed, so therender
function is never called in that case (which meanslastUpdate
is never updated). In the nextupdateWidgets
cycle, the widget'sUpdate
function is called immediately again, as thelastUpdate
time is still far enough in the past.For the top widget that is not a big deal as the function calls for CPU and memory usage are pretty cheap. On the other hand, the collection of the temperature sensor data involves some file operations so you notice some CPU usage. It will not grind your machine to a halt, but hey, why waste those cycles if it can be avoided 😄
To fix that, the temp widget just updates the
lastUpdate
time when the early return condition is met. I thought about adding this line to the top widget as well, but I just wanted to check first if I should do this in the same PR or if you prefer a separate issue/PR for that.I also noticed that the gopsutil module was quite outdated. Dependabot probably didn't update it because the module path changed to gopsutil/v3, so I updated that as well. The top widget still works the same with that new version.
Some things I considered but left open for the moment: