File: desktop_notifications_darwin.go

package info (click to toggle)
coyim 0.3.7-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,064 kB
  • ctags: 4,528
  • sloc: xml: 5,120; sh: 328; python: 286; makefile: 235; ruby: 51
file content (52 lines) | stat: -rw-r--r-- 1,067 bytes parent folder | download
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
}