Skip to content

Commit 6683d4c

Browse files
authored
fix: embeded icon for notifications (#230)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 89a2371 commit 6683d4c

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed
File renamed without changes.

output/notify/notify.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Blink Labs Software
1+
// Copyright 2024 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -15,14 +15,20 @@
1515
package notify
1616

1717
import (
18+
_ "embed"
1819
"fmt"
20+
"os"
21+
22+
"github.com/gen2brain/beeep"
1923

2024
"github.com/blinklabs-io/adder/event"
2125
"github.com/blinklabs-io/adder/input/chainsync"
2226
"github.com/blinklabs-io/adder/plugin"
23-
"github.com/gen2brain/beeep"
2427
)
2528

29+
//go:embed icon.png
30+
var icon []byte
31+
2632
type NotifyOutput struct {
2733
errorChan chan error
2834
eventChan chan event.Event
@@ -44,6 +50,21 @@ func New(options ...NotifyOptionFunc) *NotifyOutput {
4450

4551
// Start the notify output
4652
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+
}
4768
go func() {
4869
for {
4970
evt, ok := <-n.eventChan
@@ -73,7 +94,7 @@ func (n *NotifyOutput) Start() error {
7394
be.TransactionCount,
7495
be.BlockHash,
7596
),
76-
"assets/adder-icon.png",
97+
filename,
7798
)
7899
if err != nil {
79100
panic(err)
@@ -91,7 +112,7 @@ func (n *NotifyOutput) Start() error {
91112
re.SlotNumber,
92113
re.BlockHash,
93114
),
94-
"assets/adder-icon.png",
115+
filename,
95116
)
96117
if err != nil {
97118
panic(err)
@@ -119,7 +140,7 @@ func (n *NotifyOutput) Start() error {
119140
te.Fee,
120141
tc.TransactionHash,
121142
),
122-
"assets/adder-icon.png",
143+
filename,
123144
)
124145
if err != nil {
125146
panic(err)
@@ -128,7 +149,7 @@ func (n *NotifyOutput) Start() error {
128149
err := beeep.Notify(
129150
n.title,
130151
fmt.Sprintf("New Event!\nEvent: %v", evt),
131-
"assets/adder-icon.png",
152+
filename,
132153
)
133154
if err != nil {
134155
panic(err)

0 commit comments

Comments
 (0)