Skip to content

Commit 41c1f67

Browse files
authored
Merge pull request #74 from blinklabs-io/feat/notify-title-option
feat: notify title option
2 parents df560ef + 303ac76 commit 41c1f67

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

output/notify/notify.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ import (
2525
type NotifyOutput struct {
2626
errorChan chan error
2727
eventChan chan event.Event
28+
title string
2829
}
2930

3031
func New(options ...NotifyOptionFunc) *NotifyOutput {
3132
n := &NotifyOutput{
3233
errorChan: make(chan error),
3334
eventChan: make(chan event.Event, 10),
35+
title: "Snek",
3436
}
3537
for _, option := range options {
3638
option(n)
@@ -56,7 +58,7 @@ func (n *NotifyOutput) Start() error {
5658

5759
be := payload.(chainsync.BlockEvent)
5860
err := beeep.Notify(
59-
"Snek",
61+
n.title,
6062
fmt.Sprintf("New Block!\nBlockNumber: %d, SlotNumber: %d\nHash: %s",
6163
be.BlockNumber,
6264
be.SlotNumber,
@@ -75,7 +77,7 @@ func (n *NotifyOutput) Start() error {
7577

7678
re := payload.(chainsync.RollbackEvent)
7779
err := beeep.Notify(
78-
"Snek",
80+
n.title,
7981
fmt.Sprintf("Rollback!\nSlotNumber: %d\nBlockHash: %s",
8082
re.SlotNumber,
8183
re.BlockHash,
@@ -93,7 +95,7 @@ func (n *NotifyOutput) Start() error {
9395

9496
te := payload.(chainsync.TransactionEvent)
9597
err := beeep.Notify(
96-
"Snek",
98+
n.title,
9799
fmt.Sprintf("New Transaction!\nBlockNumber: %d, SlotNumber: %d\nInputs: %d, Outputs: %d\nHash: %s",
98100
te.BlockNumber,
99101
te.SlotNumber,
@@ -108,7 +110,7 @@ func (n *NotifyOutput) Start() error {
108110
}
109111
default:
110112
err := beeep.Notify(
111-
"Snek",
113+
n.title,
112114
fmt.Sprintf("New Event!\nEvent: %v", evt),
113115
"assets/snek-icon.png",
114116
)

output/notify/options.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ package notify
1717
// import "github.com/blinklabs-io/snek/event"
1818

1919
type NotifyOptionFunc func(*NotifyOutput)
20+
21+
// WithTitle specifies the notification title
22+
func WithTitle(title string) NotifyOptionFunc {
23+
return func(o *NotifyOutput) {
24+
o.title = title
25+
}
26+
}

output/notify/plugin.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,33 @@ import (
1818
"github.com/blinklabs-io/snek/plugin"
1919
)
2020

21+
var cmdlineOptions struct {
22+
title string
23+
}
24+
2125
func init() {
2226
plugin.Register(
2327
plugin.PluginEntry{
2428
Type: plugin.PluginTypeOutput,
2529
Name: "notify",
2630
Description: "display events using operating system notifications",
2731
NewFromOptionsFunc: NewFromCmdlineOptions,
28-
Options: []plugin.PluginOption{},
32+
Options: []plugin.PluginOption{
33+
{
34+
Name: "title",
35+
Type: plugin.PluginOptionTypeString,
36+
Description: "specifies the title to use",
37+
DefaultValue: "Snek",
38+
Dest: &(cmdlineOptions.title),
39+
},
40+
},
2941
},
3042
)
3143
}
3244

3345
func NewFromCmdlineOptions() plugin.Plugin {
34-
p := New()
46+
p := New(
47+
WithTitle(cmdlineOptions.title),
48+
)
3549
return p
3650
}

0 commit comments

Comments
 (0)