Make battery daemon disable itself if no battery is found at startup

This commit is contained in:
elenapan 2020-08-15 23:09:59 +03:00
parent e26b51c609
commit c133c6a7d7

View file

@ -18,7 +18,11 @@ local charger_script = [[
-- First get battery file path
-- If there are multiple, only get the first one
-- TODO support multiple batteries
awful.spawn.easy_async_with_shell("find /sys/class/power_supply/BAT?/capacity | head -1", function (battery_file)
awful.spawn.easy_async_with_shell("sh -c 'out=\"$(find /sys/class/power_supply/BAT?/capacity)\" && (echo \"$out\" | head -1) || false' ", function (battery_file, _, __, exit_code)
-- No battery file found
if not (exit_code == 0) then
return
end
-- Periodically get battery info
awful.widget.watch("cat "..battery_file, update_interval, function(_, stdout)
awesome.emit_signal("evil::battery", tonumber(stdout))
@ -26,7 +30,11 @@ awful.spawn.easy_async_with_shell("find /sys/class/power_supply/BAT?/capacity |
end)
-- First get charger file path
awful.spawn.easy_async_with_shell("find /sys/class/power_supply/*/online | head -1", function (charger_file)
awful.spawn.easy_async_with_shell("sh -c 'out=\"$(find /sys/class/power_supply/*/online)\" && (echo \"$out\" | head -1) || false' ", function (charger_file, _, __, exit_code)
-- No charger file found
if not (exit_code == 0) then
return
end
-- Then initialize function that emits charger info
local emit_charger_info = function()
awful.spawn.easy_async_with_shell("cat "..charger_file, function (out)