~eliasnaur/gio-example

0034e85d8fecef042d50f8a1df0ccafa047b0cb8 — Chris Waldon 7 months ago 10e912d
gio-extras/niotify: add niotify example

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
4 files changed, 116 insertions(+), 0 deletions(-)

A gio-extras/niotify/hello.go
A gio-extras/niotify/hello_macos.go
M go.mod
M go.sum
A gio-extras/niotify/hello.go => gio-extras/niotify/hello.go +100 -0
@@ 0,0 1,100 @@
// SPDX-License-Identifier: Unlicense OR MIT

package main

// A simple Gio program. See https://gioui.org for more information.

import (
	//	"image/color"
	"log"
	"time"

	"gioui.org/app"
	"gioui.org/io/system"
	"gioui.org/layout"
	"gioui.org/op"

	//	"gioui.org/text"
	"gioui.org/widget"
	"gioui.org/widget/material"
	"git.sr.ht/~whereswaldon/niotify"

	"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
	first := true
	notificationRequests := make(chan struct{})
	var button widget.Clickable
	var err error
	for {
		e := <-w.Events()
		switch e := e.(type) {
		case system.DestroyEvent:
			return e.Err
		case system.FrameEvent:
			if button.Clicked() {
				notificationRequests <- struct{}{}
			}
			gtx := layout.NewContext(&ops, e)
			layout.Inset{
    			Top: e.Insets.Top,
    			Bottom: e.Insets.Bottom,
    			Left: e.Insets.Left,
    			Right: e.Insets.Right,
			}.Layout(gtx, func(gtx layout.Context) layout.Dimensions {

			return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
                              layout.Rigid(func(gtx layout.Context) layout.Dimensions {
                                           text := "notification errors will appear here"
                                           if err != nil {
                                               text = err.Error()
                                           }
                                   return material.Body1(th, text).Layout(gtx)
                              }),
                              layout.Flexed(1,func(gtx layout.Context) layout.Dimensions {
                                    return material.Button(th, &button, "Send Notification").Layout(gtx)
                              }),
                          )
			})
			e.Frame(gtx.Ops)
			if first {
				first = false
				go func() {
					mgr, e := niotify.NewManager()
					if e != nil {
						log.Printf("manager creation failed: %v", e)
						err = e
					}
					for _ = range notificationRequests {
    						log.Println("trying to send notification")
						notif, e := mgr.CreateNotification("hello!", "IS GIO OUT THERE?")
						if e != nil {
							log.Printf("notification send failed: %v", e)
							err = e
							continue
						}
						go func() {
							time.Sleep(time.Second * 10)
							if err = notif.Cancel(); err != nil {
								log.Printf("failed cancelling: %v", err)
							}
						}()
					}
				}()
			}
		}
	}
}

A gio-extras/niotify/hello_macos.go => gio-extras/niotify/hello_macos.go +7 -0
@@ 0,0 1,7 @@
//+build darwin

//go:generate mkdir -p example.app/Contents/MacOS
//go:generate go build -o example.app/Contents/MacOS/example
//go:generate codesign -s - example.app

package main

M go.mod => go.mod +1 -0
@@ 6,6 6,7 @@ require (
	gioui.org v0.0.0-20201211172859-bd7bb4d5d2f3
	git.sr.ht/~whereswaldon/colorpicker v0.0.0-20201207220634-905cd7cc7248
	git.sr.ht/~whereswaldon/haptic v0.0.0-20201207220958-78675dee81dd
	git.sr.ht/~whereswaldon/niotify v0.0.3
	github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7
	github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4
	github.com/google/go-github/v24 v24.0.1

M go.sum => go.sum +8 -0
@@ 1,5 1,6 @@
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
gioui.org v0.0.0-20200619180744-e2f3bbdfc367/go.mod h1:jiUwifN9cRl/zmco43aAqh0aV+s9GbhG13KcD+gEpkU=
gioui.org v0.0.0-20201206220452-acc3f704e478/go.mod h1:Y+uS7hHMvku1Q+ooaoq6fYD5B2LGoT8JtFgvmYmRzTw=
gioui.org v0.0.0-20201211172859-bd7bb4d5d2f3 h1:MeGkzCHegIlIebxPbC+I1xwNQ7vjTYPxZQ6lzrJydSg=
gioui.org v0.0.0-20201211172859-bd7bb4d5d2f3/go.mod h1:Y+uS7hHMvku1Q+ooaoq6fYD5B2LGoT8JtFgvmYmRzTw=


@@ 7,15 8,22 @@ git.sr.ht/~whereswaldon/colorpicker v0.0.0-20201207220634-905cd7cc7248 h1:sI70yH
git.sr.ht/~whereswaldon/colorpicker v0.0.0-20201207220634-905cd7cc7248/go.mod h1:6dPWP8F87bsIhQuwg0l5hH0TSDyk414e1xe3q+8BUho=
git.sr.ht/~whereswaldon/haptic v0.0.0-20201207220958-78675dee81dd h1:xTijdESZL/kM3nS7v/N1yJ/X8eInbsyqDLOz9ZFHpsE=
git.sr.ht/~whereswaldon/haptic v0.0.0-20201207220958-78675dee81dd/go.mod h1:lFvegCF1P7IXfv5FpnnvKFdoAQWTgJZhx8aWOBgE0yg=
git.sr.ht/~whereswaldon/niotify v0.0.3 h1:EWRqPOzqTLU92A9h207LkS/U/nQxuawJ0PF7UEDApi0=
git.sr.ht/~whereswaldon/niotify v0.0.3/go.mod h1:itJ9vAQqq8+liURizx7mAdIY4o8gRDF6SAVfswYVg1U=
git.wow.st/gmp/jni v0.0.0-20200619201040-d0d3f316ae09/go.mod h1:lfKZKu2afBKJODTFgDNIaBfhq6qmQS0xsS/phLO5Urk=
git.wow.st/gmp/jni v0.0.0-20200827154156-014cd5c7c4c0 h1:Ynp3h+TC8k1clvf45D28VFQlmy0bPx8M/MG5bB24Vj8=
git.wow.st/gmp/jni v0.0.0-20200827154156-014cd5c7c4c0/go.mod h1:+axXBRUTIDlCeE73IKeD/os7LoEnTKdkp8/gQOFjqyo=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/esiqveland/notify v0.9.1 h1:hX6ZD3FCQJXI46AzUM/iWekcMfnZ9TPE4uIu9Hrn1D4=
github.com/esiqveland/notify v0.9.1/go.mod h1:63UbVSaeJwF0LVJARHFuPgUAoM7o1BEvCZyknsuonBc=
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw=
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 h1:QbL/5oDUmRBzO9/Z7Seo6zf912W/a6Sr4Eu0G/3Jho0=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4 h1:WtGNWLvXpe6ZudgnXrq0barxBImvnnJoMEhXAzcbM0I=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME=
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=