From 35f0f599c21b39237e9cc54e542fea85e75c91d6 Mon Sep 17 00:00:00 2001 From: Grigory Date: Thu, 11 Jan 2024 19:29:23 +0500 Subject: [PATCH] feat: expose `React Router`, `Redux` related stuff & improve some regexes --- jsHelper/spicetifyWrapper.js | 18 ++++++++++++++++-- src/preprocess/preprocess.go | 23 ++++++++++------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/jsHelper/spicetifyWrapper.js b/jsHelper/spicetifyWrapper.js index e16d8cb033..e32a6fba16 100644 --- a/jsHelper/spicetifyWrapper.js +++ b/jsHelper/spicetifyWrapper.js @@ -268,7 +268,12 @@ window.Spicetify = { "Snackbar", "Chip", "Toggle", - "Cards" + "Cards", + "Router", + "Routes", + "Route", + "StoreProvider", + "PlatformProvider" ]) }, { @@ -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: { @@ -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$]+\)\}$/)) }; })(); @@ -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; diff --git a/src/preprocess/preprocess.go b/src/preprocess/preprocess.go index fd8e6faeda..ef4d57b516 100644 --- a/src/preprocess/preprocess.go +++ b/src/preprocess/preprocess.go @@ -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