-
Notifications
You must be signed in to change notification settings - Fork 1
/
echo.go
46 lines (42 loc) · 997 Bytes
/
echo.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
package main
import (
ui "github.com/malivvan/webkitgtk"
)
type API struct{}
func (a *API) Echo(msg string) (string, error) {
return msg, nil
}
func main() {
app := ui.New(ui.AppOptions{
ID: "com.github.malivvan.webkitgtk.examples.api",
Name: "WebKitGTK API Example",
})
app.Open(ui.WindowOptions{
Title: "api",
Width: 420,
Height: 44,
HTML: `<doctype html>
<html>
<body>
<input id="in" type="text"></input>
<button id="echo">echo</button>
<input id="out" type="text" disabled></input>
<script>
document.querySelector("#echo").addEventListener("click", () => {
let input = document.querySelector("#in");
let output = document.querySelector("#out");
api.echo(input.value)
.then(resp => output.value = resp)
.catch(err => output.value = "error: " + err);
});
</script>
</body>
</html>`,
Define: map[string]interface{}{
"api": &API{},
},
})
if err := app.Run(); err != nil {
panic(err)
}
}