diff --git a/bin/nwg-drawer b/bin/nwg-drawer index edd6712..27e13dc 100755 Binary files a/bin/nwg-drawer and b/bin/nwg-drawer differ diff --git a/main.go b/main.go index 83492ae..0914edb 100644 --- a/main.go +++ b/main.go @@ -208,6 +208,29 @@ func main() { // ENVIRONMENT configDirectory = configDir() + // Placing the drawer config files in the nwg-panel config directory was a mistake. + // Let's move them to their own location. + oldConfigDirectory, err := oldConfigDir() + if err == nil { + for _, p := range []string{"drawer.css", "preferred-apps.json"} { + if pathExists(path.Join(oldConfigDirectory, p)) { + log.Infof("File %s found in stale location, moving to %s", p, configDirectory) + if !pathExists(path.Join(configDirectory, p)) { + err = os.Rename(path.Join(oldConfigDirectory, p), path.Join(configDirectory, p)) + if err == nil { + log.Info("Success") + } else { + log.Warn(err) + } + } else { + log.Warnf("Failed moving %s to %s: path already exists!", path.Join(oldConfigDirectory, p), path.Join(configDirectory, p)) + } + + } + } + } + + // Copy default style sheet if not found if !pathExists(filepath.Join(configDirectory, "drawer.css")) { copyFile(filepath.Join(getDataHome(), "nwg-drawer/drawer.css"), filepath.Join(configDirectory, "drawer.css")) } @@ -241,9 +264,9 @@ func main() { paFile := filepath.Join(configDirectory, "preferred-apps.json") preferredApps, err = loadPreferredApps(paFile) if err != nil { - log.Error(fmt.Sprintf("Custom associations file %s not found or invalid", paFile)) + log.Errorf("Custom associations file %s not found or invalid", paFile) } else { - log.Info(fmt.Sprintf("Found %v associations in %s", len(preferredApps), paFile)) + log.Infof("Found %v associations in %s", len(preferredApps), paFile) } // USER INTERFACE diff --git a/tools.go b/tools.go index deced93..f9bb790 100644 --- a/tools.go +++ b/tools.go @@ -10,6 +10,7 @@ import ( "io/ioutil" "os" "os/exec" + "path" "path/filepath" "regexp" "sort" @@ -149,14 +150,24 @@ func readTextFile(path string) (string, error) { return string(bytes), nil } +func oldConfigDir() (string, error) { + if os.Getenv("XDG_CONFIG_HOME") != "" { + dir := path.Join(os.Getenv("XDG_CONFIG_HOME"), "nwg-panel") + return dir, nil + } + + return "", errors.New("old config dir not found") +} + func configDir() string { if os.Getenv("XDG_CONFIG_HOME") != "" { - dir := fmt.Sprintf("%s/nwg-panel", os.Getenv("XDG_CONFIG_HOME")) + dir := path.Join(os.Getenv("XDG_CONFIG_HOME"), "nwg-drawer") createDir(dir) - return (fmt.Sprintf("%s/nwg-panel", os.Getenv("XDG_CONFIG_HOME"))) + return dir } - dir := fmt.Sprintf("%s/.config/nwg-panel", os.Getenv("HOME")) + dir := path.Join(os.Getenv("XDG_CONFIG_HOME"), "nwg-drawe") createDir(dir) + return dir }