From 253f67243afe4bb9eecef573f89484576d224dc7 Mon Sep 17 00:00:00 2001 From: popaprozac Date: Mon, 24 Feb 2025 22:39:50 -0800 Subject: [PATCH] init linux --- v3/go.mod | 1 + v3/go.sum | 2 + .../services/notifications/notifications.go | 5 + .../notifications/notifications_darwin.go | 24 ++-- .../notifications/notifications_linux.go | 103 ++++++++++++++++++ .../notifications/notifications_windows.go | 12 +- 6 files changed, 131 insertions(+), 16 deletions(-) create mode 100644 v3/pkg/services/notifications/notifications_linux.go diff --git a/v3/go.mod b/v3/go.mod index cf9dd83c7..83799de5a 100644 --- a/v3/go.mod +++ b/v3/go.mod @@ -46,6 +46,7 @@ require ( require ( atomicgo.dev/schedule v0.1.0 // indirect + git.sr.ht/~whereswaldon/shout v0.0.0-20241212204820-26acea6b0007 // indirect github.com/ncruces/go-strftime v0.1.9 // indirect ) diff --git a/v3/go.sum b/v3/go.sum index 052246286..16a7c6db4 100644 --- a/v3/go.sum +++ b/v3/go.sum @@ -10,6 +10,8 @@ dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s= dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3 h1:N3IGoHHp9pb6mj1cbXbuaSXV/UMKwmbKLf53nQmtqMA= git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3/go.mod h1:QtOLZGz8olr4qH2vWK0QH0w0O4T9fEIjMuWpKUsH7nc= +git.sr.ht/~whereswaldon/shout v0.0.0-20241212204820-26acea6b0007 h1:5xMwYHPm3ym1ccRmVmUEj4hiESj5uqXMYPwG+1Ruf28= +git.sr.ht/~whereswaldon/shout v0.0.0-20241212204820-26acea6b0007/go.mod h1:VJjhIIJD+YFIyJSH6nCDqoo9ikvAEaD63tUo4uI86pA= github.com/AlekSi/pointer v1.2.0 h1:glcy/gc4h8HnG2Z3ZECSzZ1IX1x2JxRVuDzaJwQE0+w= github.com/AlekSi/pointer v1.2.0/go.mod h1:gZGfd3dpW4vEc/UlyfKKi1roIqcCgwOIvb0tSNSBle0= github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= diff --git a/v3/pkg/services/notifications/notifications.go b/v3/pkg/services/notifications/notifications.go index 78bd6e120..c53f77ba3 100644 --- a/v3/pkg/services/notifications/notifications.go +++ b/v3/pkg/services/notifications/notifications.go @@ -46,6 +46,11 @@ type NotificationResponse = struct { UserInfo map[string]interface{} `json:"userInfo,omitempty"` } +// ServiceName returns the name of the service. +func (ns *Service) ServiceName() string { + return "github.com/wailsapp/wails/v3/services/notifications" +} + // OnNotificationResponse registers a callback function that will be called when // a notification response is received from the user func (ns *Service) OnNotificationResponse(callback func(response NotificationResponse)) { diff --git a/v3/pkg/services/notifications/notifications_darwin.go b/v3/pkg/services/notifications/notifications_darwin.go index 34e49e079..2197e6741 100644 --- a/v3/pkg/services/notifications/notifications_darwin.go +++ b/v3/pkg/services/notifications/notifications_darwin.go @@ -29,11 +29,6 @@ func New() *Service { return NotificationService } -// ServiceName returns the name of the service. -func (ns *Service) ServiceName() string { - return "github.com/wailsapp/wails/v3/services/notifications" -} - // ServiceStartup is called when the service is loaded. func (ns *Service) ServiceStartup(ctx context.Context, options application.ServiceOptions) error { if !CheckBundleIdentifier() { @@ -207,10 +202,15 @@ func (ns *Service) RemoveDeliveredNotification(identifier string) error { return nil } -func (ns *Service) forwardResponse(response NotificationResponse) { - if NotificationService != nil { - NotificationService.handleNotificationResponse(response) - } +// RemoveNotification is a macOS stub that always returns nil. +// Use one of the following instead: +// RemoveAllPendingNotifications +// RemovePendingNotification +// RemoveAllDeliveredNotifications +// RemoveDeliveredNotification +// (Linux-specific) +func (ns *Service) RemoveNotification(identifier string) error { + return nil } //export didReceiveNotificationResponse @@ -222,9 +222,11 @@ func didReceiveNotificationResponse(jsonPayload *C.char) { return } - if response.ActionIdentifier == AppleDefaultActionIdentifier { + if response.ActionIdentifier == "com.apple.UNNotificationDefaultActionIdentifier" { response.ActionIdentifier = DefaultActionIdentifier } - NotificationService.forwardResponse(response) + if NotificationService != nil { + NotificationService.handleNotificationResponse(response) + } } diff --git a/v3/pkg/services/notifications/notifications_linux.go b/v3/pkg/services/notifications/notifications_linux.go new file mode 100644 index 000000000..b499d4788 --- /dev/null +++ b/v3/pkg/services/notifications/notifications_linux.go @@ -0,0 +1,103 @@ +//go:build linux + +package notifications + +import ( + "context" + + "git.sr.ht/~whereswaldon/shout" + "github.com/wailsapp/wails/v3/pkg/application" +) + +var NotificationService *Service +var Notifier shout.Notifier + +// Creates a new Notifications Service. +func New() *Service { + if NotificationService == nil { + NotificationService = &Service{} + } + return NotificationService +} + +// ServiceStartup is called when the service is loaded +func (ns *Service) ServiceStartup(ctx context.Context, options application.ServiceOptions) error { + return nil +} + +// ServiceShutdown is called when the service is unloaded +func (ns *Service) ServiceShutdown() error { + return nil +} + +// CheckBundleIdentifier is a Linux stub that always returns true. +// (bundle identifiers are macOS-specific) +func CheckBundleIdentifier() bool { + return true +} + +// RequestUserNotificationAuthorization is a Linux stub that always returns true, nil. +// (user authorization is macOS-specific) +func (ns *Service) RequestUserNotificationAuthorization() (bool, error) { + return true, nil +} + +// CheckNotificationAuthorization is a Linux stub that always returns true. +// (user authorization is macOS-specific) +func (ns *Service) CheckNotificationAuthorization() bool { + return true +} + +// SendNotification sends a basic notification with a name, title, and body. All other options are ignored on Linux. +// (subtitle and category id are only available on macOS) +func (ns *Service) SendNotification(options NotificationOptions) error { + return nil +} + +// SendNotificationWithActions sends a notification with additional actions and inputs. +// A NotificationCategory must be registered with RegisterNotificationCategory first. The `CategoryID` must match the registered category. +// If a NotificationCategory is not registered a basic notification will be sent. +// (subtitle and category id are only available on macOS) +func (ns *Service) SendNotificationWithActions(options NotificationOptions) error { + return nil +} + +// RegisterNotificationCategory registers a new NotificationCategory to be used with SendNotificationWithActions. +func (ns *Service) RegisterNotificationCategory(category NotificationCategory) error { + return nil +} + +// RemoveNotificationCategory removes a previously registered NotificationCategory. +func (ns *Service) RemoveNotificationCategory(categoryId string) error { + return nil +} + +// RemoveAllPendingNotifications is a Linux stub that always returns nil. +// (macOS-specific) +func (ns *Service) RemoveAllPendingNotifications() error { + return nil +} + +// RemovePendingNotification is a Linux stub that always returns nil. +// (macOS-specific) +func (ns *Service) RemovePendingNotification(_ string) error { + return nil +} + +// RemoveAllDeliveredNotifications is a Linux stub that always returns nil. +// (macOS-specific) +func (ns *Service) RemoveAllDeliveredNotifications() error { + return nil +} + +// RemoveDeliveredNotification is a Linux stub that always returns nil. +// (macOS-specific) +func (ns *Service) RemoveDeliveredNotification(_ string) error { + return nil +} + +// RemoveNotification removes a pending notification matching the unique identifier. +// (Linux-specific) +func (ns *Service) RemoveNotification(identifier string) error { + return nil +} diff --git a/v3/pkg/services/notifications/notifications_windows.go b/v3/pkg/services/notifications/notifications_windows.go index 6a266bbee..e0fc917aa 100644 --- a/v3/pkg/services/notifications/notifications_windows.go +++ b/v3/pkg/services/notifications/notifications_windows.go @@ -24,6 +24,7 @@ const ( dataSeparator = ":::" ) +// Creates a new Notifications Service. func New() *Service { if NotificationService == nil { NotificationService = &Service{} @@ -31,11 +32,6 @@ func New() *Service { return NotificationService } -// ServiceName returns the name of the service -func (ns *Service) ServiceName() string { - return "github.com/wailsapp/wails/v3/services/notifications" -} - // ServiceStartup is called when the service is loaded // Sets an activation callback to emit an event when notifications are interacted with. func (ns *Service) ServiceStartup(ctx context.Context, options application.ServiceOptions) error { @@ -227,6 +223,12 @@ func (ns *Service) RemoveDeliveredNotification(_ string) error { return nil } +// RemoveNotification is a Windows stub that always returns nil. +// (Linux-specific) +func (ns *Service) RemoveNotification(identifier string) error { + return nil +} + func parseNotificationResponse(response string) (action string, data string) { parts := strings.Split(response, dataSeparator) if len(parts) == 1 {