zackelia / bclm

macOS command-line utility to limit max battery charge
MIT License
1.88k stars 92 forks source link

Feature request: use Homebrew Services for `persist` #30

Open dingwen07 opened 11 months ago

dingwen07 commented 11 months ago

Homebrew Services is a way to manage background services (using launchctl) for homebrew formulas. Using it to manage persist feature might be a good choice.

kevinm6 commented 9 months ago

@zackelia it should work something like this:

class Bclm < Formula
   desc "macOS command-line utility to limit max battery charge"
   homepage "https://github.com/zackelia/bclm”
   version "0.1.0"
   url "https://github.com/zackelia/bclm/releases/download/v#{version}/bclm.zip"
   sha256 "3f0148e107846e83c7b85282d98ce8611609084920ff0757ab4a017837d54a97"
   license "https://github.com/zackelia/bclm/blob/main/LICENSE"

   depends_on macos: :mavericks

   def install
     bin.install "bclm"
   end
  end

  service do
    run macos: [opt_bin/“bclm”, “write”, “#{value_passed_from_shell}" ]
    keep_alive true
    log_path var/“log/bclm/stdout.log"
    error_log_path var/“log/bclm/stderr.log"
  end
end

The only thing that it’s a little tricky, is that (especially for Intel Macs), this brew formula is copied on install into {/opt/homebrew, /usr/local}/Library/Taps/zackelia/homebrew-formulae/Formula, so the write value to be passed is already copied into /Library/LaunchDaemons by brew. Due to this, have a specific value for the battery percentage could be tricky to handle, since with brew it’s not flexible as populating the plist via Swift.