28
28
local acpi_is_on_ac_power = function (adapter )
29
29
local f = io.open (' /sys/class/power_supply/' .. adapter .. ' /online' )
30
30
if f == nil then return false end
31
- return string.find (f :read (), ' 1' )
31
+ local o = f :read ()
32
+ f :close ()
33
+ return string.find (o , ' 1' )
32
34
end
33
35
34
36
local acpi_battery_is_present = function (battery )
35
37
local f = io.open (' /sys/class/power_supply/' .. battery .. ' /present' )
36
38
if f == nil then return false end
37
- return string.find (f :read (), ' 1' )
39
+ local o = f :read ()
40
+ f :close ()
41
+ return string.find (o , ' 1' )
38
42
end
39
43
40
44
local acpi_battery_is_charging = function (battery )
41
45
local f = io.open (' /sys/class/power_supply/' .. battery .. ' /status' )
42
46
if f == nil then return false end
43
- return string.find (f :read (), ' Charging' )
47
+ local o = f :read ()
48
+ f :close ()
49
+ return string.find (o , ' Charging' )
44
50
end
45
51
46
52
local acpi_battery_percent = function (battery )
@@ -49,7 +55,11 @@ local acpi_battery_percent = function (battery)
49
55
local full = io.open (' /sys/class/power_supply/' .. battery .. ' /energy_full' ) or
50
56
io.open (' /sys/class/power_supply/' .. battery .. ' /charge_full' )
51
57
if (now == nil ) or (full == nil ) then return 0 end
52
- return tonumber (now :read ())/ tonumber (full :read ())
58
+ local out_n = now :read ()
59
+ now :close ()
60
+ local out_f = full :read ()
61
+ full :close ()
62
+ return tonumber (out_n )/ tonumber (out_f )
53
63
end
54
64
55
65
local battery_bolt_generate = function (width , height )
0 commit comments