Skip to content

Commit

Permalink
fix(apply): move expFeatures regex to the insertExpFeatures
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri committed Sep 8, 2024
1 parent f1c31a8 commit ffa71c3
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions src/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func AdditionalOptions(appsFolderPath string, flags Flag) {
filesToModified := map[string]func(path string, flags Flag){
filepath.Join(appsFolderPath, "xpui", "index.html"): htmlMod,
filepath.Join(appsFolderPath, "xpui", "xpui.js"): insertCustomApp,
filepath.Join(appsFolderPath, "xpui", "xpui.js"): insertExpFeatures,
filepath.Join(appsFolderPath, "xpui", "xpui.js"): insertSidebarConfig,
filepath.Join(appsFolderPath, "xpui", "vendor~xpui.js"): insertExpFeatures,
filepath.Join(appsFolderPath, "xpui", "home-v2.js"): insertHomeConfig,
filepath.Join(appsFolderPath, "xpui", "xpui-desktop-modals.js"): insertVersionInfo,
Expand Down Expand Up @@ -298,24 +300,6 @@ func insertCustomApp(jsPath string, flags Flag) {
return fmt.Sprintf("%s%s", submatches[0], cssEnableMap)
})

if flags.SidebarConfig {
utils.ReplaceOnce(
&content,
`return null!=\w+&&\w+\.totalLength(\?\w+\(\)\.createElement\(\w+,\{contextUri:)(\w+)\.uri`,
func(submatches ...string) string {
return fmt.Sprintf(`return true%s%s?.uri||""`, submatches[1], submatches[2])
})
}

if flags.ExpFeatures {
utils.ReplaceOnce(
&content,
`(([\w$.]+\.fromJSON)\(\w+\)+;)(return ?[\w{}().,]+[\w$]+\.Provider,)(\{value:\{localConfiguration)`,
func(submatches ...string) string {
return fmt.Sprintf("%sSpicetify.createInternalMap=%s;%sSpicetify.RemoteConfigResolver=%s", submatches[1], submatches[2], submatches[3], submatches[4])
})
}

return content
})
}
Expand Down Expand Up @@ -355,6 +339,7 @@ func insertHomeConfig(jsPath string, flags Flag) {
func(submatches ...string) string {
return fmt.Sprintf("%sSpicetifyHomeConfig.arrange(%s)%s", submatches[1], submatches[2], submatches[3])
})

return content
})
}
Expand All @@ -369,6 +354,23 @@ func getAssetsPath(themeFolder string) string {
return dir
}

func insertSidebarConfig(jsPath string, flags Flag) {
if !flags.SidebarConfig {
return
}

utils.ModifyFile(jsPath, func(content string) string {
utils.ReplaceOnce(
&content,
`return null!=\w+&&\w+\.totalLength(\?\w+\(\)\.createElement\(\w+,\{contextUri:)(\w+)\.uri`,
func(submatches ...string) string {
return fmt.Sprintf(`return true%s%s?.uri||""`, submatches[1], submatches[2])
})

return content
})
}

func insertExpFeatures(jsPath string, flags Flag) {
if !flags.ExpFeatures {
return
Expand All @@ -381,6 +383,13 @@ func insertExpFeatures(jsPath string, flags Flag) {
func(submatches ...string) string {
return fmt.Sprintf("%s%s=Spicetify.expFeatureOverride(%s);%s", submatches[1], submatches[2], submatches[2], submatches[3])
})

utils.ReplaceOnce(
&content,
`(([\w$.]+\.fromJSON)\(\w+\)+;)(return ?[\w{}().,]+[\w$]+\.Provider,)(\{value:\{localConfiguration)`,
func(submatches ...string) string {
return fmt.Sprintf("%sSpicetify.createInternalMap=%s;%sSpicetify.RemoteConfigResolver=%s", submatches[1], submatches[2], submatches[3], submatches[4])
})
return content
})
}
Expand Down

0 comments on commit ffa71c3

Please sign in to comment.