~whereswaldon/gio-x

e57f01cea19cd8f2f9879e9eb03984c20ad70b8e — Jack Mordaunt 2 years ago e544f34
notify: simplify api down to a single package function

notify.Push is all you need!

Concrete type is established on package initialization.

Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
M notify/notification_manager.go => notify/notification_manager.go +9 -0
@@ 9,6 9,10 @@
//     notification.Cancel()
package notify

// impl is a package global notifier initialized to the current platform
// implementation.
var impl Notifier

// Notifier provides methods for creating and managing notifications.
type Notifier interface {
	CreateNotification(title, text string) (Notification, error)


@@ 38,3 42,8 @@ type noop struct{}
func (noop) Cancel() error {
	return nil
}

// Push a notification to the OS.
func Push(title, text string) (Notification, error) {
	return impl.CreateNotification(title, text)
}

M notify/notify_android.go => notify/notify_android.go +4 -0
@@ 29,3 29,7 @@ func (a *android) CreateNotification(title, text string) (Notification, error) {
	}
	return &notification, nil
}

func init() {
	impl, _ = newNotifier()
}

M notify/notify_darwin.go => notify/notify_darwin.go +4 -0
@@ 25,3 25,7 @@ func (a *macos) CreateNotification(title, text string) (Notification, error) {
	}
	return &notification, nil
}

func init() {
	impl, _ = newNotifier()
}

M notify/notify_dbus.go => notify/notify_dbus.go +4 -0
@@ 54,3 54,7 @@ func (l linuxNotification) Cancel() error {
	_, err := l.linux.CloseNotification(l.id)
	return err
}

func init() {
	impl, _ = newNotifier()
}

M notify/notify_unsupported.go => notify/notify_unsupported.go +4 -0
@@ 11,3 11,7 @@ func newNotifier() (Notifier, error) {
func (unsupported) CreateNotification(title, text string) (Notification, error) {
	return &noop{}, nil
}

func init() {
	impl, _ = newNotifier()
}

M notify/notify_windows.go => notify/notify_windows.go +4 -0
@@ 34,3 34,7 @@ func (m *windows) CreateNotification(title, text string) (Notification, error) {
func (m *windows) UseIcon(path string) {
	m.icon = path
}

func init() {
	impl, _ = newNotifier()
}