Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion internal/attention/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/sha256"
"errors"
"fmt"
"log/slog"
"path/filepath"
"sync"
"time"
Expand Down Expand Up @@ -54,6 +55,9 @@ func (m *MacNotifier) Notify(ctx context.Context, n Notification) error {
m.mu.Unlock()
if start { // outside the lock: the callback may run synchronously
m.Center.Authorize(func(err error) {
if err != nil {
slog.Warn("macOS notification permission refused", "event", "notifications_refused", "err", err.Error())
}
m.mu.Lock()
m.authErr = err
if err != nil {
Expand Down Expand Up @@ -109,7 +113,11 @@ func (m *MacNotifier) post(ctx context.Context, n Notification) error {
}
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
return m.Center.Add(ctx, nativeNotificationRequest(n))
if err := m.Center.Add(ctx, nativeNotificationRequest(n)); err != nil {
slog.Warn("macOS notification not delivered", "event", "notification_failed", "err", err.Error())
return err
}
return nil
}

func nativeNotificationRequest(n Notification) NativeNotificationRequest {
Expand Down
9 changes: 9 additions & 0 deletions internal/cli/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"context"
"fmt"
"github.com/labstack/driga/internal/attention"
"io"
"log/slog"
"os"
Expand Down Expand Up @@ -70,6 +71,14 @@ func (c CollectCmd) Run(g *Globals) error {
if err != nil {
return err
}
if runtime.GOOS == "darwin" {
// Record what macOS reports, so a silent notification problem shows in the log.
if status, err := attention.MacNotificationStatus(); err != nil {
slog.Warn("macOS notifications unavailable", "event", "notifications_unavailable", "err", err.Error())
} else {
slog.Info("macOS notifications", "event", "notifications_status", "status", status)
}
}
ctx, stop := notifyContext(context.Background())
defer stop()
if c.CPUProfile != "" {
Expand Down
Loading