From 87d2a74db08b9d3944a5476b41591d37b7044e6c Mon Sep 17 00:00:00 2001 From: piotr Date: Wed, 21 Sep 2022 00:32:29 +0200 Subject: [PATCH] fix setting data dir #69 --- main.go | 11 +++++++++-- tools.go | 12 +----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 29be04b..52882bf 100644 --- a/main.go +++ b/main.go @@ -243,7 +243,10 @@ func main() { // 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")) + err := copyFile("/usr/share/nwg-drawer/drawer.css", filepath.Join(configDirectory, "drawer.css")) + if err != nil { + log.Errorf("Failed copying 'drawer.css' file: %s", err) + } } cacheDirectory := cacheDir() @@ -312,7 +315,11 @@ func main() { log.Infof("User demanded theme: %s", *gtkTheme) } } else { - settings.SetProperty("gtk-application-prefer-dark-theme", true) + err := settings.SetProperty("gtk-application-prefer-dark-theme", true) + if err != nil { + log.Error("Error setting 'gtk-application-prefer-dark-theme' property") + return + } log.Info("Preferring dark theme variants") } diff --git a/tools.go b/tools.go index 9dc8a20..840182e 100644 --- a/tools.go +++ b/tools.go @@ -213,13 +213,6 @@ 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") - } - return "/usr/share/" -} - func getAppDirs() []string { var dirs []string xdgDataDirs := "" @@ -300,16 +293,13 @@ func listDesktopFiles() []string { } func setUpCategories() { - p := filepath.Join(getDataHome(), "nwg-drawer/desktop-directories") - log.Debugf("Desktop dirs location: %s", p) var other category for _, cName := range categoryNames { fileName := fmt.Sprintf("%s.directory", cName) - fp := filepath.Join(p, fileName) + fp := filepath.Join("/usr/share/nwg-drawer/desktop-directories", fileName) lines, err := loadTextFile(fp) if err == nil { - log.Debugf("Opened file '%s'", fp) var cat category cat.Name = cName