Skip to content

Commit

Permalink
feat: enhance snackbar exposition (#2701)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunsetTechuila authored Dec 5, 2023
1 parent 7e89c05 commit 89d49d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 7 additions & 1 deletion jsHelper/spicetifyWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@ window.Spicetify = {
},
_reservedPanelIds: modules.find(m => m?.BuddyFeed),
Mousetrap: cache.find(m => m?.addKeycodes),
// Snackbar notifications
// https://github.com/iamhosseindhv/notistack
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+\)\}/))
},
Locale: modules.find(m => m?._dictionary)
});

Expand Down Expand Up @@ -521,7 +527,7 @@ window.Spicetify = {

// Combine snackbar and notification
(function bindShowNotification() {
if (!Spicetify.Snackbar && !Spicetify.showNotification) {
if (!Spicetify.Snackbar?.enqueueSnackbar && !Spicetify.showNotification) {
setTimeout(bindShowNotification, 250);
return;
}
Expand Down
12 changes: 8 additions & 4 deletions src/preprocess/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ Spicetify.React.useEffect(() => {
`case [\w$.]+BuddyFeed:(?:return ?|[\w$]+=)[\w$?]*(?:\([\w$.,]+\)\([\w(){},.:]+)?;(?:break;)?(?:case [\w$.]+:(?:return ?|[\w$]+=)[\w$?]*(?:\([\w$.,]+\)\([\w(){},.:]+)?[\w:]*;(?:break;)?)*default:(?:return ?|[\w$]+=)`,
`${0} Spicetify.Panel?.render()??`)

// Snackbar https://mui.com/material-ui/react-snackbar/
utils.Replace(
&input,
`\b\w\s*\(\)\s*[^;,]*enqueueCustomSnackbar:\s*(\w)\s*[^;]*;`,
Expand Down Expand Up @@ -463,11 +462,16 @@ if (${1}.popper?.firstChild?.id === "context-menu") {
`([\w$]+)=((?:function|\()([\w$.,{}()= ]+(?:springConfig|overshootClamping)){2})`,
`${1}=Spicetify.ReactFlipToolkit.spring=${2}`)

// Snackbar https://mui.com/material-ui/react-snackbar/
// Snackbar https://github.com/iamhosseindhv/notistack
utils.Replace(
&input,
`\w+\s*=\s*\w\.call\(this,[^)]+\)\s*\|\|\s*this\)\.enqueueSnackbar`,
`Spicetify.Snackbar=${0}`)
`\(\w+\s*=\s*\w\.call\(this,[^)]+\)\s*\|\|\s*this\)\.enqueueSnackbar`,
` Spicetify.Snackbar.enqueueSnackbar=${0}`)

utils.Replace(
&input,
`\w+.closeSnackbar=function`,
`Spicetify.Snackbar.closeSnackbar=${0}`)

return input
}
Expand Down

0 comments on commit 89d49d7

Please sign in to comment.