-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathsessions.go
67 lines (54 loc) · 1.56 KB
/
sessions.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
package chrome
import "github.com/gopherjs/gopherjs/js"
type Sessions struct {
o *js.Object
MAX_SESSION_RESULTS int
}
func NewSessions(sessionsObj *js.Object) *Sessions {
s := new(Sessions)
s.o = sessionsObj
if s.o.String() != "undefined" {
s.MAX_SESSION_RESULTS = s.o.Get("MAX_SESSION_RESULTS").Int()
}
return s
}
/*
* Types
*/
type Filter struct {
*js.Object
MaxResults int `js:"maxResults"`
}
type Session struct {
*js.Object
LastModified int `js:"lastModified"`
Tab Tab `js:"tab"`
Window Window `js:"window"`
}
type Device struct {
*js.Object
DeviceName string `js:"deviceName"`
Sessions []Session `js:"sessions"`
}
/*
* Methods
*/
// GetRecentlyClosed gets the list of recently closed tabs and/or windows.
func (s *Sessions) GetRecentlyClosed(filter Filter, callback func(sessions []Session)) {
s.o.Call("getRecentlyClosed", filter, callback)
}
// GetDevices retrieves all devices with synced sessions.
func (s *Sessions) GetDevices(filter Filter, callback func(devices []Device)) {
s.o.Call("getDevices", filter, callback)
}
// Restore reopens a windows.Window or tabs.Tab, with an optional callback to run when the entry has been restored.
func (s *Sessions) Restore(sessionId string, callback func(restoredSession Session)) {
s.o.Call("restore", sessionId, callback)
}
/*
* Events
*/
// OnChanged fired when recently closed tabs and/or windows are changed. This event does not monitor synced sessions changes.
func (s *Sessions) OnChanged(callback func()) {
s.o.Get("onChanged").Call("addListener", callback)
}