Skip to content

Commit

Permalink
refactor: linear search over events
Browse files Browse the repository at this point in the history
  • Loading branch information
tshakalekholoane committed Nov 27, 2024
1 parent 39040b9 commit 9933b7e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions main_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os/exec"
"path/filepath"
rtdebug "runtime/debug"
"slices"
"strconv"
"strings"
"text/template"
Expand All @@ -34,12 +35,12 @@ const threshold = "charge_control_end_threshold"
var (
tag string

events = map[string]struct{}{
"hibernate": {},
"hybrid-sleep": {},
"multi-user": {},
"suspend": {},
"suspend-then-hibernate": {},
events = [...]string{
"hibernate",
"hybrid-sleep",
"multi-user",
"suspend",
"suspend-then-hibernate",
}

services = filepath.Join("/", "etc", "systemd", "system")
Expand Down Expand Up @@ -246,8 +247,7 @@ func main() {
available := make([]string, 0)
for _, target := range targets {
event := strings.TrimSuffix(target.Unit, ".target")
_, ok := events[event]
if ok {
if slices.Index(events[:], event) != -1 {
available = append(available, event)
}
}
Expand Down Expand Up @@ -341,7 +341,7 @@ func main() {
os.Exit(1)
}
case "reset":
for event := range events {
for _, event := range events {
service := "bat-" + event + ".service"
output, err := exec.Command("systemctl", "disable", service).CombinedOutput()
if err != nil {
Expand Down

0 comments on commit 9933b7e

Please sign in to comment.