mirror of
https://github.com/elenapan/dotfiles.git
synced 2026-05-11 17:35:57 +08:00
Make battery daemon disable itself if no battery is found at startup
This commit is contained in:
parent
e26b51c609
commit
c133c6a7d7
1 changed files with 10 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue