1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
package gui
import (
"fmt"
"github.com/twstrike/gosx-notifier"
"github.com/twstrike/coyim/ui"
)
var hasBundle = false
const notificationFeaturesSupported = notificationStyles
func init() {
hasBundle = !fileNotFound("/Applications/CoyIM.app/Contents/Info.plist")
}
type desktopNotifications struct {
notificationStyle string
notificationUrgent bool
notificationExpires bool
}
func newDesktopNotifications() *desktopNotifications {
return createDesktopNotifications()
}
func (dn *desktopNotifications) show(jid, from, message string) error {
if dn.notificationStyle == "off" {
return nil
}
from = ui.EscapeAllHTMLTags(string(ui.StripSomeHTML([]byte(from))))
summary, body := dn.format(from, message, false)
note := gosxnotifier.NewNotification(body)
note.Title = summary
note.Group = fmt.Sprintf("im.coy.coyim.%s", from)
if hasBundle {
note.Sender = "im.coy.coyim"
} else {
note.ContentImage = coyimIcon.getPath()
}
err := note.Push()
if err != nil {
return fmt.Errorf("Error showing notification: %v", err)
}
return nil
}
|