Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDen committed Dec 2, 2023
1 parent a79581e commit 6144b1a
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const (
boltIconFilled = "bolt-filled.png"
)

var hardwareUUID string

Check failure on line 23 in main.go

View workflow job for this annotation

GitHub Actions / runner / Go package

var hardwareUUID is unused (U1000)
var plistPath string

type BatteryState uint8

const (
Expand Down Expand Up @@ -92,7 +95,7 @@ func setLowPowerMode(str string) error {
return err
}

func getState(plistPath string) (BatteryState, error) {
func getState() (BatteryState, error) {
cmd := exec.Command("defaults", "read", plistPath)
out, err := cmd.Output()
if err != nil {
Expand Down Expand Up @@ -123,27 +126,23 @@ func getState(plistPath string) (BatteryState, error) {
return state, nil
}

func pollLowPowerState(hardwareUUID string) {
log.Printf("Hardware UUID is %s\n", hardwareUUID)
plistPath := fmt.Sprintf(
"/Library/Preferences/com.apple.PowerManagement.%s.plist",
hardwareUUID,
)
var err error
currentState, err = getState(plistPath)
func pollLowPowerState() {
// Set initial state
currentState, err := getState()
if err != nil {
fmt.Fprintln(os.Stderr, err)
log.Println(err)
os.Exit(1)
}
err = setMenu(currentState)
if err != nil {
fmt.Fprintln(os.Stderr, err)
log.Println(err)
os.Exit(1)
}
tick := time.Tick(15 * time.Second)

// Polling loop
tick := time.Tick(15 * time.Second)
for range tick {
state, err := getState(plistPath)
state, err := getState()
if err != nil {
log.Println(err)
continue
Expand Down Expand Up @@ -293,18 +292,22 @@ func menu() {
func main() {
go menu()
hardwareUUID, err := getHardwareUUID()
log.Printf("Hardware UUID is %s\n", hardwareUUID)
plistPath = fmt.Sprintf(
"/Library/Preferences/com.apple.PowerManagement.%s.plist",
hardwareUUID,
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
log.Println(err)
os.Exit(1)
}
go pollLowPowerState(hardwareUUID)
go pollLowPowerState()

app := menuet.App()
app.Name = "Galvani"
app.Label = "com.github.theden.galvani"
app.Children = menuItems
app.AutoUpdate.Version = appVersion
app.AutoUpdate.Repo = "TheDen/galvani"
// Hook up the graceful shutdown handles
app.RunApplication()
}

0 comments on commit 6144b1a

Please sign in to comment.