Skip to content

Commit 24dbf2c

Browse files
authored
Merge pull request #53 from blinklabs-io/feat/notify
feat: os notifications w/ beeep
2 parents e86c996 + 8205dc3 commit 24dbf2c

File tree

7 files changed

+177
-0
lines changed

7 files changed

+177
-0
lines changed

assets/snek-icon.png

5.92 KB
Loading

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ go 1.18
44

55
require (
66
github.com/blinklabs-io/gouroboros v0.48.0
7+
github.com/gen2brain/beeep v0.0.0-20230602101333-f384c29b62dd
78
github.com/kelseyhightower/envconfig v1.4.0
89
go.uber.org/zap v1.24.0
910
gopkg.in/yaml.v2 v2.4.0
1011
)
1112

1213
require (
1314
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
15+
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect
16+
github.com/godbus/dbus/v5 v5.1.0 // indirect
1417
github.com/jinzhu/copier v0.3.5 // indirect
18+
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
19+
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
1520
github.com/x448/float16 v0.8.4 // indirect
1621
go.uber.org/atomic v1.7.0 // indirect
1722
go.uber.org/multierr v1.6.0 // indirect

go.sum

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,26 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
66
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
77
github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88=
88
github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
9+
github.com/gen2brain/beeep v0.0.0-20230602101333-f384c29b62dd h1:eVPIv7aXHQYJ5lbhXHoJyfPhivIn+BvH2xPoG62lT2w=
10+
github.com/gen2brain/beeep v0.0.0-20230602101333-f384c29b62dd/go.mod h1:0W7dI87PvXJ1Sjs0QPvWXKcQmNERY77e8l7GFhZB/s4=
11+
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE=
12+
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10=
13+
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
14+
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
915
github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg=
1016
github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
1117
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
1218
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
19+
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
20+
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
1321
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
1422
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1523
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1624
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1725
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
1826
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
27+
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
28+
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
1929
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
2030
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
2131
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
@@ -27,6 +37,7 @@ go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
2737
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
2838
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
2939
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
40+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3041
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
3142
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3243
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

output/notify/notify.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2023 Blink Labs, LLC.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package notify
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/blinklabs-io/snek/event"
21+
"github.com/blinklabs-io/snek/input/chainsync"
22+
"github.com/gen2brain/beeep"
23+
)
24+
25+
type NotifyOutput struct {
26+
errorChan chan error
27+
eventChan chan event.Event
28+
}
29+
30+
func New(options ...NotifyOptionFunc) *NotifyOutput {
31+
n := &NotifyOutput{
32+
errorChan: make(chan error),
33+
eventChan: make(chan event.Event, 10),
34+
}
35+
for _, option := range options {
36+
option(n)
37+
}
38+
return n
39+
}
40+
41+
// Start the notify output
42+
func (n *NotifyOutput) Start() error {
43+
go func() {
44+
for {
45+
evt, ok := <-n.eventChan
46+
// Channel has been closed, which means we're shutting down
47+
if !ok {
48+
return
49+
}
50+
switch evt.Type {
51+
case "chainsync.block":
52+
payload := evt.Payload
53+
if payload == nil {
54+
panic(fmt.Errorf("ERROR: %v", payload))
55+
}
56+
57+
be := payload.(chainsync.BlockEvent)
58+
err := beeep.Notify(
59+
"Snek",
60+
fmt.Sprintf("New Block!\nBlockNumber: %d, SlotNumber: %d\nHash: %s",
61+
be.BlockNumber,
62+
be.SlotNumber,
63+
be.BlockHash,
64+
),
65+
"assets/snek-icon.png",
66+
)
67+
if err != nil {
68+
panic(err)
69+
}
70+
default:
71+
err := beeep.Notify(
72+
"Snek",
73+
fmt.Sprintf("New Event!\nEvent: %v", evt),
74+
"assets/snek-icon.png",
75+
)
76+
if err != nil {
77+
panic(err)
78+
}
79+
}
80+
}
81+
}()
82+
return nil
83+
}
84+
85+
// Stop the embedded output
86+
func (n *NotifyOutput) Stop() error {
87+
close(n.eventChan)
88+
close(n.errorChan)
89+
return nil
90+
}
91+
92+
// ErrorChan returns the input error channel
93+
func (n *NotifyOutput) ErrorChan() chan error {
94+
return n.errorChan
95+
}
96+
97+
// InputChan returns the input event channel
98+
func (n *NotifyOutput) InputChan() chan<- event.Event {
99+
return n.eventChan
100+
}
101+
102+
// OutputChan always returns nil
103+
func (n *NotifyOutput) OutputChan() <-chan event.Event {
104+
return nil
105+
}

output/notify/options.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2023 Blink Labs, LLC.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package notify
16+
17+
// import "github.com/blinklabs-io/snek/event"
18+
19+
type NotifyOptionFunc func(*NotifyOutput)

output/notify/plugin.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2023 Blink Labs, LLC.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package notify
16+
17+
import (
18+
"github.com/blinklabs-io/snek/plugin"
19+
)
20+
21+
func init() {
22+
plugin.Register(
23+
plugin.PluginEntry{
24+
Type: plugin.PluginTypeOutput,
25+
Name: "notify",
26+
Description: "display events using operating system notifications",
27+
NewFromOptionsFunc: NewFromCmdlineOptions,
28+
Options: []plugin.PluginOption{},
29+
},
30+
)
31+
}
32+
33+
func NewFromCmdlineOptions() plugin.Plugin {
34+
p := New()
35+
return p
36+
}

output/output.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ package output
1717
// We import the various plugins that we want to be auto-registered
1818
import (
1919
_ "github.com/blinklabs-io/snek/output/log"
20+
_ "github.com/blinklabs-io/snek/output/notify"
2021
)

0 commit comments

Comments
 (0)