Skip to content

Commit

Permalink
refactor: change folder location for Backup and Extracted (#3282)
Browse files Browse the repository at this point in the history
  • Loading branch information
UnaTried authored Feb 3, 2025
1 parent f1fc842 commit bc37b7c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
var (
spicetifyFolder = utils.GetSpicetifyFolder()
rawFolder, themedFolder = getExtractFolder()
backupFolder = utils.GetUserFolder("Backup")
backupFolder = utils.GetStateFolder("Backup")
userThemesFolder = utils.GetUserFolder("Themes")
quiet bool
isAppX = false
Expand Down Expand Up @@ -205,7 +205,7 @@ func GetSpotifyPath() string {
}

func getExtractFolder() (string, string) {
dir := utils.GetUserFolder("Extracted")
dir := utils.GetStateFolder("Extracted")

raw := filepath.Join(dir, "Raw")
utils.CheckExistAndCreate(raw)
Expand Down
30 changes: 30 additions & 0 deletions src/utils/path-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,36 @@ func GetSpicetifyFolder() string {
return result
}

func GetStateFolder(name string) string {
result, isAvailable := os.LookupEnv("SPICETIFY_STATE")
defer func() { CheckExistAndCreate(result) }()

if isAvailable && len(result) > 0 {
return result
}

if runtime.GOOS == "windows" {
parent := os.Getenv("APPDATA")

result = filepath.Join(parent, "spicetify")
} else if runtime.GOOS == "linux" {
parent, isAvailable := os.LookupEnv("XDG_STATE_HOME")

if !isAvailable || len(parent) == 0 {
parent = filepath.Join(os.Getenv("HOME"), ".local", "state")
CheckExistAndCreate(parent)
}

result = filepath.Join(parent, "spicetify")
} else if runtime.GOOS == "darwin" {
parent := filepath.Join(os.Getenv("HOME"), ".local", "state")
CheckExistAndCreate(parent)

result = filepath.Join(parent, "spicetify")
}
return result
}

// getUserFolder checks if folder `name` is available in spicetifyFolder,
// else creates then returns the path.
func GetUserFolder(name string) string {
Expand Down

0 comments on commit bc37b7c

Please sign in to comment.