From 28c33e36b74d756518e9fd01e2b355597eb553e8 Mon Sep 17 00:00:00 2001 From: ririxi Date: Thu, 7 Dec 2023 17:32:14 +0100 Subject: [PATCH 1/2] revert: enhance snackbar exposition We should expose private methods so they can use them and not limit only to the public ones --- jsHelper/spicetifyWrapper.js | 1 + src/preprocess/preprocess.go | 9 ++------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/jsHelper/spicetifyWrapper.js b/jsHelper/spicetifyWrapper.js index b6419e156f..75a6e0f848 100644 --- a/jsHelper/spicetifyWrapper.js +++ b/jsHelper/spicetifyWrapper.js @@ -449,6 +449,7 @@ window.Spicetify = { // Snackbar notifications // https://github.com/iamhosseindhv/notistack 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+\)\}/)) }, diff --git a/src/preprocess/preprocess.go b/src/preprocess/preprocess.go index 3c0a920c3b..7a8f63d472 100644 --- a/src/preprocess/preprocess.go +++ b/src/preprocess/preprocess.go @@ -465,13 +465,8 @@ if (${1}.popper?.firstChild?.id === "context-menu") { // Snackbar https://github.com/iamhosseindhv/notistack utils.Replace( &input, - `\(\w+\s*=\s*\w\.call\(this,[^)]+\)\s*\|\|\s*this\)\.enqueueSnackbar`, - ` Spicetify.Snackbar.enqueueSnackbar=${0}`) - - utils.Replace( - &input, - `\w+.closeSnackbar=function`, - `Spicetify.Snackbar.closeSnackbar=${0}`) + `\w+\s*=\s*\w\.call\(this,[^)]+\)\s*\|\|\s*this\)\.enqueueSnackbar`, + `Spicetify.Snackbar=${0}`) return input } From fca184bce0fd0be542a28941ac88a97c1c2cd78d Mon Sep 17 00:00:00 2001 From: ririxi Date: Sat, 9 Dec 2023 01:26:36 +0100 Subject: [PATCH 2/2] feat(wrapper): assign empty object to Snackbar --- jsHelper/spicetifyWrapper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jsHelper/spicetifyWrapper.js b/jsHelper/spicetifyWrapper.js index 75a6e0f848..7fe0110d20 100644 --- a/jsHelper/spicetifyWrapper.js +++ b/jsHelper/spicetifyWrapper.js @@ -311,7 +311,8 @@ window.Spicetify = { }, ReactComponent: {}, ReactHook: {}, - ReactFlipToolkit: {} + ReactFlipToolkit: {}, + Snackbar: {} }; (async function hotloadWebpackModules() { @@ -543,7 +544,6 @@ window.Spicetify = { return; } - if (!Spicetify.Snackbar) Spicetify.Snackbar = {}; Spicetify.Snackbar.enqueueSnackbar = (message, { variant = "default", autoHideDuration } = {}) => { isError = variant === "error"; Spicetify.showNotification(message, isError, autoHideDuration);