zenity/notify_unix.go

34 lines
847 B
Go
Raw Normal View History

2022-03-24 10:37:37 -04:00
//go:build !windows && !darwin
2020-01-26 11:04:49 -05:00
package zenity
2024-07-10 00:06:01 -04:00
import "git.bigun.dev/evan/zenity/internal/zenutil"
2020-01-26 11:31:23 -05:00
2021-03-04 07:42:30 -05:00
func notify(text string, opts options) error {
2021-03-05 08:56:16 -05:00
args := []string{"--notification", "--text", text}
2022-06-02 07:24:24 -04:00
args = appendGeneral(args, opts)
2020-01-26 11:31:23 -05:00
switch opts.icon {
case ErrorIcon:
2021-03-04 08:06:49 -05:00
args = append(args, "--window-icon=dialog-error")
2020-01-26 11:31:23 -05:00
case WarningIcon:
2021-03-04 08:06:49 -05:00
args = append(args, "--window-icon=dialog-warning")
2020-01-26 11:31:23 -05:00
case InfoIcon:
2021-03-04 08:06:49 -05:00
args = append(args, "--window-icon=dialog-information")
2020-01-26 11:31:23 -05:00
case QuestionIcon:
2021-03-04 08:06:49 -05:00
args = append(args, "--window-icon=dialog-question")
2021-03-05 10:14:30 -05:00
case PasswordIcon:
args = append(args, "--window-icon=dialog-password")
case NoIcon:
2022-05-24 07:02:51 -04:00
args = append(args, "--window-icon=")
}
if i, ok := opts.icon.(string); ok {
args = append(args, "--window-icon", i)
2020-01-26 11:31:23 -05:00
}
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
}