Skip to content

Commit

Permalink
fix(wrapper): accommodate different profile menu containers (#2812)
Browse files Browse the repository at this point in the history
  • Loading branch information
Delusoire authored Feb 10, 2024
1 parent e5449ca commit cdca8d0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion jsHelper/spicetifyWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,7 @@ Spicetify.ContextMenuV2 = (() => {
})();

Spicetify.Menu = (() => {
const shouldAdd = (_, trigger, target) => trigger === "click" && target.parentElement.classList.contains("main-topBar-topbarContentRight");
const shouldAdd = (_, trigger, target) => trigger === "click" && target.closest(".main-topBar-container");

class Item extends Spicetify.ContextMenuV2.Item {
constructor(children, isEnabled, onClick, leadingIcon) {
Expand Down
24 changes: 18 additions & 6 deletions src/preprocess/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,24 @@ func exposeAPIs_main(input string) string {
// Menu hook
utils.Replace(&input, `("Menu".+?children:)([\w$][\w$\d]*)`, `${1}[Spicetify.ContextMenuV2.renderItems(),${2}].flat()`)

croppedInput := utils.FindFirstMatch(input, `.*value:"contextmenu"`)[0]

react := utils.FindLastMatch(croppedInput, `([\w_$]+)\.useRef`)[1]
menu := utils.FindLastMatch(croppedInput, `menu:([\w_$]+)`)[1]
trigger := utils.FindLastMatch(croppedInput, `trigger:([\w_$]+)`)[1]
target := utils.FindLastMatch(croppedInput, `triggerRef:([\w_$]+)`)[1]
croppedInput := utils.FindFirstMatch(input, `"context-menu".*value:"contextmenu"`)[0]

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]
} else {
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"[^\}]+\}\)\}\)`, `(0,${1}.jsx)((Spicetify.ContextMenuV2._context||(Spicetify.ContextMenuV2._context=`+react+`.createContext(null))).Provider,{value:{props:`+menu+`?.props,trigger:`+trigger+`,target:`+target+`},children:${0}})`)

Expand Down

0 comments on commit cdca8d0

Please sign in to comment.