-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathruntime.go
141 lines (110 loc) · 3.69 KB
/
runtime.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package chrome
import "github.com/gopherjs/gopherjs/js"
type Runtime struct {
o *js.Object
LastError *js.Object
Id string
}
func NewRuntime(runtimeObj *js.Object) *Runtime {
r := new(Runtime)
r.o = runtimeObj
if r.o.String() != "undefined" {
r.LastError = r.o.Get("lastError")
r.Id = r.o.Get("id").String()
}
return r
}
/*
* Types
*/
type Port struct {
*js.Object
Name string `js:"name"`
OnDisconnect js.Object `js:"onDisconnect"`
OnMessage js.Object `js:"onMessage"`
Sender MessageSender `js:"sender"`
}
type MessageSender struct {
*js.Object
tab Tab `js:"tab"`
FrameId int `js:"frameId"`
Id string `js:"id"`
Url string `js:"url"`
TlsChannelId string `js:"tlsChannelId"`
}
type PlatformInfo map[string]string
/*
* Methods
*/
func (r *Runtime) GetBackgroundPage(callback func(backgroundPage interface{})) {
r.o.Call("getBackgroundPage", callback)
}
func (r *Runtime) GetManifest() *js.Object {
return r.o.Call("getManifest")
}
func (r *Runtime) GetURL(path string) string {
return r.o.Call("getURL", path).String()
}
func (r *Runtime) Reload() {
r.o.Call("reload")
}
// Maybe make status an Enum string with specific values.
func (r *Runtime) RequestUpdateCheck(callback func(status string, details interface{})) {
r.o.Call("requestUpdateCheck", callback)
}
func (r *Runtime) Restart() {
r.o.Call("restart")
}
func (r *Runtime) Connect(extensionId string, connectInfo interface{}) Port {
portObj := r.o.Call("connect", extensionId, connectInfo)
return Port{Object: portObj}
}
func (r *Runtime) ConnectNative(application string) Port {
portObj := r.o.Call("connectNative", application)
return Port{Object: portObj}
}
func (r *Runtime) SendMessage(extensionId string, message interface{}, options interface{}, responseCallback func(response interface{})) {
r.o.Call("sendMessage", extensionId, message, options, responseCallback)
}
func (r *Runtime) SendNativeMessage(application string, message interface{}, responseCallback func(response interface{})) {
r.o.Call("sendNativeMessage", application, message, responseCallback)
}
func (r *Runtime) GetPlatformInfo(callback func(platformInfo PlatformInfo)) {
r.o.Call("getPlatformInfo", callback)
}
func (r *Runtime) GetPackageDirectoryEntry(callback func(directoryEntry interface{})) {
r.o.Call("getPackageDirectoryEntry", callback)
}
/*
* Events
*/
func (r *Runtime) OnStartup(callback func()) {
r.o.Get("onStartup").Call("addListener", callback)
}
func (r *Runtime) OnInstalled(callback func(details map[string]string)) {
r.o.Get("onInstalled").Call("addListener", callback)
}
func (r *Runtime) OnSuspend(callback func()) {
r.o.Get("onSuspend").Call("addListener", callback)
}
func (r *Runtime) OnSuspendCanceled(callback func()) {
r.o.Get("onSuspendCanceled").Call("addListener", callback)
}
func (r *Runtime) OnUpdateAvailable(callback func(details map[string]string)) {
r.o.Get("onUpdateAvailable").Call("addListener", callback)
}
func (r *Runtime) OnConnect(callback func(port Port)) {
r.o.Get("onConnect").Call("addListener", callback)
}
func (r *Runtime) OnConnectExternal(callback func(port Port)) {
r.o.Get("onConnectExternal").Call("addListener", callback)
}
func (r *Runtime) OnMessage(callback func(message interface{}, sender MessageSender, sendResponse func(interface{}))) {
r.o.Get("onMessage").Call("addListener", callback)
}
func (r *Runtime) OnMessageExternal(callback func(message interface{}, sender MessageSender, sendResponse func(interface{}))) {
r.o.Get("onMessageExternal").Call("addListener", callback)
}
func (r *Runtime) OnRestartRequired(callback func(reason string)) {
r.o.Get("onRestartRequired").Call("addListener", callback)
}