-
Notifications
You must be signed in to change notification settings - Fork 1
/
notify.go
64 lines (56 loc) · 1.34 KB
/
notify.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
package main
import (
_ "embed"
ui "github.com/malivvan/webkitgtk"
)
type NotifyAPI struct {
app *ui.App
}
type Notification struct {
Title string `json:"title"`
Body string `json:"body"`
}
func (a *NotifyAPI) Notify(notification *Notification) (uint32, error) {
return a.app.Notify(notification.Title, notification.Body).
Action("open", func() {
println("action open")
}).
Closed(func() {
println("closed")
}).Show()
}
func main() {
app := ui.New(ui.AppOptions{
ID: "com.github.malivvan.webkitgtk.examples.notify",
Name: "WebKitGTK Notify Example",
})
app.Open(ui.WindowOptions{
Title: "notify",
Width: 200,
Height: 90,
HTML: `<doctype html>
<html>
<body>
<input id="title" type="text" placeholder="Title"></input><br>
<input id="body" type="text" placeholder="Body"></input><br>
<button id="notify">notify</button>
<script>
document.querySelector("#notify").addEventListener("click", () => {
let title = document.querySelector("#title");
let body = document.querySelector("#body");
api.notify({
title: title.value,
body: body.value,
}).catch(err => console.error("error: " + err));
});
</script>
</body>
</html>`,
Define: map[string]interface{}{
"api": &NotifyAPI{app: app},
},
})
if err := app.Run(); err != nil {
panic(err)
}
}