go-toast

Send toast notifications in Windows
Log | Files | Refs | README | LICENSE

README.md (1905B)


      1 # go-toast
      2 
      3 This package implements Windows toast notifications using the Windows Runtime COM API. 
      4 
      5 The XML schema used to describe such notifications is here: 
      6 
      7 https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/adaptive-interactive-toasts
      8 
      9 Package `wintoast` offers a lower-level api.
     10 Package `toast` offers a higher-level wrapper. 
     11 
     12 `wintoast` uses build tags to guard Windows only code. It will still compile on 
     13 non-Windows platforms, however the functions are stubbed out and will do nothing 
     14 when invoked. 
     15 
     16 ## Usage
     17 
     18 ### Basic
     19 
     20 ```go
     21 noti := toast.Notification{
     22     AppID: "My cool app",
     23     Title: "Title",
     24     Body: "Body",
     25 }
     26 
     27 err := noti.Push()
     28 ```
     29 
     30 ### Actions / Inputs with Callback
     31 
     32 Additionally, we can respond to notification activation with a callback. 
     33 
     34 ```go
     35 // Set the callback that receives the data from the notification.
     36 // Any data from actions or inputs will be accessible here. 
     37 toast.SetActivationCallback(func(args string, data []UserData) {
     38     fmt.Printf("args: %q, data: %v\n", args, data)
     39 })
     40 
     41 n := toast.Notification{
     42     AppID: "My cool app",
     43     Title: "Title",
     44     Body: "Body", 
     45 }
     46 
     47 n.Inputs = append(n.Inputs, toast.Input{
     48 	ID:          "reply-to:john-doe",
     49 	Title:       "Reply",
     50 	Placeholder: "Reply to John Doe",
     51 })
     52 
     53 n.Inputs = append(n.Inputs, toast.Input{
     54 	ID:          "select-action",
     55 	Title:       "Selection Action",
     56 	Placeholder: "Pick an action to perform",
     57 	Selections: []toast.InputSelection{
     58 		{
     59 			ID:      "1",
     60 			Content: "do thing one",
     61 		},
     62 		{
     63 			ID:      "2",
     64 			Content: "do thing two",
     65 		},
     66 		{
     67 			ID:      "3",
     68 			Content: "do thing three",
     69 		},
     70 	},
     71 })
     72 
     73 n.Actions = append(n.Actions, toast.Action{
     74 	Type:      toast.Foreground,
     75 	Content:   "Send",
     76 	Arguments: "send",
     77 })
     78 
     79 n.Actions = append(n.Actions, toast.Action{
     80 	Type:      toast.Foreground,
     81 	Content:   "Close",
     82 	Arguments: "close",
     83 })
     84 
     85 err := n.Push()
     86 ```