Skip to content

Commit

Permalink
Merge pull request #36 from JoelleJS/fix/issue-35
Browse files Browse the repository at this point in the history
Fix issue #35
  • Loading branch information
nwg-piotr authored May 14, 2024
2 parents f9cca5d + 432b82a commit fcd2858
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,10 @@ func main() {
}
}

dataHome = getDataHome()
dataHome, err = getDataHome()
if err != nil {
log.Fatal("Error getting data directory:", err)
}
configDirectory = configDir()
// if it doesn't exist:
createDir(configDirectory)
Expand Down
29 changes: 24 additions & 5 deletions tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func createPixbuf(icon string, size int) (*gdk.Pixbuf, error) {

func cacheDir() string {
if os.Getenv("XDG_CACHE_HOME") != "" {
return os.Getenv("XDG_CONFIG_HOME")
return os.Getenv("XDG_CACHE_HOME")
}
if os.Getenv("HOME") != "" && pathExists(filepath.Join(os.Getenv("HOME"), ".cache")) {
p := filepath.Join(os.Getenv("HOME"), ".cache")
Expand Down Expand Up @@ -474,11 +474,30 @@ func copyFile(src, dst string) error {
return os.Chmod(dst, srcinfo.Mode())
}

func getDataHome() string {
if os.Getenv("XDG_DATA_HOME") != "" {
return os.Getenv("XDG_DATA_HOME")
func getDataHome() (string, error) {
var dirs []string
home := os.Getenv("HOME")
xdgDataHome := os.Getenv("XDG_DATA_HOME")
if xdgDataHome != "" {
dirs = append(dirs, xdgDataHome)
} else if home != "" {
dirs = append(dirs, filepath.Join(home, ".local/share"))
}

var xdgDataDirs []string
if os.Getenv("XDG_DATA_DIRS") != "" {
xdgDataDirs = strings.Split(os.Getenv("XDG_DATA_DIRS"), ":")
} else {
xdgDataDirs = []string{"/usr/local/share/", "/usr/share/"}
}
dirs = append(dirs, xdgDataDirs...)

for _, d := range dirs {
if pathExists(filepath.Join(d, "nwg-dock-hyprland")) {
return d, nil
}
}
return "/usr/share/"
return "", errors.New("no data directory found for nwg-dock-hyprland")
}

func getAppDirs() []string {
Expand Down

0 comments on commit fcd2858

Please sign in to comment.