Skip to content

Commit

Permalink
fix(preprocess/contextmenu): fallback when regex doesn't find candicates
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri committed Sep 9, 2024
1 parent 761fe0f commit d0c9272
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/preprocess/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,17 @@ func exposeAPIs_main(input string) string {

croppedInput := utils.FindFirstMatch(input, `.*value:"contextmenu"`)[0]
react := utils.FindLastMatch(croppedInput, `([a-zA-Z_\$][\w\$]*)\.useRef`)[1]
menu := utils.FindLastMatch(croppedInput, `menu:([\w_$]+)`)[1]
trigger := utils.FindLastMatch(croppedInput, `trigger:([\w_$]+)`)[1]
target := utils.FindLastMatch(croppedInput, `triggerRef:([\w_$]+)`)[1]
candicates := utils.FindLastMatch(croppedInput, `\(\{[^}]*menu:([a-zA-Z_\$][\w\$]*),[^}]*trigger:([a-zA-Z_\$][\w\$]*),[^}]*triggerRef:([a-zA-Z_\$][\w\$]*)`)
var menu, trigger, target string
if len(candicates) == 0 {
menu = "e.menu"
trigger = "e.trigger"
target = "e.triggerRef"
} else {
menu = candicates[1]
trigger = candicates[2]
target = candicates[3]
}

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

1 comment on commit d0c9272

@rxri
Copy link
Member Author

@rxri rxri commented on d0c9272 Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is taken from https://github.com/spicetify/modules/blob/main/modules/stdlib/src/registers/menu.ts. I forgot to include this note in the code

Please sign in to comment.