Skip to content

Commit

Permalink
Merge pull request #9 from esiqveland/redesign
Browse files Browse the repository at this point in the history
Redesign
  • Loading branch information
esiqveland authored Feb 11, 2020
2 parents 38bc9e2 + 193e705 commit 76c80de
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 106 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
docker:
# specify the version
- image: circleci/golang:1.12
- image: circleci/golang:1.13

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
Expand All @@ -19,4 +19,4 @@ jobs:
# specify any bash command here prefixed with `run: `
- run: go get -v -t -d ./...
- run: cd example; go build -v
- run: go test -v ./...
- run: go test -v ./...
37 changes: 26 additions & 11 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package main
import (
"fmt"
"log"
"os"
"sync"

"github.com/esiqveland/notify"
"github.com/godbus/dbus/v5"
)

func main() {
wg := &sync.WaitGroup{}

conn, err := dbus.SessionBus()
if err != nil {
Expand Down Expand Up @@ -54,8 +57,26 @@ func main() {
fmt.Printf("Version: %v\n", info.Version)
fmt.Printf("Spec: %v\n", info.SpecVersion)

// Notifyer interface with event delivery
notifier, err := notify.New(conn)
// Listen for actions invoked!
onAction := func(action *notify.ActionInvokedSignal) {
log.Printf("ActionInvoked: %v Key: %v", action.ID, action.ActionKey)
wg.Done()
}

onClosed := func(closer *notify.NotificationClosedSignal) {
log.Printf("NotificationClosed: %v Reason: %v", closer.ID, closer.Reason)
}

// Notifier interface with event delivery
notifier, err := notify.New(
conn,
// action event handler
notify.WithOnAction(onAction),
// closed event handler
notify.WithOnClosed(onClosed),
// override with custom logger
notify.WithLogger(log.New(os.Stdout, "notify: ", log.Flags())),
)
if err != nil {
log.Fatalln(err.Error())
}
Expand All @@ -67,14 +88,8 @@ func main() {
}
log.Printf("sent notification id: %v", id)

// Listen for actions invoked!
actions := notifier.ActionInvoked()
go func() {
action := <-actions
log.Printf("ActionInvoked: %v Key: %v", action.ID, action.ActionKey)
}()

closer := <-notifier.NotificationClosed()
log.Printf("NotificationClosed: %v Reason: %v", closer.ID, closer.Reason)
//outClosed := notifier.NotificationClosed()

wg.Add(2)
wg.Wait()
}
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module github.com/esiqveland/notify

go 1.12
go 1.13

require (
github.com/godbus/dbus v5.0.1+incompatible
github.com/godbus/dbus/v5 v5.0.3
)
require github.com/godbus/dbus/v5 v5.0.3
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
github.com/godbus/dbus v4.1.0+incompatible h1:WqqLRTsQic3apZUK9qC5sGNfXthmPXzUZ7nQPrNITa4=
github.com/godbus/dbus v5.0.1+incompatible h1:fsDsnr/6MFSIm3kl6JJpq5pH+vO/rA5jUunalLnzSc8=
github.com/godbus/dbus v5.0.1+incompatible/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME=
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Loading

0 comments on commit 76c80de

Please sign in to comment.