2020-06-19 17:40:18 -04:00
|
|
|
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
// A simple Gio program. See https://gioui.org for more information.
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image/color"
|
|
|
|
"log"
|
2020-06-20 10:17:40 -04:00
|
|
|
"time"
|
2020-06-19 17:40:18 -04:00
|
|
|
|
|
|
|
"gioui.org/app"
|
|
|
|
"gioui.org/io/system"
|
|
|
|
"gioui.org/layout"
|
|
|
|
"gioui.org/op"
|
|
|
|
"gioui.org/text"
|
|
|
|
"gioui.org/widget/material"
|
2020-06-21 21:54:07 -04:00
|
|
|
"git.sr.ht/~whereswaldon/niotify"
|
2020-06-19 17:40:18 -04:00
|
|
|
|
|
|
|
"gioui.org/font/gofont"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
go func() {
|
|
|
|
w := app.NewWindow()
|
|
|
|
if err := loop(w); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
app.Main()
|
|
|
|
}
|
|
|
|
|
|
|
|
func loop(w *app.Window) error {
|
|
|
|
th := material.NewTheme(gofont.Collection())
|
|
|
|
var ops op.Ops
|
2020-06-19 19:07:37 -04:00
|
|
|
first := true
|
2020-06-19 17:40:18 -04:00
|
|
|
for {
|
|
|
|
e := <-w.Events()
|
|
|
|
switch e := e.(type) {
|
|
|
|
case system.DestroyEvent:
|
|
|
|
return e.Err
|
|
|
|
case system.FrameEvent:
|
|
|
|
gtx := layout.NewContext(&ops, e)
|
|
|
|
l := material.H1(th, "Hello, Gio")
|
|
|
|
maroon := color.RGBA{127, 0, 0, 255}
|
|
|
|
l.Color = maroon
|
|
|
|
l.Alignment = text.Middle
|
|
|
|
l.Layout(gtx)
|
|
|
|
e.Frame(gtx.Ops)
|
2020-06-19 19:07:37 -04:00
|
|
|
if first {
|
|
|
|
first = false
|
|
|
|
go func() {
|
2020-06-21 21:54:07 -04:00
|
|
|
mgr, err := niotify.NewManager()
|
2020-06-19 19:07:37 -04:00
|
|
|
if err != nil {
|
2020-06-21 21:54:07 -04:00
|
|
|
log.Printf("manager creation failed: %v", err)
|
2020-06-19 19:07:37 -04:00
|
|
|
}
|
2020-06-21 21:54:07 -04:00
|
|
|
notif, err := mgr.CreateNotification("hello!", "IS GIO OUT THERE?")
|
2020-06-19 19:07:37 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("notification send failed: %v", err)
|
|
|
|
}
|
2020-06-20 10:17:40 -04:00
|
|
|
time.Sleep(time.Second * 10)
|
|
|
|
if err := notif.Cancel(); err != nil {
|
|
|
|
log.Printf("failed cancelling: %v", err)
|
|
|
|
}
|
2020-06-19 19:07:37 -04:00
|
|
|
}()
|
|
|
|
}
|
2020-06-19 17:40:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|