-
Notifications
You must be signed in to change notification settings - Fork 33
/
windows.go
101 lines (84 loc) · 2.97 KB
/
windows.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package chrome
import "github.com/gopherjs/gopherjs/js"
type Windows struct {
o *js.Object
WINDOW_ID_NONE int
WINDOW_ID_CURRENT int
}
func NewWindows(windowsObj *js.Object) *Windows {
w := new(Windows)
w.o = windowsObj
if w.o.String() != "undefined" {
w.WINDOW_ID_CURRENT = w.o.Get("WINDOW_ID_CURRENT").Int()
w.WINDOW_ID_NONE = w.o.Get("WINDOW_ID_NONE").Int()
}
return w
}
/*
* Types
*/
type Window struct {
*js.Object
Id int `js:"id"`
Focused bool `js:"focused"`
Top int `js:"top"`
Left int `js:"left"`
Width int `js:"width"`
Height int `js:"height"`
Tabs []Tab `js:"tabs"`
Incognito bool `js:"incognito"`
Type string `js:"type"`
State string `js:"state"`
AlwaysOnTop bool `js:"alwaysOnTop"`
SessionId string `js:"sessionId"`
}
/*
* Methods
*/
// Get gets details about a window.
func (w *Windows) Get(windowId int, getInfo Object, callback func(window Window)) {
w.o.Call("get", windowId, getInfo, callback)
}
// GetCurrent gets the current window.
func (w *Windows) GetCurrent(getInfo Object, callback func(window Window)) {
w.o.Call("getCurrent", getInfo, callback)
}
// GetLastFocused gets the window that was most recently focused — typically the window 'on top'.
func (w *Windows) GetLastFocused(getInfo Object, callback func(window Window)) {
w.o.Call("getLastFocused", getInfo, callback)
}
// GetAll gets all windows.
func (w *Windows) GetAll(getInfo Object, callback func(windows []Window)) {
w.o.Call("getAll", getInfo, callback)
}
// Create creates (opens) a new browser with any optional sizing, position or default URL provided.
func (w *Windows) Create(createData Object, callback func(window Window)) {
w.o.Call("create", createData, callback)
}
// Update updates the properties of a window. Specify only the properties that you
// want to change; unspecified properties will be left unchanged.
func (w *Windows) Update(windowId int, updateInfo Object, callback func(window Window)) {
w.o.Call("update", windowId, updateInfo, callback)
}
// Remove removes (closes) a window, and all the tabs inside it.
func (w *Windows) Remove(windowId int, callback func(js.Object)) {
w.o.Call("remove", windowId, callback)
}
/*
* Events
*/
// OnCreated fired when a window is created.
func (w *Windows) OnCreated(callback func(window Window)) {
w.o.Get("onCreated").Call("addListener", callback)
}
// OnRemoved fired when a window is removed (closed).
func (w *Windows) OnRemoved(callback func(windowId int)) {
w.o.Get("onRemoved").Call("addListener", callback)
}
// OnFocusChanged fired when the currently focused window changes.
// Will be chrome.windows.WINDOW_ID_NONE if all chrome windows have lost focus.
// Note: On some Linux window managers, WINDOW_ID_NONE will always be sent immediately
// preceding a switch from one chrome window to another.
func (w *Windows) OnFocusChanged(callback func(windowId int)) {
w.o.Get("onFocusChanged").Call("addListener", callback)
}