Windows uses paths set by XDG variables over APPDATA if they are set

Fixes #255
This commit is contained in:
makeworld 2021-12-07 17:40:50 -05:00
parent 043242392c
commit 790d7ace6c
2 changed files with 9 additions and 13 deletions

View File

@ -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 - Default search engine changed to geminispace.info from gus.guru
- The user's terminal theme colors are used by default (#181) - 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) - 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 ## Removed
- Favicon support (#199) - Favicon support (#199)

View File

@ -68,6 +68,8 @@ var hasDarkTerminalBackground bool
func Init() error { func Init() error {
// *** Set paths *** // *** 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() home, err := homedir.Dir()
if err != nil { if err != nil {
@ -84,10 +86,10 @@ func Init() error {
} }
// Store config directory and file paths // Store config directory and file paths
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" && os.Getenv("XDG_CONFIG_HOME") == "" {
configDir = amforaAppData configDir = amforaAppData
} else { } else {
// Unix / POSIX system // Unix / POSIX system, or Windows with XDG_CONFIG_HOME defined
configDir = filepath.Join(basedir.ConfigHome, "amfora") configDir = filepath.Join(basedir.ConfigHome, "amfora")
} }
configPath = filepath.Join(configDir, "config.toml") configPath = filepath.Join(configDir, "config.toml")
@ -100,7 +102,7 @@ func Init() error {
} }
// Store TOFU db directory and file paths // 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 // Windows just stores it in APPDATA along with other stuff
tofuDBDir = amforaAppData tofuDBDir = amforaAppData
} else { } else {
@ -110,7 +112,7 @@ func Init() error {
tofuDBPath = filepath.Join(tofuDBDir, "tofu.toml") tofuDBPath = filepath.Join(tofuDBDir, "tofu.toml")
// Store bookmarks dir and path // 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 // Windows just keeps it in APPDATA along with other Amfora files
bkmkDir = amforaAppData bkmkDir = amforaAppData
} else { } else {
@ -121,19 +123,12 @@ func Init() error {
BkmkPath = filepath.Join(bkmkDir, "bookmarks.xml") BkmkPath = filepath.Join(bkmkDir, "bookmarks.xml")
// Feeds dir and path // Feeds dir and path
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" && os.Getenv("XDG_DATA_HOME") == "" {
// In APPDATA beside other Amfora files // In APPDATA beside other Amfora files
subscriptionDir = amforaAppData subscriptionDir = amforaAppData
} else { } else {
//nolint:revive
// XDG data dir on POSIX systems // XDG data dir on POSIX systems
xdg_data, ok := os.LookupEnv("XDG_DATA_HOME") subscriptionDir = filepath.Join(basedir.DataHome, "amfora")
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")
}
} }
SubscriptionPath = filepath.Join(subscriptionDir, "subscriptions.json") SubscriptionPath = filepath.Join(subscriptionDir, "subscriptions.json")