1
- // Copyright 2023 Blink Labs Software
1
+ // Copyright 2024 Blink Labs Software
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
15
15
package notify
16
16
17
17
import (
18
+ _ "embed"
18
19
"fmt"
20
+ "os"
21
+
22
+ "github.com/gen2brain/beeep"
19
23
20
24
"github.com/blinklabs-io/adder/event"
21
25
"github.com/blinklabs-io/adder/input/chainsync"
22
26
"github.com/blinklabs-io/adder/plugin"
23
- "github.com/gen2brain/beeep"
24
27
)
25
28
29
+ //go:embed icon.png
30
+ var icon []byte
31
+
26
32
type NotifyOutput struct {
27
33
errorChan chan error
28
34
eventChan chan event.Event
@@ -44,6 +50,21 @@ func New(options ...NotifyOptionFunc) *NotifyOutput {
44
50
45
51
// Start the notify output
46
52
func (n * NotifyOutput ) Start () error {
53
+ // Write our icon asset
54
+ userCacheDir , err := os .UserCacheDir ()
55
+ if err != nil {
56
+ return err
57
+ }
58
+ if _ , err := os .Stat (fmt .Sprintf ("%s/%s" , userCacheDir , "adder" )); os .IsNotExist (err ) {
59
+ err = os .MkdirAll (fmt .Sprintf ("%s/%s" , userCacheDir , "adder" ), os .ModePerm )
60
+ if err != nil {
61
+ panic (err )
62
+ }
63
+ }
64
+ filename := fmt .Sprintf ("%s/%s/%s" , userCacheDir , "adder" , "icon.png" )
65
+ if err := os .WriteFile (filename , icon , 0666 ); err != nil {
66
+ panic (err )
67
+ }
47
68
go func () {
48
69
for {
49
70
evt , ok := <- n .eventChan
@@ -73,7 +94,7 @@ func (n *NotifyOutput) Start() error {
73
94
be .TransactionCount ,
74
95
be .BlockHash ,
75
96
),
76
- "assets/adder-icon.png" ,
97
+ filename ,
77
98
)
78
99
if err != nil {
79
100
panic (err )
@@ -91,7 +112,7 @@ func (n *NotifyOutput) Start() error {
91
112
re .SlotNumber ,
92
113
re .BlockHash ,
93
114
),
94
- "assets/adder-icon.png" ,
115
+ filename ,
95
116
)
96
117
if err != nil {
97
118
panic (err )
@@ -119,7 +140,7 @@ func (n *NotifyOutput) Start() error {
119
140
te .Fee ,
120
141
tc .TransactionHash ,
121
142
),
122
- "assets/adder-icon.png" ,
143
+ filename ,
123
144
)
124
145
if err != nil {
125
146
panic (err )
@@ -128,7 +149,7 @@ func (n *NotifyOutput) Start() error {
128
149
err := beeep .Notify (
129
150
n .title ,
130
151
fmt .Sprintf ("New Event!\n Event: %v" , evt ),
131
- "assets/adder-icon.png" ,
152
+ filename ,
132
153
)
133
154
if err != nil {
134
155
panic (err )
0 commit comments