Notifications (linux).

This commit is contained in:
Nuno Cruces 2020-01-26 16:31:23 +00:00
parent c2c09ddd32
commit bcfacfe62f
3 changed files with 37 additions and 8 deletions

View file

@ -48,13 +48,13 @@ func message(kind messageKind, text string, options []Option) (bool, error) {
} }
switch opts.icon { switch opts.icon {
case ErrorIcon: case ErrorIcon:
args = append(args, "--icon-name=dialog-error") args = append(args, "--window-icon=error", "--icon-name=dialog-error")
case WarningIcon: case WarningIcon:
args = append(args, "--icon-name=dialog-warning") args = append(args, "--window-icon=warning", "--icon-name=dialog-warning")
case InfoIcon: case InfoIcon:
args = append(args, "--icon-name=dialog-information") args = append(args, "--window-icon=info", "--icon-name=dialog-information")
case QuestionIcon: case QuestionIcon:
args = append(args, "--icon-name=dialog-question") args = append(args, "--window-icon=question", "--icon-name=dialog-question")
} }
out, err := zenutil.Run(args) out, err := zenutil.Run(args)

View file

@ -3,8 +3,8 @@ package zenity_test
import "github.com/ncruces/zenity" import "github.com/ncruces/zenity"
func ExampleNotify() { func ExampleNotify() {
zenity.Notify("An error has occurred.", zenity.Notify("There are system updates necessary!",
zenity.Title("Error"), zenity.Title("Warning"),
zenity.Icon(zenity.ErrorIcon)) zenity.Icon(zenity.InfoIcon))
// Output: // Output:
} }

View file

@ -2,6 +2,35 @@
package zenity package zenity
import (
"github.com/ncruces/zenity/internal/zenutil"
)
func notify(text string, options []Option) error { func notify(text string, options []Option) error {
panic("not implemented") opts := applyOptions(options)
args := []string{"--notification"}
if text != "" {
args = append(args, "--text", text, "--no-markup")
}
if opts.title != "" {
args = append(args, "--title", opts.title)
}
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")
}
_, err := zenutil.Run(args)
if err != nil {
return err
}
return nil
} }