main.go (2503B)
1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "time" 7 8 "git.sr.ht/~jackmordaunt/go-toast/v2" 9 ) 10 11 func main() { 12 var ( 13 n toast.Notification 14 wait bool 15 showActions bool 16 ) 17 18 flag.StringVar(&n.AppID, "app-id", "com.windows.toast.cli", "Application ID that identifies this app") 19 flag.StringVar(&n.Title, "title", "title", "Title") 20 flag.StringVar(&n.Body, "body", "body", "Body") 21 flag.StringVar(&n.Icon, "icon", "", "Icon") 22 flag.StringVar(&n.ActivationType, "activation-type", toast.Foreground, "Activation Type [protocol, foreground, background]") 23 flag.StringVar(&n.ActivationArguments, "activation-args", "", "Activation Arguments") 24 flag.StringVar(&n.Audio, "audio", "", "Audio to play when displaying the toast") 25 flag.StringVar(&n.ActivationExe, "activation-exe", "", "path to activation executable") 26 flag.BoolVar(&n.Loop, "loop", false, "Loop audio") 27 flag.StringVar(&n.Duration, "duration", "short", "Audio duration") 28 29 flag.BoolVar(&wait, "wait", false, "Wait for activation") 30 flag.BoolVar(&showActions, "demo-actions", false, "Display preconfigured actions for demonstration") 31 32 flag.Parse() 33 34 n.Inputs = append(n.Inputs, toast.Input{ 35 ID: "reply-to:john-doe", 36 Title: "Reply", 37 Placeholder: "Reply to John Doe", 38 }) 39 40 n.Inputs = append(n.Inputs, toast.Input{ 41 ID: "select-action", 42 Title: "Selection Action", 43 Placeholder: "Pick an action to perform", 44 Selections: []toast.InputSelection{ 45 { 46 ID: "1", 47 Content: "do thing one", 48 }, 49 { 50 ID: "2", 51 Content: "do thing two", 52 }, 53 { 54 ID: "3", 55 Content: "do thing three", 56 }, 57 }, 58 }) 59 60 n.Actions = append(n.Actions, toast.Action{ 61 Type: toast.Foreground, 62 Content: "Send", 63 Arguments: "send", 64 }) 65 n.Actions = append(n.Actions, toast.Action{ 66 Type: toast.Foreground, 67 Content: "Close", 68 Arguments: "close", 69 }) 70 71 if wait { 72 // Dummy goroutine to stop the runtime from thinking we are deadlocked when 73 // waiting on C code to call us back. 74 go func() { 75 for range time.NewTicker(time.Second).C { 76 } 77 }() 78 79 done := make(chan struct{}) 80 defer func() { 81 <-done 82 }() 83 84 toast.SetActivationCallback(func(args string, data []toast.UserData) { 85 fmt.Printf("OnActivate args: %q, userdata: %v\n", args, data) 86 done <- struct{}{} 87 }) 88 89 } else { 90 toast.SetActivationCallback(func(_ string, _ []toast.UserData) { 91 fmt.Printf("OnActivate\n") 92 }) 93 } 94 95 if err := n.Push(); err != nil { 96 fmt.Printf("error: %v\n", err) 97 } 98 }