diff --git a/output/notify/notify.go b/output/notify/notify.go index 5f9a5e7..d74dbda 100644 --- a/output/notify/notify.go +++ b/output/notify/notify.go @@ -25,12 +25,14 @@ import ( type NotifyOutput struct { errorChan chan error eventChan chan event.Event + title string } func New(options ...NotifyOptionFunc) *NotifyOutput { n := &NotifyOutput{ errorChan: make(chan error), eventChan: make(chan event.Event, 10), + title: "Snek", } for _, option := range options { option(n) @@ -56,7 +58,7 @@ func (n *NotifyOutput) Start() error { be := payload.(chainsync.BlockEvent) err := beeep.Notify( - "Snek", + n.title, fmt.Sprintf("New Block!\nBlockNumber: %d, SlotNumber: %d\nHash: %s", be.BlockNumber, be.SlotNumber, @@ -75,7 +77,7 @@ func (n *NotifyOutput) Start() error { re := payload.(chainsync.RollbackEvent) err := beeep.Notify( - "Snek", + n.title, fmt.Sprintf("Rollback!\nSlotNumber: %d\nBlockHash: %s", re.SlotNumber, re.BlockHash, @@ -93,7 +95,7 @@ func (n *NotifyOutput) Start() error { te := payload.(chainsync.TransactionEvent) err := beeep.Notify( - "Snek", + n.title, fmt.Sprintf("New Transaction!\nBlockNumber: %d, SlotNumber: %d\nInputs: %d, Outputs: %d\nHash: %s", te.BlockNumber, te.SlotNumber, @@ -108,7 +110,7 @@ func (n *NotifyOutput) Start() error { } default: err := beeep.Notify( - "Snek", + n.title, fmt.Sprintf("New Event!\nEvent: %v", evt), "assets/snek-icon.png", ) diff --git a/output/notify/options.go b/output/notify/options.go index f3fb56d..2dad323 100644 --- a/output/notify/options.go +++ b/output/notify/options.go @@ -17,3 +17,10 @@ package notify // import "github.com/blinklabs-io/snek/event" type NotifyOptionFunc func(*NotifyOutput) + +// WithTitle specifies the notification title +func WithTitle(title string) NotifyOptionFunc { + return func(o *NotifyOutput) { + o.title = title + } +} diff --git a/output/notify/plugin.go b/output/notify/plugin.go index 714b5b2..2d289c0 100644 --- a/output/notify/plugin.go +++ b/output/notify/plugin.go @@ -18,6 +18,10 @@ import ( "github.com/blinklabs-io/snek/plugin" ) +var cmdlineOptions struct { + title string +} + func init() { plugin.Register( plugin.PluginEntry{ @@ -25,12 +29,22 @@ func init() { Name: "notify", Description: "display events using operating system notifications", NewFromOptionsFunc: NewFromCmdlineOptions, - Options: []plugin.PluginOption{}, + Options: []plugin.PluginOption{ + { + Name: "title", + Type: plugin.PluginOptionTypeString, + Description: "specifies the title to use", + DefaultValue: "Snek", + Dest: &(cmdlineOptions.title), + }, + }, }, ) } func NewFromCmdlineOptions() plugin.Plugin { - p := New() + p := New( + WithTitle(cmdlineOptions.title), + ) return p }