Skip to content

Commit

Permalink
feat: patch only xpui.js on Spotify 1.2.57 and higher
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri committed Feb 8, 2025
1 parent 7a53725 commit f345385
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
22 changes: 19 additions & 3 deletions src/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/spicetify/cli/src/utils"
Expand Down Expand Up @@ -36,9 +37,6 @@ func AdditionalOptions(appsFolderPath string, flags Flag) {
insertSidebarConfig,
insertHomeConfig,
},
filepath.Join(appsFolderPath, "xpui", "vendor~xpui.js"): {
insertExpFeatures,
},
filepath.Join(appsFolderPath, "xpui", "home-v2.js"): {
insertHomeConfig,
},
Expand All @@ -47,6 +45,24 @@ func AdditionalOptions(appsFolderPath string, flags Flag) {
},
}

verParts := strings.Split(flags.SpotifyVer, ".")
spotifyMajor, spotifyMinor, spotifyPatch := 0, 0, 0
if len(verParts) > 0 {
spotifyMajor, _ = strconv.Atoi(verParts[0])
}
if len(verParts) > 1 {
spotifyMinor, _ = strconv.Atoi(verParts[1])
}
if len(verParts) > 2 {
spotifyPatch, _ = strconv.Atoi(verParts[2])
}

if spotifyMajor >= 1 && spotifyMinor >= 2 && spotifyPatch >= 57 {
filesToModified[filepath.Join(appsFolderPath, "xpui", "xpui.js")] = append(filesToModified[filepath.Join(appsFolderPath, "xpui", "xpui.js")], insertExpFeatures)
} else {
filesToModified[filepath.Join(appsFolderPath, "xpui", "vendor~xpui.js")] = []func(string, Flag){insertExpFeatures}
}

for file, calls := range filesToModified {
if _, err := os.Stat(file); os.IsNotExist(err) {
continue
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ Modded Spotify cannot be launched using original Shortcut/Start menu tile. To co
DisableSentry: preprocSection.Key("disable_sentry").MustBool(false),
DisableLogging: preprocSection.Key("disable_ui_logging").MustBool(false),
RemoveRTL: preprocSection.Key("remove_rtl_rule").MustBool(false),
ExposeAPIs: preprocSection.Key("expose_apis").MustBool(false)},
ExposeAPIs: preprocSection.Key("expose_apis").MustBool(false),
SpotifyVer: utils.GetSpotifyVersion(prefsPath)},
)
utils.PrintGreen("OK")

Expand Down
20 changes: 19 additions & 1 deletion src/preprocess/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Flag struct {
RemoveRTL bool
// ExposeAPIs leaks some Spotify's API, functions, objects to Spicetify global object.
ExposeAPIs bool
SpotifyVer string
}

func readRemoteCssMap(tag string, cssTranslationMap *map[string]string) error {
Expand Down Expand Up @@ -82,6 +83,18 @@ func Start(version string, extractedAppsPath string, flags Flag) {
readLocalCssMap(&cssTranslationMap)
}

verParts := strings.Split(flags.SpotifyVer, ".")
spotifyMajor, spotifyMinor, spotifyPatch := 0, 0, 0
if len(verParts) > 0 {
spotifyMajor, _ = strconv.Atoi(verParts[0])
}
if len(verParts) > 1 {
spotifyMinor, _ = strconv.Atoi(verParts[1])
}
if len(verParts) > 2 {
spotifyPatch, _ = strconv.Atoi(verParts[2])
}

filepath.Walk(appPath, func(path string, info os.FileInfo, err error) error {
fileName := info.Name()
extension := filepath.Ext(fileName)
Expand All @@ -101,8 +114,13 @@ func Start(version string, extractedAppsPath string, flags Flag) {
switch fileName {
case "xpui.js":
content = exposeAPIs_main(content)
if spotifyMajor >= 1 && spotifyMinor >= 2 && spotifyPatch >= 57 {
content = exposeAPIs_vendor(content)
}
case "vendor~xpui.js":
content = exposeAPIs_vendor(content)
if spotifyMajor < 1 && spotifyMinor < 2 && spotifyPatch < 57 {
content = exposeAPIs_vendor(content)
}
}
}
for k, v := range cssTranslationMap {
Expand Down

0 comments on commit f345385

Please sign in to comment.