batalert-0.4.0/0000755000004100000410000000000013672621215013346 5ustar www-datawww-databatalert-0.4.0/README.md0000644000004100000410000000646313672621215014636 0ustar www-datawww-data# batalert `batalert` (aka *Battery Alert*) is a tool, written in Ruby, to notify the users when their battery is either under-charged (default: < 10%) or over-charged (default: > 90%). > notify the users when their battery is either under-charged (default: < 10%) or over-charged (default: > 90%). Ever ran out of battery whilst in the middle of work? Well, say no more! `batalert` has got you covered! Just consider installing it and put this on cron so that you never have to worry about running out of battery in midst of your work! Isn't that...amazing? 🚀 This is originally intended for [WM](https://en.wikipedia.org/wiki/Window_manager) users who don't have get battery notifications by default, but can be used by everyone who sees its worth! How it works is that this tool, upon being set up, shall notify you when to put your battery on charging and when to unplug it, too. Whilst notifying so, it also numerically mentions your battery percentage at that particular moment. ## Setting up `batalert` #### Ways of installation: - Install the [gem](https://rubygems.org/gems/batalert) from the [rubygems](https://rubygems.org/) archive: `$ gem install batalert` - Install the [package](https://tracker.debian.org/pkg/batalert) via apt (only for Sid and Bullseye): `$ apt install batalert` - Download the deb and install it manually: The [release page](https://github.com/utkarsh2102/batalert/releases) has a .deb binary which can be downloaded with a single click. Once done, run: `$ dpkg -i /batalert__all.deb` #### Ways of setting it as a cron job: - Set it up manually: `$ crontab -e` And then add the following line at the end: `*/n * * * * /usr/bin/batalert` **NOTE**: `n` is the duration of interval (in minutes) after which the binary is executed. So, for instance, if you want to schedule a cron after every 15 minutes (that's what I do), then the line becomes: `*/15 * * * * /usr/bin/batalert` - Use [whenever](https://www.rubyguides.com/2019/04/ruby-whenever-gem/) to schedule the cron automatically on your behalf: (you can install `whenever` via `gem install whenever` or `apt install ruby-whenever`) - Clone this repository: `$ git clone https://github.com/utkarsh2102/batalert.git` - Move to its parent directory: `$ cd batalert` - Set the value of interval in `config/schedule.rb`. - Run `whenever` to schedule the cron: `$ whenever --update-crontab` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing As always, bug reports and pull requests are heartily welcomed! 💖 This project is intended to be a safe and welcoming space for collaboration. ## License `batalert` is available as open-source under the [MIT](https://github.com/utkarsh2102/batalert/blob/master/LICENSE) license. Copyright © 2020 Utkarsh Gupta batalert-0.4.0/LICENSE0000644000004100000410000000212213672621215014350 0ustar www-datawww-dataMIT License =========== Copyright (©) 2020 Utkarsh Gupta Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. batalert-0.4.0/lib/0000755000004100000410000000000013672621215014114 5ustar www-datawww-databatalert-0.4.0/lib/batalert/0000755000004100000410000000000013672621215015712 5ustar www-datawww-databatalert-0.4.0/lib/batalert/version.rb0000644000004100000410000000010713672621215017722 0ustar www-datawww-data# frozen_string_literal: true module Batalert VERSION = '0.4.0' end batalert-0.4.0/lib/batalert.rb0000644000004100000410000000262113672621215016240 0ustar www-datawww-data# frozen_string_literal: true require_relative 'batalert/version' require 'espeak' require 'libnotify' module Batalert # :nodoc: # This is the main Runner class, inside which is the driving code. class Runner # This is the main and the only method which will drive the # entire application and the binary. # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Style/GuardClause 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 # rubocop:enable Metrics/AbcSize,Metrics/MethodLength,Style/GuardClause end end batalert-0.4.0/config/0000755000004100000410000000000013672621215014613 5ustar www-datawww-databatalert-0.4.0/config/schedule.rb0000644000004100000410000000111113672621215016726 0ustar www-datawww-data# frozen_string_literal: true # env :PATH, ENV['PATH'] # env :GEM_PATH, ENV['GEM_PATH'] # Use this file to easily define all of your cron jobs. # # It's helpful, but not entirely necessary to understand cron before proceeding. # http://en.wikipedia.org/wiki/Cron # Example: # # set :output, "/path/to/my/cron_log.log" # # every 2.hours do # command "/usr/bin/some_great_command" # runner "MyModel.some_method" # rake "some:great:rake:task" # end # # every 4.days do # runner "AnotherModel.prune_old_records" # end every 15.minute do command '/usr/local/bin/batalert' end batalert-0.4.0/batalert.gemspec0000644000004100000410000000467013672621215016520 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: batalert 0.4.0 ruby lib Gem::Specification.new do |s| s.name = "batalert".freeze s.version = "0.4.0" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["Utkarsh Gupta".freeze] s.bindir = "exe".freeze s.date = "2020-06-18" s.email = ["utkarsh@debian.org".freeze] s.executables = ["batalert".freeze] s.files = ["LICENSE".freeze, "README.md".freeze, "config/schedule.rb".freeze, "exe/batalert".freeze, "lib/batalert.rb".freeze, "lib/batalert/version.rb".freeze] s.homepage = "https://github.com/utkarsh2102/batalert".freeze s.licenses = ["MIT".freeze] s.required_ruby_version = Gem::Requirement.new(">= 2.3.0".freeze) s.rubygems_version = "2.5.2.1".freeze s.summary = "Battery notifications/alerts for your favorite WM! \u{1f4af}".freeze if s.respond_to? :specification_version then s.specification_version = 4 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q.freeze, [">= 0"]) s.add_runtime_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, [">= 0"]) else s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) end else s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) end end batalert-0.4.0/exe/0000755000004100000410000000000013672621215014127 5ustar www-datawww-databatalert-0.4.0/exe/batalert0000755000004100000410000000014113672621215015647 0ustar www-datawww-data#! /usr/bin/env ruby # frozen_string_literal: true require 'batalert' Batalert::Runner.new.main