Skip to content

Commit

Permalink
fix: fix threshold persistence after hibernation
Browse files Browse the repository at this point in the history
Fix an issue, #11, with the
charging threshold where it would not persist after the system went into
hibernation on some distributions.
  • Loading branch information
Tshaka Eric Lekholoane committed Jul 27, 2021
1 parent 1e01080 commit 62d47b3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ There have also been some [problems setting the charging threshold inside of a v

## Installation

Precompiled binaries (Linux x86-64) are available from the [GitHub releases page](https://github.com/leveson/bat/releases), the latest of which can be downloaded from [here](https://github.com/leveson/bat/releases/download/0.7/bat).
Precompiled binaries (Linux x86-64) are available from the [GitHub releases page](https://github.com/leveson/bat/releases), the latest of which can be downloaded from [here](https://github.com/leveson/bat/releases/download/0.8/bat).

After downloading the binary, give it permission to execute on your system by running the following command. For example, assuming the binary is located in the user's Downloads folder:

Expand Down
3 changes: 2 additions & 1 deletion cmd/bat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func main() {
log.Fatal(err)
}
}
fmt.Println("Persistence of the current threshold enabled.")
fmt.Println("Persistence of the current charging threshold enabled.")
case "-r", "--reset":
err := persist.RemoveServices()
if err != nil {
Expand All @@ -72,6 +72,7 @@ func main() {
}
log.Fatal(err)
}
fmt.Println("Charging threshold persistence reset.")
case "-s", "--status":
printFile("status")
case "-t", "--threshold":
Expand Down
2 changes: 1 addition & 1 deletion internal/docs/version.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
bat 0.7
bat 0.8
Copyright (c) 2021 Tshaka Eric Lekholoane.
MIT Licence.
5 changes: 3 additions & 2 deletions internal/persist/persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func hasRequiredSystemd() (bool, error) {
// level between restarts. If the call is successful, the return value
// is nil.
func RemoveServices() error {
for _, service := range [2]string{"boot", "sleep"} {
for _, service := range [3]string{"boot", "hibernation", "sleep"} {
err := os.Remove(
fmt.Sprintf("/etc/systemd/system/bat-%s.service", service))
if err != nil {
Expand Down Expand Up @@ -89,8 +89,9 @@ func WriteServices() error {
if err != nil {
return err
}
units := [2]Service{
units := [3]Service{
{"boot", "multi-user", threshold},
{"hibernation", "hibernate", threshold},
{"sleep", "suspend", threshold},
}
tmpl, err := template.New("unit").Parse(unit)
Expand Down
2 changes: 1 addition & 1 deletion internal/persist/unit.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Unit]
Description=Persist the battery charging threshold between {{ .Event }}
Description=Persist the battery charging threshold after {{ .Event }}
After={{ .Target }}.target
StartLimitBurst=0

Expand Down

0 comments on commit 62d47b3

Please sign in to comment.