Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: partially expose React Router, Redux & improve some regexes #2763

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions jsHelper/spicetifyWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,12 @@ window.Spicetify = {
"Snackbar",
"Chip",
"Toggle",
"Cards"
"Cards",
"Router",
"Routes",
"Route",
"StoreProvider",
"PlatformProvider"
])
},
{
Expand Down Expand Up @@ -456,6 +461,10 @@ window.Spicetify = {
CardImage: functionModules.find(m => m.toString().includes("isHero") && m.toString().includes("withWaves")),
...Object.fromEntries(cards)
},
Router: functionModules.find(m => m.toString().includes("navigationType") && m.toString().includes("static")),
Routes: functionModules.find(m => m.toString().match(/\([\w$]+\)\{let\{children:[\w$]+,location:[\w$]+\}=[\w$]+/)),
Route: functionModules.find(m => m.toString().match(/^function [\w$]+\([\w$]+\)\{\(0,[\w$]+\.[\w$]+\)\(\!1\)\}$/)),
StoreProvider: functionModules.find(m => m.toString().includes("notifyNestedSubs") && m.toString().includes("serverState")),
...Object.fromEntries(menus)
},
ReactHook: {
Expand Down Expand Up @@ -489,7 +498,7 @@ window.Spicetify = {
Spicetify.Snackbar = {
...Spicetify.Snackbar,
SnackbarProvider: functionModules.find(m => m.toString().includes("enqueueSnackbar called with invalid argument")),
useSnackbar: functionModules.find(m => m.toString().match(/\{return\(0,\w+\.useContext\)\(\w+\)\}/))
useSnackbar: functionModules.find(m => m.toString().match(/^function\(\)\{return\(0,[\w$]+\.useContext\)\([\w$]+\)\}$/))
};
})();

Expand Down Expand Up @@ -1742,6 +1751,11 @@ Spicetify._cloneSidebarItem = (list, isLibX = false) => {
return baseClassname;
}

if (!Spicetify.React) {
setTimeout(Spicetify._cloneSidebarItem, 10, list, isLibX);
return;
}

const React = Spicetify.React;
const reactObjs = [];
const sidebarIsCollapsed = Spicetify.Platform?.LocalStorageAPI?.getItem?.("ylx-sidebar-state") === 1;
Expand Down
23 changes: 10 additions & 13 deletions src/preprocess/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,23 +313,20 @@ func exposeAPIs_main(input string) string {
// Spicetify._platform
utils.Replace(
&input,
`(setTitlebarHeight[\w(){}.,&$!=;"" ]+)(\{version:\w+,)`,
`(setTitlebarHeight[\w(){}.,&$!=;"" ]+)(\{version:[\w$]+,)`,
`${1}Spicetify._platform=${2}`)

// Profile Menu hook v1.1.56
// Redux store
utils.Replace(
&input,
`\{listItems:\w+,icons:\w+,onOutsideClick:(\w+)\}=\w+;`,
`${0};
Spicetify.React.useEffect(() => {
const container = document.querySelector(".main-userWidget-dropDownMenu")?.parentElement;
if (!container) {
console.error("Profile Menu Hook v1.1.56 failed");
return;
}
container._tippy = { props: { onClickOutside: ${1} }};
Spicetify.Menu._addItems(container);
}, []);`)
`(,[\w$]+=)(([$\w,.:=;(){}]+\(\{session:[\w$]+,features:[\w$]+,seoExperiment:[\w$]+\}))`,
`${1}Spicetify.Platform.ReduxStore=${2}`)

// React Component: Platform Provider
utils.Replace(
&input,
`(,[$\w]+=)((function\([\w$]{1}\)\{var [\w$]+=[\w$]+\.platform,[\w$]+=[\w$]+\.children,)|(\(\{platform:[\w$]+,children:[\w$]+\}\)=>\{))`,
`${1}Spicetify.ReactComponent.PlatformProvider=${2}`)

// React Component: Context Menu
// TODO: replace with webpack module
Expand Down