From ddff6cf1aae8e6e81e4e0023922b73a00dbcb137 Mon Sep 17 00:00:00 2001 From: Ashwani Sharma Date: Sat, 5 Nov 2022 12:28:37 +0530 Subject: [PATCH] feat!: unsupported config updater --- configs/config.toml | 38 -------------------------------------- internal/config.go | 22 ++++++++++++++-------- internal/nitrogen.go | 2 +- 3 files changed, 15 insertions(+), 47 deletions(-) delete mode 100644 configs/config.toml diff --git a/configs/config.toml b/configs/config.toml deleted file mode 100644 index 4c1ff42..0000000 --- a/configs/config.toml +++ /dev/null @@ -1,38 +0,0 @@ -title = "OpenRWC Configuration" -version = "0.0.2" - -[reddit] -subreddits = ["wallpaper", "wallpapers", "Animewallpaper", "AnimeWallpapersSFW", "MinimalWallpaper"] -# one of (hour, day, week, month, year, all) -sort = "hour" -# custom query in addition to openrwc.resolution -query = "" - -[openrwc] -# Wallpapert resulutions to search for -# The wallpaper resolution may not always need to match your display resolution -resolutions = [ - "7680x4320", "3840x2160", "1920x1080", "1366x768", "1280x720" - ] - -max_attempts = 50 -# Number of monitors. Same wallpaper will be set on each monitors -monitors=2 - -# Software used to set the wallpaper. One of ("nitrogen", "kde") -util = "kde" -# Util parameter. -# Examples: -# nitrogen: one of ("set-auto", "set-centered", "set-scaled", "set-tiled", "set-zoom" , "set-zoom-fill") -# KDE: -util_param = "set-scaled" - - [openrwc.timeout] - # s=seconds,m=minutes,h=hours,d=days - - # HTTP call - call = "15s" - # Wallpaper refresh frequency. Minimum "2s". - refresh = "1h" - # Retry delay if previous query fails. Minimum "2s". - retry = "5s" diff --git a/internal/config.go b/internal/config.go index 5ad0a10..fb8b4f5 100644 --- a/internal/config.go +++ b/internal/config.go @@ -12,6 +12,7 @@ package internal import ( + "fmt" "os" log "github.com/sirupsen/logrus" @@ -21,7 +22,8 @@ import ( // LoadConfig Load configuration and return the path of config directory func LoadConfig() string { // Load config - path := "configs" + home, _ := os.UserHomeDir() + path := home + "/.config/OpenRWC" file := "config" if _, err := os.Stat(path + "/" + file + ".toml"); os.IsNotExist(err) { path, file := createDefaultConfig() @@ -32,16 +34,21 @@ func LoadConfig() string { } return path } else { - pwd, pwdErr := os.Getwd() - if pwdErr != nil { - log.Fatal(pwdErr) - } - path = pwd + "/" + path setupViper(path, file, "toml") // Usually location in project err := viper.ReadInConfig() if err != nil { log.Fatal(err.Error()) } + if viper.GetString("version") != "0.0.2" { // set supported configuration version + log.Warnf(fmt.Sprintf("Installed configuration version (\"%s\") is unsupported. It is backed up with `.old` extension!", viper.GetString("version"))) + old := path + "/" + file + ".toml" + backup := path + "/" + file + ".toml.old" + err := os.Rename(old, backup) + if nil != err { + log.Fatal(err) + } + return LoadConfig() + } return path } } @@ -105,8 +112,7 @@ util_param = "set-scaled" log.Fatal(openError) } defer f.Close() - output, writeError := f.WriteString(template) - log.Infof(string(output)) + _, writeError := f.WriteString(template) if writeError != nil { log.Fatal(writeError) } diff --git a/internal/nitrogen.go b/internal/nitrogen.go index 1543ee1..565aefd 100644 --- a/internal/nitrogen.go +++ b/internal/nitrogen.go @@ -23,7 +23,7 @@ import ( func NitrogenChange(wallpaper string) error { monitors := viper.GetInt("openrwc.monitors") for i := 0; i < monitors; i++ { - _, err := exec.Command("nitrogen", "--"+viper.GetString("openrwc.nitrogen_param"), + _, err := exec.Command("nitrogen", "--"+viper.GetString("openrwc.util_param"), wallpaper, fmt.Sprintf("--head=%d", i)).Output() if nil != err { return err