-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathalarms.go
58 lines (47 loc) · 1.44 KB
/
alarms.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
package chrome
import "github.com/gopherjs/gopherjs/js"
type Alarms struct {
o *js.Object
}
/*
* Types
*/
type Alarm struct {
*js.Object
Name string `js:"name"`
ScheduledTime string `js:"scheduledTime"`
PeriodInMinutes string `js:"periodInMinutes"`
}
/*
* Methods:
*/
// Create creates an alarm. Near the time(s) specified by alarmInfo, the onAlarm event is fired.
// If there is another alarm with the same name (or no name if none is specified), it will be
// cancelled and replaced by this alarm.
// You must use time.Now().UnixNano() for "when" timestamp in alarmInfo for this to work.
func (a *Alarms) Create(name string, alarmInfo Object) {
a.o.Call("create", name, alarmInfo)
}
// Get retrieves details about the specified alarm.
func (a *Alarms) Get(name string, callback func(alarm Alarm)) {
a.o.Call("get", name, callback)
}
// GetAll gets an array of all the alarms.
func (a *Alarms) GetAll(callback func(alarms []Alarm)) {
a.o.Call("getAll", callback)
}
// Clear clears the alarm with the given name.
func (a *Alarms) Clear(name string, callback func(wasCleared bool)) {
a.o.Call("clear", name, callback)
}
// ClearAll clears all alarms.
func (a *Alarms) ClearAll(callback func(wasCleared bool)) {
a.o.Call("clearAll", callback)
}
/*
* Events
*/
// OnAlarm is fired when an alarm has elapsed. Useful for event pages.
func (a *Alarms) OnAlarm(callback func(alarm Alarm)) {
a.o.Get("onAlarm").Call("addListener", callback)
}