-
Notifications
You must be signed in to change notification settings - Fork 0
/
dunstctl-history.go
90 lines (84 loc) · 1.85 KB
/
dunstctl-history.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"encoding/json"
"html"
"log"
"os/exec"
"strings"
"github.com/grokify/html-strip-tags-go"
)
type DunstctlHistoryData struct {
Type string `json:"type"`
Data [][]DunstNotification
}
type DunstNotification struct {
Body struct {
Type string `json:"type"`
Data string `json:"data"`
} `json:"body"`
Message struct {
Type string `json:"type"`
Data string `json:"data"`
} `json:"message"`
Summary struct {
Type string `json:"type"`
Data string `json:"data"`
} `json:"summary"`
Appname struct {
Type string `json:"type"`
Data string `json:"data"`
} `json:"appname"`
Category struct {
Type string `json:"type"`
Data string `json:"data"`
} `json:"category"`
DefaultActionName struct {
Type string `json:"type"`
Data string `json:"data"`
} `json:"default_action_name"`
IconPath struct {
Type string `json:"type"`
Data string `json:"data"`
} `json:"icon_path"`
ID struct {
Type string `json:"type"`
Data int `json:"data"`
} `json:"id"`
Timestamp struct {
Type string `json:"type"`
Data int64 `json:"data"`
} `json:"timestamp"`
Timeout struct {
Type string `json:"type"`
Data int64 `json:"data"`
} `json:"timeout"`
Progress struct {
Type string `json:"type"`
Data int `json:"data"`
} `json:"progress"`
}
func getDunstctlHistoryJSON() string {
cmd := exec.Command("dunstctl", "history")
output, err := cmd.Output()
if err != nil {
log.Fatal(err)
return ""
}
return string(output)
}
func getDunstctlHistory() []DunstNotification {
var dunstctlHistory DunstctlHistoryData
err := json.Unmarshal([]byte(getDunstctlHistoryJSON()), &dunstctlHistory)
if err != nil {
log.Fatal(err)
}
result := dunstctlHistory.Data[0]
for i := range result {
result[i].Body.Data = strings.ReplaceAll(
html.UnescapeString(
strip.StripTags(result[i].Body.Data),
), "\n", " ",
)
}
return result
}