aboutsummaryrefslogtreecommitdiffstats
path: root/notifier_windows.go
blob: 60a88f0875b1df62c94d0bde11e5cf1cca4a5710 (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
36
37
38
39
40
41
42
43
44
// 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 windowsNotifier struct{}

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

// DeliverNotification sends a notification
func (n windowsNotifier) DeliverNotification(notification Notification) error {
	args := []string{}

	if notification.Title != "" {
		args = append(args, "-t", notification.Title)
	}
	if notification.Message != "" {
		args = append(args, "-m", notification.Message)
	}
	if notification.ImagePath != "" {
		args = append(args, "-p", notification.ImagePath)
	}

	// For testing
	// toastPath := filepath.Join(os.Getenv("GOPATH"), "src/github.com/keybase/go-osnotify/toaster/toast.exe")

	cmd := exec.Command(notification.ToastPath, 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
}