github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/pkg/mac/notification_darwin.go (about)

     1  // Package mac provides MacOS related utility functions for Wails applications
     2  package mac
     3  
     4  import (
     5  	"fmt"
     6  
     7  	"github.com/AlpineAIO/wails/v2/internal/shell"
     8  	"github.com/pkg/errors"
     9  )
    10  
    11  // StartAtLogin will either add or remove this application to/from the login
    12  // items, depending on the given boolean flag. The limitation is that the
    13  // currently running app must be in an app bundle.
    14  func ShowNotification(title string, subtitle string, message string, sound string) error {
    15  	command := fmt.Sprintf("display notification \"%s\"", message)
    16  	if len(title) > 0 {
    17  		command += fmt.Sprintf(" with title \"%s\"", title)
    18  	}
    19  	if len(subtitle) > 0 {
    20  		command += fmt.Sprintf(" subtitle \"%s\"", subtitle)
    21  	}
    22  	if len(sound) > 0 {
    23  		command += fmt.Sprintf(" sound name \"%s\"", sound)
    24  	}
    25  	_, stde, err := shell.RunCommand("/tmp", "osascript", "-e", command)
    26  	if err != nil {
    27  		return errors.Wrap(err, stde)
    28  	}
    29  	return nil
    30  }