forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotification.go
More file actions
55 lines (46 loc) · 1.86 KB
/
Copy pathnotification.go
File metadata and controls
55 lines (46 loc) · 1.86 KB
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
package fyne
import "time"
// Notification represents a user notification that can be sent to the operating system.
type Notification struct {
Title, Content string
}
// NewNotification creates a notification that can be passed to [App.SendNotification].
func NewNotification(title, content string) *Notification {
return &Notification{Title: title, Content: content}
}
// ScheduledNotification represents a notification that has been queued for delivery at a
// future time. Instances are returned from [App.ScheduleNotification] and can be cancelled
// using the ID with [App.CancelScheduledNotification].
//
// Since: 2.8
type ScheduledNotification struct {
*Notification
// DeliveryTime is the time at which the notification is scheduled to be delivered.
DeliveryTime time.Time
id string
}
// ID returns the unique identifier for this scheduled notification.
// Pass this value to [App.CancelScheduledNotification] to cancel a pending delivery.
func (s *ScheduledNotification) ID() string {
return s.id
}
// Cancel will remove this scheduled notification from future posting.
// If your application might want to cancel a future notification after it has been restarted
// you should persist the `ID` value and then use `CancelScheduledNotification`.
func (s *ScheduledNotification) Cancel() error {
return CurrentApp().CancelScheduledNotification(s.id)
}
// NewScheduledNotification builds a scheduled notification record with a known ID.
// Application code should not normally call this directly - prefer [App.ScheduleNotification]
// which assigns an ID and arranges delivery.
//
// This is exposed for use by app implementations and advanced testing.
//
// Since: 2.8
func NewScheduledNotification(id string, n *Notification, deliverAt time.Time) *ScheduledNotification {
return &ScheduledNotification{
Notification: n,
DeliveryTime: deliverAt,
id: id,
}
}