summaryrefslogtreecommitdiff
path: root/battery-widget/battery.lua
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@users.noreply.github.com>2021-04-26 15:46:35 -0400
committerGitHub <noreply@github.com>2021-04-26 15:46:35 -0400
commit864b224492442a26503c214c1ae5c0fbdc3b15d2 (patch)
tree3268ea2a20f90c5b8328ba40db271812699229aa /battery-widget/battery.lua
parent9d9f435f21690c36dc7573abdcdcfaf4a0e4517e (diff)
parent700b4e1f55563ed8d6cc4aed084fe454e67f9534 (diff)
Merge pull request #257 from bssb/master
prevent battery widget from crashing by ignoring null capacity field of Logitech mice
Diffstat (limited to 'battery-widget/battery.lua')
-rw-r--r--battery-widget/battery.lua12
1 files changed, 7 insertions, 5 deletions
diff --git a/battery-widget/battery.lua b/battery-widget/battery.lua
index d406a50..0422fcc 100644
--- a/battery-widget/battery.lua
+++ b/battery-widget/battery.lua
@@ -142,12 +142,14 @@ local function worker(user_args)
local charge = 0
local status
for i, batt in ipairs(battery_info) do
- if batt.charge >= charge then
- status = batt.status -- use most charged battery status
- -- this is arbitrary, and maybe another metric should be used
- end
+ if capacities[i] ~= nil then
+ if batt.charge >= charge then
+ status = batt.status -- use most charged battery status
+ -- this is arbitrary, and maybe another metric should be used
+ end
- charge = charge + batt.charge * capacities[i]
+ charge = charge + batt.charge * capacities[i]
+ end
end
charge = charge / capacity