forked from eyasliu/desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
46 lines (41 loc) · 885 Bytes
/
util.go
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
package desktop
import (
"crypto/md5"
"encoding/hex"
"io/ioutil"
"os"
"path/filepath"
"runtime"
)
func iconBytesToFilePath(iconBytes []byte) (string, error) {
bh := md5.Sum(iconBytes)
dataHash := hex.EncodeToString(bh[:])
iconFilePath := filepath.Join(os.TempDir(), "systray_temp_icon_"+dataHash+".ico")
if _, err := os.Stat(iconFilePath); os.IsNotExist(err) {
if err := ioutil.WriteFile(iconFilePath, iconBytes, 0644); err != nil {
return "", err
}
}
return iconFilePath, nil
}
func IsHeadless() bool {
if len(os.Getenv("SSH_CONNECTION")) > 0 {
return true
}
if runtime.GOOS == "windows" {
return false
}
if runtime.GOOS == "darwin" {
return len(os.Getenv("XPC_FLAGS")) == 0
}
if len(os.Getenv("DISPLAY")) == 0 {
return true
}
return false
}
func IsSupportTray() bool {
if IsHeadless() {
return false
}
return runtime.GOOS == "windows"
}