Skip to content

Commit aa4ac60

Browse files
committed
fix(preprocess/contextmenu): adapt regex for 1.2.46
1 parent d207549 commit aa4ac60

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/preprocess/preprocess.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -561,25 +561,22 @@ func exposeAPIs_main(input string) string {
561561
return fmt.Sprintf("%s[Spicetify.ContextMenuV2.renderItems(),%s].flat()", submatches[1], submatches[2])
562562
})
563563

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

566-
react := utils.FindFirstMatch(croppedInput, `([\w_$]+)\.useRef`)[1]
567-
var menu string
568-
var trigger string
569-
var target string
570-
571-
menuCandidates := utils.FindMatch(croppedInput, `menu:([\w_$]+)`)
572-
if len(menuCandidates) == 0 {
573-
// v1.2.13 fix
574-
menu = utils.FindFirstMatch(croppedInput, `([\w_$]+)=[\w_$]+\.menu,`)[1]
575-
trigger = utils.FindFirstMatch(croppedInput, `([\w_$]+)=[\w_$]+\.trigger,`)[1]
576-
target = utils.FindFirstMatch(croppedInput, `([\w_$]+)=[\w_$]+\.triggerRef,`)[1]
567+
reactRef := utils.FindFirstMatch(croppedInput, `([\w_$]+)\.useRef`)
568+
var react, menu, trigger, target string
569+
if len(reactRef) == 1 {
570+
react = reactRef[0]
577571
} else {
578-
menu = menuCandidates[0][1]
579-
trigger = utils.FindFirstMatch(croppedInput, `trigger:([\w_$]+)`)[1]
580-
target = utils.FindFirstMatch(croppedInput, `triggerRef:([\w_$]+)`)[1]
572+
react = reactRef[1]
581573
}
582574

575+
menuCandidates := utils.FindMatch(croppedInput, `menu:([\w_$]+)`)
576+
menu = menuCandidates[0][1]
577+
trigger = utils.FindFirstMatch(croppedInput, `trigger:([\w_$]+)`)[1]
578+
target = utils.FindFirstMatch(croppedInput, `triggerRef:([\w_$]+)`)[1]
579+
583580
utils.Replace(&input, `\(0,([\w_$]+)\.jsx\)\([\w_$]+\.[\w_$]+,\{value:"contextmenu"[^\}]+\}\)\}\)`, func(submatches ...string) string {
584581
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])
585582
})

0 commit comments

Comments
 (0)