Skip to content
Browse files

Bugfixing

-first element of the returned array of acpi_down_test has to be set to
 be set to true or false
-misspelling in system-call to zenity in on_low_discharge. Forgot to set
 the closing '
-using a flag-variable in the loop to determine if the warning-window
 was shown already. Its resetet if power-supply is plugged
  • Loading branch information...
1 parent ab7b137 commit 77c3516374bc98ea442584d0ee6092b65eb42cce chaosprinz committed Apr 11, 2012
Showing with 7 additions and 3 deletions.
  1. +7 −3 auto_power.rb
View
10 auto_power.rb
@@ -15,15 +15,15 @@
# -the second tells the charging-state in percent
def acpi_down_test
acpi = `acpi`
- [acpi.match(/Discharging/),acpi.match(/[\d]+%/).to_s.gsub('%','').to_i]
+ [acpi.match(/Discharging/).nil? ? false : true,acpi.match(/[\d]+%/).to_s.gsub('%','').to_i]
end
#=on_low_discharge
#callback for discharging low-battery-event
#@@return [TrueClass] makes a syscall, which uses zenity to throw a
# window with a warning-message.
def on_low_discharge
- fork {system " zenity --info --text 'akku ist bei #{acpi_down_test[1]}% Leistung. Das System wird demnächst heruntergefahren."}
+ fork {system "zenity --info --text 'akku ist bei #{acpi_down_test[1]}% Leistung. Das System wird demnächst heruntergefahren.'"}
end
#=on_critic_discharge
@@ -37,14 +37,18 @@ def on_critic_discharge
#endless loop whih uses acpi_down_test to get the time to run, and uses the correct
#callback-methods
def acpi_test_loop
+ message_shown = false
loop do
charge,offstate = acpi_down_test[1],acpi_down_test[0]
sleep_time = charge> @min_battery_work ? @test_time : @critic_time
sleep sleep_time
- if offstate && charge<= @min_battery_work
+ if offstate && charge <= @min_battery_work && charge >= @min_battery_critic && !message_shown
on_low_discharge
+ message_shown = true
elsif offstate && charge <= @min_battery_critic
on_critic_discharge
+ elsif !offstate && message_shown
+ message_shown = false
end
end
end

0 comments on commit 77c3516

Please sign in to comment.
Something went wrong with that request. Please try again.