utkarsh2102 / batalert

Battery notifications/alerts for your favorite WM! 💯
MIT License
8 stars 2 forks source link

Bat alert does not respect the volume settings of the laptop and screams in full volume every time it has to give an alert. #5

Closed rajudev closed 1 year ago

rajudev commented 2 years ago

Even if my laptop has a lower volume set, batalert screams in full volume every time. This disturbs other people specially when I am in a meeting or working from a place where other people are also working.

rajudev commented 2 years ago

Any progress on this issue @utkarsh2102 ?

utkarsh2102 commented 2 years ago

Hi @rajudev,

Sorry I haven't had the time to look at it yet. But gimme a while, I'll work through this. Essentially, the problem lies here: https://github.com/utkarsh2102/batalert/blob/703e816bcecfe56962f5cc91c041164cb9425c68/lib/batalert.rb#L24-L25

I just need to look at how to make this work with system's volume.

rajudev commented 2 years ago

Interesting, take your time. I'll look forward to an update. Thank You.

Animesh-Ghosh commented 2 years ago

@utkarsh2102 I have added a comment on https://github.com/dejan/espeak-ruby/issues/21. Let's see if the author accepts the proposal of adding the -a option. After that, we can try integrating picandocodigo/volumerb maybe to fetch the system's volume in this gem.

Cheers!

utkarsh2102 commented 2 years ago

Hi @Animesh-Ghosh,

That is awesome, thank you! I wonder if we can just use volumerb here directly? Do we really have to rely on espeak-ruby to accept the patch?

P.S: I genuinely hope they accept it! Thanks a bunch for looking at it and working on this. Let me know what you think!?

utkarsh2102 commented 2 years ago

Hi @Animesh-Ghosh (again!),

That is awesome, thank you! I wonder if we can just use volumerb here directly? Do we really have to rely on espeak-ruby to accept the patch?

Aah, yeah, they do have to accept the patch for us to put the system volume. Once they accept the patch, I think this should do:

--- a/lib/batalert.rb
+++ b/lib/batalert.rb
@@ -3,6 +3,7 @@
 require_relative 'batalert/version'
 require 'espeak'
 require 'libnotify'
+require 'volumerb'

 module Batalert # :nodoc:
   # This is the main Runner class, inside which is the driving code.
@@ -17,11 +18,13 @@ module Batalert # :nodoc:
       status = File.open('/sys/class/power_supply/BAT0/status', &:readline)
       status = status.chomp

+      volume = Volumerb.value
+
       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 = ESpeak::Speech.new("put on charging, your battery is at #{capacity}%.", amplitude: #{volume})
         speech.speak
       end

@@ -29,7 +32,7 @@ module Batalert # :nodoc:
         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 = ESpeak::Speech.new("remove charging, your battery is at #{capacity}%.", amplitude: #{volume})
         speech.speak
       end
     end

What do you think, @Animesh-Ghosh?

Animesh-Ghosh commented 2 years ago

I think the changes look good @utkarsh2102. I'm not on a laptop, so I may not be able to test out the changes by building the gem locally, so I think we can have @rajudev test it out after the updates?

What do you think @utkarsh2102?

Have created https://github.com/dejan/espeak-ruby/pull/22 by the way. 😃

utkarsh2102 commented 2 years ago

I think the changes look good @utkarsh2102. I'm not on a laptop, so I may not be able to test out the changes by building the gem locally, so I think we can have @rajudev test it out after the updates?

No problem, thanks. Maybe I'll ask you once before cutting out a new release. If you have a minute or so to test, that'd be super helpful. Thanks, again! :)

Have created dejan/espeak-ruby#22 by the way. smiley

Lovely, thank you! 🎉