-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathbeeep.go
More file actions
55 lines (43 loc) · 1 KB
/
beeep.go
File metadata and controls
55 lines (43 loc) · 1 KB
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
53
54
55
// Package beeep provides a cross-platform library for sending desktop notifications and beeps.
package beeep
import (
"fmt"
"os"
"path/filepath"
"runtime"
"time"
)
var (
// ErrUnsupported is returned when an operating system is not supported.
ErrUnsupported = fmt.Errorf("beeep: unsupported operating system: %s", runtime.GOOS)
)
// AppName is the name of app.
// This should be the application's formal name, rather than some sort of ID.
var AppName = "DefaultAppName"
// timeout is notification duration (where applicable).
var timeout = time.Second * 5
func pathAbs(path string) string {
var err error
var abs string
if path != "" {
abs, err = filepath.Abs(path)
if err != nil {
abs = path
}
}
return abs
}
func bytesToFilename(data []byte) (string, error) {
var out string
tmp, err := os.CreateTemp(os.TempDir(), "beeep*.png")
if err != nil {
return out, err
}
defer tmp.Close()
_, err = tmp.Write(data)
if err != nil {
return out, err
}
out = tmp.Name()
return out, nil
}