This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 344
/
notification.go
66 lines (59 loc) · 2.1 KB
/
notification.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
package astilectron
import "context"
// Notification event names
const (
eventNameNotificationCmdCreate = "notification.cmd.create"
eventNameNotificationCmdShow = "notification.cmd.show"
EventNameNotificationEventClicked = "notification.event.clicked"
EventNameNotificationEventClosed = "notification.event.closed"
EventNameNotificationEventCreated = "notification.event.created"
EventNameNotificationEventReplied = "notification.event.replied"
EventNameNotificationEventShown = "notification.event.shown"
)
// Notification represents a notification
// https://github.com/electron/electron/blob/v1.8.1/docs/api/notification.md
type Notification struct {
isSupported bool
o *NotificationOptions
*object
}
// NotificationOptions represents notification options
type NotificationOptions struct {
Body string `json:"body,omitempty"`
HasReply *bool `json:"hasReply,omitempty"`
Icon string `json:"icon,omitempty"`
ReplyPlaceholder string `json:"replyPlaceholder,omitempty"`
Silent *bool `json:"silent,omitempty"`
Sound string `json:"sound,omitempty"`
Subtitle string `json:"subtitle,omitempty"`
Title string `json:"title,omitempty"`
}
func newNotification(ctx context.Context, o *NotificationOptions, isSupported bool, d *dispatcher, i *identifier, wrt *writer) *Notification {
return &Notification{
isSupported: isSupported,
o: o,
object: newObject(ctx, d, i, wrt, i.new()),
}
}
// Create creates the notification
func (n *Notification) Create() (err error) {
if !n.isSupported {
return
}
if err = n.ctx.Err(); err != nil {
return
}
_, err = synchronousEvent(n.ctx, n, n.w, Event{Name: eventNameNotificationCmdCreate, TargetID: n.id, NotificationOptions: n.o}, EventNameNotificationEventCreated)
return
}
// Show shows the notification
func (n *Notification) Show() (err error) {
if !n.isSupported {
return
}
if err = n.ctx.Err(); err != nil {
return
}
_, err = synchronousEvent(n.ctx, n, n.w, Event{Name: eventNameNotificationCmdShow, TargetID: n.id}, EventNameNotificationEventShown)
return
}