aboutsummaryrefslogtreecommitdiffstats
path: root/notifier_linux.go
blob: 69b32cb133721cc4593a088548950c59933a7b89 (plain)
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
// Copyright 2016 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.

package notifier

import (
	"fmt"
	"os/exec"
)

type linuxNotifier struct{}

// NewNotifier constructs notifier for Linux
func NewNotifier() (Notifier, error) {
	return &linuxNotifier{}, nil
}

// DeliverNotification sends a notification
func (n linuxNotifier) DeliverNotification(notification Notification) error {
	args := []string{}
	if notification.ImagePath != "" {
		args = append(args, "-i", notification.ImagePath)
	}
	args = append(args, notification.Title)
	args = append(args, notification.Message)
	cmd := exec.Command("notify-send", args...)
	if cmd == nil {
		return fmt.Errorf("No command")
	}
	_, err := cmd.Output()
	if err != nil {
		return fmt.Errorf("Error running command: %s", err)
	}
	return nil
}