Skip to content

Commit

Permalink
fix(preprocess/contextmenu): adapt regex for 1.2.46
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri committed Sep 8, 2024
1 parent d207549 commit aa4ac60
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/preprocess/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,25 +561,22 @@ func exposeAPIs_main(input string) string {
return fmt.Sprintf("%s[Spicetify.ContextMenuV2.renderItems(),%s].flat()", submatches[1], submatches[2])
})

croppedInput := utils.FindFirstMatch(input, `"context-menu".*value:"contextmenu"`)[0]
croppedInput := utils.FindFirstMatch(input, `\({menu:[^,]+,.*?triggerRef:[^,]+,[^}]*}\).*value:"contextmenu"`)[0]
fmt.Println(croppedInput)

react := utils.FindFirstMatch(croppedInput, `([\w_$]+)\.useRef`)[1]
var menu string
var trigger string
var target string

menuCandidates := utils.FindMatch(croppedInput, `menu:([\w_$]+)`)
if len(menuCandidates) == 0 {
// v1.2.13 fix
menu = utils.FindFirstMatch(croppedInput, `([\w_$]+)=[\w_$]+\.menu,`)[1]
trigger = utils.FindFirstMatch(croppedInput, `([\w_$]+)=[\w_$]+\.trigger,`)[1]
target = utils.FindFirstMatch(croppedInput, `([\w_$]+)=[\w_$]+\.triggerRef,`)[1]
reactRef := utils.FindFirstMatch(croppedInput, `([\w_$]+)\.useRef`)
var react, menu, trigger, target string
if len(reactRef) == 1 {
react = reactRef[0]
} else {
menu = menuCandidates[0][1]
trigger = utils.FindFirstMatch(croppedInput, `trigger:([\w_$]+)`)[1]
target = utils.FindFirstMatch(croppedInput, `triggerRef:([\w_$]+)`)[1]
react = reactRef[1]
}

menuCandidates := utils.FindMatch(croppedInput, `menu:([\w_$]+)`)
menu = menuCandidates[0][1]
trigger = utils.FindFirstMatch(croppedInput, `trigger:([\w_$]+)`)[1]
target = utils.FindFirstMatch(croppedInput, `triggerRef:([\w_$]+)`)[1]

utils.Replace(&input, `\(0,([\w_$]+)\.jsx\)\([\w_$]+\.[\w_$]+,\{value:"contextmenu"[^\}]+\}\)\}\)`, func(submatches ...string) string {
return fmt.Sprintf("(0,%s.jsx)((Spicetify.ContextMenuV2._context||(Spicetify.ContextMenuV2._context=%s.createContext(null))).Provider,{value:{props:%s?.props,trigger:%s,target:%s},children:%s})", submatches[1], react, menu, trigger, target, submatches[0])
})
Expand Down

0 comments on commit aa4ac60

Please sign in to comment.