Skip to content

Commit

Permalink
Fix error when ActivationType not set [#5]
Browse files Browse the repository at this point in the history
This also fixes issues where people using go-toast pre-v1 would no longer have audio.
  • Loading branch information
jmshal committed Sep 27, 2016
1 parent 982a5f7 commit a15160c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions toast.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const (
LoopingCall8 = "ms-winsoundevent:Notification.Looping.Call8"
LoopingCall9 = "ms-winsoundevent:Notification.Looping.Call9"
LoopingCall10 = "ms-winsoundevent:Notification.Looping.Call10"
Silent = ""
Silent = "silent"
)

type toastDuration string
Expand Down Expand Up @@ -82,7 +82,7 @@ $template = @"
{{end}}
</binding>
</visual>
{{if .Audio}}
{{if ne .Audio "silent"}}
<audio src="{{.Audio}}" loop="{{.Loop}}" />
{{else}}
<audio silent="true" />
Expand Down Expand Up @@ -192,6 +192,18 @@ type Action struct {
Arguments string
}

func (n *Notification) applyDefaults() {
if n.ActivationType == "" {
n.ActivationType = "protocol"
}
if n.Duration == "" {
n.Duration = Short
}
if n.Audio == "" {
n.Audio = Default
}
}

func (n *Notification) buildXML() (string, error) {
var out bytes.Buffer
err := toastTemplate.Execute(&out, n)
Expand Down Expand Up @@ -221,7 +233,11 @@ func (n *Notification) buildXML() (string, error) {
// log.Fatalln(err)
// }
func (n *Notification) Push() error {
xml, _ := n.buildXML()
n.applyDefaults()
xml, err := n.buildXML()
if err != nil {
return err
}
return invokeTemporaryScript(xml)
}

Expand Down

0 comments on commit a15160c

Please sign in to comment.