Skip to content

Commit

Permalink
fix: helper scrips position
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhas committed Jun 25, 2021
1 parent 5107e1d commit 03c35d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
18 changes: 11 additions & 7 deletions src/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,34 @@ func htmlMod(htmlPath string, flags Flag) {
return
}

extensionsHTML := ""
extensionsHTML := "\n"
helperHTML := "\n"

if flags.SidebarConfig {
extensionsHTML += `<script src="helper/sidebarConfig.js"></script>` + "\n"
helperHTML += `<script defer src="helper/sidebarConfig.js"></script>` + "\n"
}

if flags.HomeConfig {
extensionsHTML += `<script src="helper/homeConfig.js"></script>` + "\n"
helperHTML += `<script defer src="helper/homeConfig.js"></script>` + "\n"
}

for _, v := range flags.Extension {
if strings.HasSuffix(v, ".mjs") {
extensionsHTML += `<script type="module" src="extensions/` + v + `"></script>` + "\n"
extensionsHTML += `<script defer type="module" src="extensions/` + v + `"></script>` + "\n"
} else {
extensionsHTML += `<script src="extensions/` + v + `"></script>` + "\n"
extensionsHTML += `<script defer src="extensions/` + v + `"></script>` + "\n"
}
}

utils.ModifyFile(htmlPath, func(content string) string {
utils.Replace(
&content,
`<\!-- spicetify helpers -->`,
"${0}"+helperHTML)
utils.Replace(
&content,
`</body>`,
extensionsHTML+"${0}",
)
extensionsHTML+"${0}")
return content
})
}
Expand Down
13 changes: 7 additions & 6 deletions src/preprocess/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ func Start(extractedAppsPath string, flags Flag) {

var tags string
if flags.ExposeAPIs {
tags += `<script src="helper/spicetifyWrapper.js"></script>`
tags += `<script src="helper/spicetifyWrapper.js"></script>` + "\n"
tags += `<!-- spicetify helpers -->` + "\n"
}

utils.Replace(&content, `<body>`, "${0}\n"+tags)
Expand Down Expand Up @@ -379,18 +380,18 @@ func exposeAPIs_vendor(input string) string {
&input,
`\w+\("onMount",\[(\w+)\]\)`,
`${0};
if (G.popper?.firstChild?.id === "context-menu") {
const container = G.popper.firstChild;
if (${1}.popper?.firstChild?.id === "context-menu") {
const container = ${1}.popper.firstChild;
if (!container.children.length) {
const observer = new MutationObserver(() => {
Spicetify.ContextMenu._addItems(G.popper);
Spicetify.ContextMenu._addItems(${1}.popper);
observer.disconnect();
});
observer.observe(container, { childList: true });
} else if (container.firstChild.classList.contains("main-userWidget-dropDownMenu")) {
Spicetify.Menu._addItems(G.popper);
Spicetify.Menu._addItems(${1}.popper);
} else {
Spicetify.ContextMenu._addItems(G.popper);
Spicetify.ContextMenu._addItems(${1}.popper);
}
};0`)

Expand Down

0 comments on commit 03c35d4

Please sign in to comment.