forked from dolfly/termux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notificationList.go
56 lines (45 loc) · 1.24 KB
/
notificationList.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
package termux
import (
"bytes"
"encoding/json"
"fmt"
"time"
)
const layout = "2006-01-02 15:04:05"
// NotificationListResponse represents a notification
type NotificationListResponse struct {
ID int `json:"id"`
Tag string `json:"tag"`
Key string `json:"key"`
Group string `json:"group"`
PackageName string `json:"packageName"`
Title string `json:"title"`
Content string `json:"content"`
When string `json:"when"`
}
func (n NotificationListResponse) String() string {
var timestamp int64
t, err := time.Parse(layout, n.When)
if err == nil {
timestamp = t.Unix()
}
return fmt.Sprintf("ID: %d\nTag: %s\nKey: %s\nGroup: %s\nPackageName: %s\n"+
"Title: %s\nContent: %s\nWhen: %s\nTimestamp: %d\n",
n.ID, n.Tag, n.Key, n.Group, n.PackageName, n.Title, n.Content, n.When, timestamp)
}
func NotificationList() ([]NotificationListResponse, error) {
buf := bytes.NewBuffer([]byte{})
err := exec(nil, buf, "NotificationList", nil, "")
if err != nil {
return nil, err
}
res := buf.Bytes()
if err := checkErr(res); err != nil {
return nil, err
}
ret := make([]NotificationListResponse, 0)
if err := json.Unmarshal(res, &ret); err != nil {
return nil, err
}
return ret, nil
}