adding mac support mainly

This commit is contained in:
lwoodard
2026-04-13 08:11:19 -06:00
parent 9c681e482e
commit 0f5a136764
9 changed files with 657 additions and 190 deletions

View File

@@ -7,6 +7,7 @@ import (
"image"
"image/jpeg"
_ "image/png"
"runtime"
"strings"
"sync"
@@ -62,7 +63,16 @@ func Open(vendorID, productID uint16) (*StreamDeck, error) {
dev, err := hid.OpenFirst(vendorID, productID)
if err != nil {
return nil, fmt.Errorf("open device 0x%04x:0x%04x: %w (try: sudo chmod a+rw /dev/hidraw*)", vendorID, productID, err)
var hint string
switch runtime.GOOS {
case "linux":
hint = "try: sudo chmod a+rw /dev/hidraw*"
case "darwin":
hint = "try: brew install hidapi; check System Settings → Privacy & Security → Input Monitoring"
default:
hint = "check device permissions"
}
return nil, fmt.Errorf("open device 0x%04x:0x%04x: %w (%s)", vendorID, productID, err, hint)
}
return &StreamDeck{dev: dev, model: m}, nil
@@ -153,10 +163,14 @@ func (sd *StreamDeck) ReadButtons() ([]bool, error) {
data := make([]byte, readReportSize)
n, err := sd.dev.ReadWithTimeout(data, 250)
if err != nil {
// hidraw on Linux returns errors rather than (0, nil) for non-fatal
// conditions: timeout waiting for data, or EINTR (signal interrupted).
// Linux hidraw returns errors (not (0,nil)) for non-fatal conditions:
// timeout waiting for data, or EINTR (signal interrupted).
// macOS IOHIDManager usually returns (0, nil) on timeout, but may also
// return an error with a different message — catch both spellings.
msg := strings.ToLower(err.Error())
if strings.Contains(msg, "timeout") || strings.Contains(msg, "interrupted") {
if strings.Contains(msg, "timeout") ||
strings.Contains(msg, "timed out") ||
strings.Contains(msg, "interrupted") {
return nil, nil
}
return nil, err