From 790d7ace6c5d1a2a6b78608a3462c9be6ff6de47 Mon Sep 17 00:00:00 2001 From: makeworld Date: Tue, 7 Dec 2021 17:40:50 -0500 Subject: [PATCH] Windows uses paths set by `XDG` variables over `APPDATA` if they are set Fixes #255 --- CHANGELOG.md | 1 + config/config.go | 21 ++++++++------------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8eb47a6..90d24a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Default search engine changed to geminispace.info from gus.guru - The user's terminal theme colors are used by default (#181) - By default, non-gemini URI schemes are opened in the default application. This requires a config change for previous users, see the [wiki](https://github.com/makeworld-the-better-one/amfora/wiki/Handling-Other-URL-Schemes) (#207) +- Windows uses paths set by `XDG` variables over `APPDATA` if they are set (#255) ## Removed - Favicon support (#199) diff --git a/config/config.go b/config/config.go index 4ff29c9..f45e893 100644 --- a/config/config.go +++ b/config/config.go @@ -68,6 +68,8 @@ var hasDarkTerminalBackground bool func Init() error { // *** Set paths *** + // Windows uses paths under APPDATA, Unix systems use XDG paths + // Windows systems use XDG paths if variables are defined, see #255 home, err := homedir.Dir() if err != nil { @@ -84,10 +86,10 @@ func Init() error { } // Store config directory and file paths - if runtime.GOOS == "windows" { + if runtime.GOOS == "windows" && os.Getenv("XDG_CONFIG_HOME") == "" { configDir = amforaAppData } else { - // Unix / POSIX system + // Unix / POSIX system, or Windows with XDG_CONFIG_HOME defined configDir = filepath.Join(basedir.ConfigHome, "amfora") } configPath = filepath.Join(configDir, "config.toml") @@ -100,7 +102,7 @@ func Init() error { } // Store TOFU db directory and file paths - if runtime.GOOS == "windows" { + if runtime.GOOS == "windows" && os.Getenv("XDG_CACHE_HOME") == "" { // Windows just stores it in APPDATA along with other stuff tofuDBDir = amforaAppData } else { @@ -110,7 +112,7 @@ func Init() error { tofuDBPath = filepath.Join(tofuDBDir, "tofu.toml") // Store bookmarks dir and path - if runtime.GOOS == "windows" { + if runtime.GOOS == "windows" && os.Getenv("XDG_DATA_HOME") == "" { // Windows just keeps it in APPDATA along with other Amfora files bkmkDir = amforaAppData } else { @@ -121,19 +123,12 @@ func Init() error { BkmkPath = filepath.Join(bkmkDir, "bookmarks.xml") // Feeds dir and path - if runtime.GOOS == "windows" { + if runtime.GOOS == "windows" && os.Getenv("XDG_DATA_HOME") == "" { // In APPDATA beside other Amfora files subscriptionDir = amforaAppData } else { - //nolint:revive // XDG data dir on POSIX systems - xdg_data, ok := os.LookupEnv("XDG_DATA_HOME") - if ok && strings.TrimSpace(xdg_data) != "" { - subscriptionDir = filepath.Join(xdg_data, "amfora") - } else { - // Default to ~/.local/share/amfora - subscriptionDir = filepath.Join(home, ".local", "share", "amfora") - } + subscriptionDir = filepath.Join(basedir.DataHome, "amfora") } SubscriptionPath = filepath.Join(subscriptionDir, "subscriptions.json")