/
system.go
54 lines (43 loc) · 969 Bytes
/
system.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package notification
import (
"fmt"
"os"
"path"
"path/filepath"
"github.com/gen2brain/beeep"
)
const (
icon = "ui/assets/decredicons/qrcodeSymbol.png"
title = "Godcr"
)
type SystemNotification struct {
iconPath string
message string
}
func NewSystemNotification() (*SystemNotification, error) {
absolutePath, err := getAbsolutePath()
if err != nil {
return nil, err
}
return &SystemNotification{
iconPath: filepath.Join(absolutePath, icon),
}, nil
}
func (s *SystemNotification) Notify(message string) error {
err := beeep.Notify(title, message, s.iconPath)
if err != nil {
return err
}
return nil
}
func getAbsolutePath() (string, error) {
ex, err := os.Executable()
if err != nil {
return "", fmt.Errorf("error getting executable path: %s", err.Error())
}
exSym, err := filepath.EvalSymlinks(ex)
if err != nil {
return "", fmt.Errorf("error getting filepath after evaluating sym links")
}
return path.Dir(exSym), nil
}