7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/batalert.rb', line 7
def main
capacity = File.open('/sys/class/power_supply/BAT0/capacity', &:readline)
capacity = capacity.to_i
status = File.open('/sys/class/power_supply/BAT0/status', &:readline)
status = status.chomp
if capacity < 10 && status == 'Discharging'
notify = Libnotify.new(summary: "PUT ON CHARGING, YOUR BATTERY IS AT #{capacity}%.", timeout: 3, urgency: :critical)
notify.update
speech = ESpeak::Speech.new("put on charging, your battery is at #{capacity}%.")
speech.speak
end
if capacity > 90 && status == 'Charging'
notify = Libnotify.new(summary: "REMOVE CHARGING, YOUR BATTERY IS AT #{capacity}%.", timeout: 3, urgency: :critical)
notify.update
speech = ESpeak::Speech.new("remove charging, your battery is at #{capacity}%.")
speech.speak
end
end
|