Skip to content

Commit

Permalink
Merge pull request #74 from blinklabs-io/feat/notify-title-option
Browse files Browse the repository at this point in the history
feat: notify title option
  • Loading branch information
wolf31o2 authored Sep 5, 2023
2 parents df560ef + 303ac76 commit 41c1f67
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
10 changes: 6 additions & 4 deletions output/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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",
)
Expand Down
7 changes: 7 additions & 0 deletions output/notify/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
18 changes: 16 additions & 2 deletions output/notify/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,33 @@ import (
"github.com/blinklabs-io/snek/plugin"
)

var cmdlineOptions struct {
title string
}

func init() {
plugin.Register(
plugin.PluginEntry{
Type: plugin.PluginTypeOutput,
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
}

0 comments on commit 41c1f67

Please sign in to comment.