mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-23 17:01:29 +02:00
Shorten over-long godoc/inline comments across the client/ui tray and services code: drop narrative restatement, legacy-Fyne tangents, and text already evident from signatures and names. Keep only the non-obvious why (concurrency/lock ordering, platform quirks, ordering constraints, the profile-switch state table). No code changes.
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
//go:build !android && !ios && !freebsd && !js
|
|
|
|
package main
|
|
|
|
import (
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/wailsapp/wails/v3/pkg/services/notifications"
|
|
)
|
|
|
|
// sendFn fits both NotificationService.SendNotification and SendNotificationWithActions.
|
|
type sendFn func(notifications.NotificationOptions) error
|
|
|
|
// safeSendNotification sends a best-effort OS notification, swallowing errors and panics.
|
|
//
|
|
// The panic guard is load-bearing on Linux: when Wails' notifier fails to
|
|
// connect the session bus at startup (headless, unreachable
|
|
// DBUS_SESSION_BUS_ADDRESS) it stays registered with a nil *dbus.Conn, so the
|
|
// next send nil-derefs inside godbus. Because sends run on a Wails
|
|
// event-dispatch goroutine that panic is fatal process-wide; recover() turns
|
|
// it into a logged no-op.
|
|
func safeSendNotification(send sendFn, what string, opts notifications.NotificationOptions) (err error) {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
log.Errorf("notify %s: recovered from panic (notification bus unavailable): %v", what, r)
|
|
err = nil
|
|
}
|
|
}()
|
|
if err := send(opts); err != nil {
|
|
log.Errorf("notify %s: %v", what, err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|