Skip to content

Commit

Permalink
feat: turn off MagSafe LED after closing lid #13
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Chiang <[email protected]>
  • Loading branch information
charlie0129 committed Sep 18, 2024
1 parent 1049ab7 commit 1b3c260
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sleepcallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"time"

"github.com/sirupsen/logrus"

"github.com/charlie0129/batt/smc"
)

var (
Expand Down Expand Up @@ -109,6 +111,10 @@ func systemWillSleepCallback() {
logrus.Errorf("DisableCharging failed: %v", err)
return
}
err = smcConn.SetMagSafeLedState(smc.LedOff)
if err != nil {
logrus.Errorf("SetMagSafeLedState failed: %v", err)
}
} else {
logrus.Debugln("no maintained charging is in progress, allow sleep")
}
Expand All @@ -134,6 +140,14 @@ func systemHasPoweredOnCallback() {
// Use sleep instead of time.After because when the computer sleeps, we
// actually want the sleep to prolong as well.
sleep(postSleepLoopDelaySeconds)

if config.DisableChargingPreSleep {
err := smcConn.SetMagSafeLedState(smc.LedOff)
if err != nil {
logrus.Errorf("SetMagSafeLedState failed: %v", err)
}
}

wg.Done()
}()
}
Expand Down

0 comments on commit 1b3c260

Please sign in to comment.