Skip to content

Commit 6c01db7

Browse files
committed
feat(preprocess): expose graphql defs from every js file
1 parent 39fcc02 commit 6c01db7

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/preprocess/preprocess.go

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ func Start(version string, spotifyBasePath string, extractedAppsPath string, fla
214214
case "vendor~xpui.js":
215215
content = exposeAPIs_vendor(content, printPatch)
216216
}
217+
218+
content = exposeGraphQL(content, printPatch)
217219
}
218220
printPatch("CSS (JS): Patching our mappings into file")
219221
for k, v := range cssTranslationMap {
@@ -796,6 +798,27 @@ func removeRTL(input string) string {
796798
return applyPatches(input, rtlPatches)
797799
}
798800

801+
func exposeGraphQL(input string, report logPatch) string {
802+
graphQLPatches := []Patch{
803+
{
804+
Name: "GraphQL definitions (<=1.2.30)",
805+
Regex: `((?:\w+ ?)?[\w$]+=)(\{kind:"Document",definitions:\[\{(?:\w+:[\w"]+,)+name:\{(?:\w+:[\w"]+,?)+value:("\w+"))`,
806+
Replacement: func(submatches ...string) string {
807+
return fmt.Sprintf("%sSpicetify.GraphQL.Definitions[%s]=%s", submatches[1], submatches[3], submatches[2])
808+
},
809+
},
810+
{
811+
Name: "GraphQL definitons (>=1.2.31)",
812+
Regex: `(=new [\w_\$][\w_\$\d]*\.[\w_\$][\w_\$\d]*\("(\w+)","(query|mutation)","[\w\d]{64}",null\))`,
813+
Replacement: func(submatches ...string) string {
814+
return fmt.Sprintf(`=Spicetify.GraphQL.Definitions["%s"]%s`, submatches[2], submatches[1])
815+
},
816+
},
817+
}
818+
819+
return applyPatches(input, graphQLPatches, report)
820+
}
821+
799822
func exposeAPIs_main(input string, report logPatch) string {
800823
inputContextMenu := utils.FindFirstMatch(input, `.*value:"contextmenu"`)
801824
if len(inputContextMenu) > 0 {
@@ -880,20 +903,6 @@ func exposeAPIs_main(input string, report logPatch) string {
880903
return ""
881904
},
882905
},
883-
{
884-
Name: "GraphQL definitions (<=1.2.30)",
885-
Regex: `((?:\w+ ?)?[\w$]+=)(\{kind:"Document",definitions:\[\{(?:\w+:[\w"]+,)+name:\{(?:\w+:[\w"]+,?)+value:("\w+"))`,
886-
Replacement: func(submatches ...string) string {
887-
return fmt.Sprintf("%sSpicetify.GraphQL.Definitions[%s]=%s", submatches[1], submatches[3], submatches[2])
888-
},
889-
},
890-
{
891-
Name: "GraphQL definitons (>=1.2.31)",
892-
Regex: `(=new [\w_\$][\w_\$\d]*\.[\w_\$][\w_\$\d]*\("(\w+)","(query|mutation)","[\w\d]{64}",null\))`,
893-
Replacement: func(submatches ...string) string {
894-
return fmt.Sprintf(`=Spicetify.GraphQL.Definitions["%s"]%s`, submatches[2], submatches[1])
895-
},
896-
},
897906
{
898907
Name: "Spotify Custom Snackbar Interfaces (<=1.2.37)",
899908
Regex: `\b\w\s*\(\)\s*[^;,]*enqueueCustomSnackbar:\s*(\w)\s*[^;]*;`,

0 commit comments

Comments
 (0)