zenity/notify_unix.go

37 lines
734 B
Go
Raw Normal View History

2020-01-26 11:04:49 -05:00
// +build !windows,!darwin
package zenity
2020-01-26 11:31:23 -05:00
import (
"github.com/ncruces/zenity/internal/zenutil"
)
2020-01-26 11:04:49 -05:00
func notify(text string, options []Option) error {
2020-01-26 11:31:23 -05:00
opts := applyOptions(options)
args := []string{"--notification"}
if text != "" {
args = append(args, "--text", text, "--no-markup")
}
2021-03-04 07:35:27 -05:00
if opts.title != nil {
args = append(args, "--title", *opts.title)
2020-01-26 11:31:23 -05:00
}
switch opts.icon {
case ErrorIcon:
args = append(args, "--window-icon=error")
case WarningIcon:
args = append(args, "--window-icon=warning")
case InfoIcon:
args = append(args, "--window-icon=info")
case QuestionIcon:
args = append(args, "--window-icon=question")
}
2020-01-28 07:46:43 -05:00
_, err := zenutil.Run(opts.ctx, args)
2020-01-26 11:31:23 -05:00
if err != nil {
return err
}
return nil
2020-01-26 11:04:49 -05:00
}