Skip to content

Commit 4d82e1b

Browse files
committed
feat: add build type detection
1 parent 651cbbe commit 4d82e1b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/preprocess/preprocess.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ func Start(version string, spotifyBasePath string, extractedAppsPath string, fla
116116
spotifyPatch, _ = strconv.Atoi(verParts[2])
117117
}
118118

119+
var spotifyBinaryPath string
120+
switch runtime.GOOS {
121+
case "windows":
122+
spotifyBinaryPath = filepath.Join(spotifyBasePath, "spotify.dll")
123+
case "darwin":
124+
spotifyBinaryPath = filepath.Join(spotifyBasePath, "..", "MacOS", "Spotify")
125+
}
126+
127+
if spotifyBinaryPath != "" {
128+
if err := validateReleaseBuild(spotifyBinaryPath); err != nil {
129+
utils.PrintError(err.Error())
130+
utils.Fatal(errors.New("aborting the patching process due to unsupported build"))
131+
}
132+
}
133+
119134
frameworkResourcesPath := ""
120135
switch runtime.GOOS {
121136
case "darwin":
@@ -1022,6 +1037,28 @@ func exposeAPIs_vendor(input string) string {
10221037
return applyPatches(input, vendorPatches)
10231038
}
10241039

1040+
func validateReleaseBuild(spotifyBinaryPath string) error {
1041+
fileContent, err := os.ReadFile(spotifyBinaryPath)
1042+
if err != nil {
1043+
return fmt.Errorf("could not read %s: %w", filepath.Base(spotifyBinaryPath), err)
1044+
}
1045+
1046+
buildRegex := regexp.MustCompile(`(Master|Release|PR|Local) Build.+(cef_\d+\.\d+\.\d+\+g[0-9a-f]+\+chromium-\d+\.\d+\.\d+\.\d+)`)
1047+
matches := buildRegex.FindSubmatch(fileContent)
1048+
1049+
if len(matches) == 0 {
1050+
return fmt.Errorf("could not detect Spotify build type in %s", filepath.Base(spotifyBinaryPath))
1051+
}
1052+
1053+
buildType := string(matches[1])
1054+
if buildType != "Release" {
1055+
return fmt.Errorf("detected %s Spotify build! spicetify works only on Release builds. Please install latest Release version of Spotify", buildType)
1056+
}
1057+
1058+
utils.PrintSuccess(fmt.Sprintf("Spotify's build type is %s. Continuing...", string(matches[1])))
1059+
return nil
1060+
}
1061+
10251062
type githubRelease = utils.GithubRelease
10261063

10271064
func splitVersion(version string) ([3]int, error) {

0 commit comments

Comments
 (0)