Skip to content

Commit

Permalink
fix: magsafe led may keep in the off-state if no control magsafe led …
Browse files Browse the repository at this point in the history
…option is set
  • Loading branch information
charlie0129 committed Jan 21, 2025
1 parent 18ce7df commit 296bc6c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
12 changes: 10 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import (
)

func send(method string, path string, data string) (string, error) {
logrus.Debugf("sending %s %s with data %s to %s", method, path, data, unixSocketPath)
logrus.WithFields(logrus.Fields{
"method": method,
"path": path,
"data": data,
"unix": unixSocketPath,
}).Debug("sending request")

httpc := http.Client{
Transport: &http.Transport{
Expand Down Expand Up @@ -63,7 +68,10 @@ func send(method string, path string, data string) (string, error) {

code := resp.StatusCode

logrus.Debugf("got response: %d %s", code, body)
logrus.WithFields(logrus.Fields{
"code": code,
"body": body,
}).Debug("got response")

if code < 200 || code > 299 {
return "", fmt.Errorf("got %d: %s", code, body)
Expand Down
2 changes: 1 addition & 1 deletion conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func saveConfig() error {
func loadConfig() error {
// Check if config file exists
if _, err := os.Stat(configPath); errors.Is(err, os.ErrNotExist) {
logrus.Infof("config file %s does not exist, using default config %#v", configPath, defaultConfig)
logrus.WithField("config", defaultConfig).Infof("config file %s does not exist, using default config", configPath)
config = defaultConfig
err := saveConfig()
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ func printStatus(
isPluggedIn bool,
maintainedChargingInProgress bool,
) {
logrus.Debugf("batteryCharge=%d, lower=%d, upper=%d, chargingEnabled=%t, isPluggedIn=%t, maintainedChargingInProgress=%t",
batteryCharge,
lower,
upper,
isChargingEnabled,
isPluggedIn,
maintainedChargingInProgress,
)
logrus.WithFields(logrus.Fields{
"batteryCharge": batteryCharge,
"lower": lower,
"upper": upper,
"chargingEnabled": isChargingEnabled,
"isPluggedIn": isPluggedIn,
"maintainedChargingInProgress": maintainedChargingInProgress,
}).Debug("maintain loop status")
}
8 changes: 5 additions & 3 deletions sleepcallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ func systemWillSleepCallback() {
logrus.Errorf("DisableCharging failed: %v", err)
return
}
err = smcConn.SetMagSafeLedState(smc.LEDOff)
if err != nil {
logrus.Errorf("SetMagSafeLedState failed: %v", err)
if config.ControlMagSafeLED {
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 Down

0 comments on commit 296bc6c

Please sign in to comment.