...
1 package desktop
2
3 import (
4 "os"
5 "path"
6 "path/filepath"
7 "strings"
8 )
9
10
11 func DataDirs() []string {
12 var dataDirs []string
13
14 homeDir := os.Getenv("HOME")
15 if strings.TrimSpace(homeDir) == "" {
16 homeDir = "~/"
17 }
18 dataHomeSetting := os.Getenv("XDG_DATA_HOME")
19 if dataHomeSetting == "" {
20 dataHomeSetting = path.Join(homeDir, ".local/share")
21 }
22 dataDirs = append(dataDirs, filepath.Join(dataHomeSetting, "applications"))
23
24 dataDirsSetting := strings.Split(os.Getenv("XDG_DATA_DIRS"), ":")
25 for _, dataDir := range dataDirsSetting {
26 dataDir = strings.TrimSpace(dataDir)
27 if dataDir == "" {
28 continue
29 }
30
31 dataDirs = append(dataDirs, filepath.Join(dataDir, "applications"))
32 }
33 if len(dataDirs) == 1 {
34 dataDirs = append(dataDirs, "/usr/local/share/applications", "/usr/share/applications")
35 }
36
37 return dataDirs
38 }
39
View as plain text