Skip to content

Commit f345385

Browse files
committed
feat: patch only xpui.js on Spotify 1.2.57 and higher
1 parent 7a53725 commit f345385

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

src/apply/apply.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66
"path/filepath"
7+
"strconv"
78
"strings"
89

910
"github.com/spicetify/cli/src/utils"
@@ -36,9 +37,6 @@ func AdditionalOptions(appsFolderPath string, flags Flag) {
3637
insertSidebarConfig,
3738
insertHomeConfig,
3839
},
39-
filepath.Join(appsFolderPath, "xpui", "vendor~xpui.js"): {
40-
insertExpFeatures,
41-
},
4240
filepath.Join(appsFolderPath, "xpui", "home-v2.js"): {
4341
insertHomeConfig,
4442
},
@@ -47,6 +45,24 @@ func AdditionalOptions(appsFolderPath string, flags Flag) {
4745
},
4846
}
4947

48+
verParts := strings.Split(flags.SpotifyVer, ".")
49+
spotifyMajor, spotifyMinor, spotifyPatch := 0, 0, 0
50+
if len(verParts) > 0 {
51+
spotifyMajor, _ = strconv.Atoi(verParts[0])
52+
}
53+
if len(verParts) > 1 {
54+
spotifyMinor, _ = strconv.Atoi(verParts[1])
55+
}
56+
if len(verParts) > 2 {
57+
spotifyPatch, _ = strconv.Atoi(verParts[2])
58+
}
59+
60+
if spotifyMajor >= 1 && spotifyMinor >= 2 && spotifyPatch >= 57 {
61+
filesToModified[filepath.Join(appsFolderPath, "xpui", "xpui.js")] = append(filesToModified[filepath.Join(appsFolderPath, "xpui", "xpui.js")], insertExpFeatures)
62+
} else {
63+
filesToModified[filepath.Join(appsFolderPath, "xpui", "vendor~xpui.js")] = []func(string, Flag){insertExpFeatures}
64+
}
65+
5066
for file, calls := range filesToModified {
5167
if _, err := os.Stat(file); os.IsNotExist(err) {
5268
continue

src/cmd/backup.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ Modded Spotify cannot be launched using original Shortcut/Start menu tile. To co
7272
DisableSentry: preprocSection.Key("disable_sentry").MustBool(false),
7373
DisableLogging: preprocSection.Key("disable_ui_logging").MustBool(false),
7474
RemoveRTL: preprocSection.Key("remove_rtl_rule").MustBool(false),
75-
ExposeAPIs: preprocSection.Key("expose_apis").MustBool(false)},
75+
ExposeAPIs: preprocSection.Key("expose_apis").MustBool(false),
76+
SpotifyVer: utils.GetSpotifyVersion(prefsPath)},
7677
)
7778
utils.PrintGreen("OK")
7879

src/preprocess/preprocess.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Flag struct {
2626
RemoveRTL bool
2727
// ExposeAPIs leaks some Spotify's API, functions, objects to Spicetify global object.
2828
ExposeAPIs bool
29+
SpotifyVer string
2930
}
3031

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

86+
verParts := strings.Split(flags.SpotifyVer, ".")
87+
spotifyMajor, spotifyMinor, spotifyPatch := 0, 0, 0
88+
if len(verParts) > 0 {
89+
spotifyMajor, _ = strconv.Atoi(verParts[0])
90+
}
91+
if len(verParts) > 1 {
92+
spotifyMinor, _ = strconv.Atoi(verParts[1])
93+
}
94+
if len(verParts) > 2 {
95+
spotifyPatch, _ = strconv.Atoi(verParts[2])
96+
}
97+
8598
filepath.Walk(appPath, func(path string, info os.FileInfo, err error) error {
8699
fileName := info.Name()
87100
extension := filepath.Ext(fileName)
@@ -101,8 +114,13 @@ func Start(version string, extractedAppsPath string, flags Flag) {
101114
switch fileName {
102115
case "xpui.js":
103116
content = exposeAPIs_main(content)
117+
if spotifyMajor >= 1 && spotifyMinor >= 2 && spotifyPatch >= 57 {
118+
content = exposeAPIs_vendor(content)
119+
}
104120
case "vendor~xpui.js":
105-
content = exposeAPIs_vendor(content)
121+
if spotifyMajor < 1 && spotifyMinor < 2 && spotifyPatch < 57 {
122+
content = exposeAPIs_vendor(content)
123+
}
106124
}
107125
}
108126
for k, v := range cssTranslationMap {

0 commit comments

Comments
 (0)