init linux

This commit is contained in:
popaprozac 2025-02-24 22:39:50 -08:00
commit 253f67243a
6 changed files with 131 additions and 16 deletions

View file

@ -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
)

View file

@ -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=

View file

@ -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)) {

View file

@ -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)
}
}

View file

@ -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
}

View file

@ -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 {