Skip to content

Commit

Permalink
Merge branch 'spicetify:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Lseoksee authored Dec 10, 2023
2 parents 1358249 + 1fc2bb9 commit 1352f24
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
run: echo "IS_WIN=${{ matrix.os == 'windows' && matrix.arch != 'arm64' }}" >> $GITHUB_ENV

- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
pull-requests: write

steps:
- uses: actions/stale@v8.0.0
- uses: actions/stale@v9.0.0
with:
# Token for the repository. Can be passed in using `{{ secrets.GITHUB_TOKEN }}`.
repo-token: ${{ github.token }}
Expand Down
60 changes: 32 additions & 28 deletions jsHelper/spicetifyWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ window.Spicetify = {
"ButtonSecondary",
"ButtonTertiary",
"Snackbar",
"Chip"
"Chip",
"Toggle"
];

const REACT_HOOK = ["DragHandler", "usePanelState", "useExtractedColor"];
Expand Down Expand Up @@ -311,7 +312,8 @@ window.Spicetify = {
},
ReactComponent: {},
ReactHook: {},
ReactFlipToolkit: {}
ReactFlipToolkit: {},
Snackbar: {}
};

(async function hotloadWebpackModules() {
Expand Down Expand Up @@ -403,7 +405,7 @@ window.Spicetify = {
),
Menu: functionModules.find(m => m.toString().includes("getInitialFocusElement") && m.toString().includes("children")),
MenuItem: functionModules.find(m => m.toString().includes("handleMouseEnter") && m.toString().includes("onClick")),
Slider: wrapProvider(functionModules.find(m => m.toString().includes("onStepBackward"))),
Slider: wrapProvider(functionModules.find(m => m.toString().includes("onStepBackward") && !m.toString().includes("volume"))),
RemoteConfigProvider: functionModules.find(m => m.toString().includes("resolveSuspense") && m.toString().includes("configuration")),
RightClickMenu: functionModules.find(
m =>
Expand All @@ -421,12 +423,13 @@ window.Spicetify = {
ButtonSecondary: modules.find(m => m?.render && m?.displayName === "ButtonSecondary"),
ButtonTertiary: modules.find(m => m?.render && m?.displayName === "ButtonTertiary"),
Snackbar: {
wrapper: functionModules.find(m => m.toString().includes("encore-light-theme")),
simpleLayout: functionModules.find(m => m.toString().includes("leading")),
wrapper: functionModules.find(m => m.toString().includes("encore-light-theme") && m.toString().includes("elevated")),
simpleLayout: functionModules.find(m => ["leading", "center", "trailing"].every(keyword => m.toString().includes(keyword))),
ctaText: functionModules.find(m => m.toString().includes("ctaText")),
styledImage: functionModules.find(m => m.toString().includes("placeholderSrc"))
},
Chip: modules.find(m => m?.render?.toString().includes("invertedDark") && m?.render?.toString().includes("isUsingKeyboard")),
Toggle: functionModules.find(m => m.toString().includes("onSelected")) && functionModules.find(m => m.toString().includes('type:"checkbox"')),
...Object.fromEntries(menus)
},
ReactHook: {
Expand All @@ -449,6 +452,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+\)\}/))
},
Expand Down Expand Up @@ -476,6 +480,7 @@ window.Spicetify = {
get _dictionary() {
return localeModule._translations;
},
formatDate: (date, options) => localeModule.formatDate(date, options),
formatRelativeTime: (date, options) => localeModule.formatRelativeDate(date, options),
formatNumber: (number, options) => localeModule.formatNumber(number, options),
formatNumberCompact: (number, options) => localeModule.formatNumberCompact(number, options),
Expand Down Expand Up @@ -542,7 +547,6 @@ window.Spicetify = {
return;
}

if (!Spicetify.Snackbar) Spicetify.Snackbar = {};
Spicetify.Snackbar.enqueueSnackbar = (message, { variant = "default", autoHideDuration } = {}) => {
isError = variant === "error";
Spicetify.showNotification(message, isError, autoHideDuration);
Expand Down Expand Up @@ -681,31 +685,22 @@ window.Spicetify = {
return;
}

function objectsAreEqual(obj1, obj2) {
return JSON.stringify(obj1) === JSON.stringify(obj2);
}
const interval = setInterval(() => {
if (!Spicetify.Player.origin._state) return;
Spicetify.Player.data = Spicetify.Player.origin._state;
clearInterval(interval);
}, 10);

const playerState = {
cache: Spicetify.Player.data,
current: null
};

setInterval(() => {
if (
objectsAreEqual(Spicetify.Platform.PlayerAPI._state, playerState.cache) ||
(!Spicetify.Platform.PlayerAPI._state.item && !Spicetify.Player.data)
)
return;

if (!Spicetify.Platform.PlayerAPI._state.item) {
Spicetify.Player.data = null;
return;
}

playerState.current = Spicetify.Platform.PlayerAPI._state;
Spicetify.Player.origin._events.addListener("update", ({ data: playerEventData }) => {
playerState.current = playerEventData;
Spicetify.Player.data = playerState.current;

if (playerState.cache?.item.uri !== playerState.current?.item?.uri) {
if (playerState.cache?.item?.uri !== playerState.current?.item?.uri) {
const event = new Event("songchange");
event.data = Spicetify.Player.data;
Spicetify.Player.dispatchEvent(event);
Expand All @@ -718,12 +713,21 @@ window.Spicetify = {
}

playerState.cache = playerState.current;
}, 100);
});

Spicetify.Player.origin._events.addListener("error", ({ data: error }) => {
if (error.code === "all_tracks_unplayable_auto_stopped") {
Spicetify.Player.data = null;
playerState.cache = null;
}
});

setInterval(() => {
const event = new Event("onprogress");
event.data = Spicetify.Player.getProgress();
Spicetify.Player.dispatchEvent(event);
if (playerState.cache?.isPaused === false) {
const event = new Event("onprogress");
event.data = Spicetify.Player.getProgress();
Spicetify.Player.dispatchEvent(event);
}
}, 100);

Spicetify.addToQueue = uri => {
Expand Down Expand Up @@ -765,7 +769,7 @@ Spicetify.colorExtractor = async uri => {
if (body.entries && body.entries.length) {
const list = {};
for (const color of body.entries[0].color_swatches) {
list[color.preset] = `#${color.color.toString(16).padStart(6, "0")}`;
list[color.preset] = `#${color.color?.toString(16).padStart(6, "0")}`;
}
return list;
} else {
Expand Down
18 changes: 7 additions & 11 deletions src/preprocess/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,21 +244,22 @@ func disableLogging(input string) string {
utils.Replace(&input, `key:"logImpression",value:function\([\w,]+\)\{`, "${0}return;")
utils.Replace(&input, `key:"logNonAuthImpression",value:function\([\w,]+\)\{`, "${0}return;")
utils.Replace(&input, `key:"logNavigation",value:function\([\w,]+\)\{`, "${0}return;")
utils.Replace(&input, `key:"logClientLostFocus",value:function\(\)\{`, "${0}return;")
utils.Replace(&input, `key:"logClientGainedFocus",value:function\(\)\{`, "${0}return;")
utils.Replace(&input, `key:"handleBackgroundStates",value:function\(\)\{`, "${0}return;")
utils.Replace(&input, `key:"createLoggingParams",value:function\([\w,]+\)\{`, "${0}return;")
utils.Replace(&input, `key:"initSendingEvents",value:function\(\)\{`, "${0}return;")
utils.Replace(&input, `key:"flush",value:function\(\)\{`, "${0}return;")
utils.Replace(&input, `(\{key:"send",value:function\([\w,]+\))\{[\d\w\s,{}()[\]\.,!\?=>&|;:_""]+?\}(\},\{key:"hasContext")`, "${1}{return;}${2}")
utils.Replace(&input, `key:"lastFlush",value:function\(\)\{`, "${0}return;")

utils.Replace(&input, `(\}registerEventListeners\(\))\{.+?\}(unregisterEventListeners)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}logInteraction\([\w,]+\))\{.+?\}(logImpression)`, "${1}{return{interactionId:null,pageInstanceId:null};}${2}")
utils.Replace(&input, `(\}logImpression\([\w,]+\))\{.+?\}(logNavigation)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}logNavigation\([\w,]+\))\{.+?\}(getPageInstanceId|getInteractionId)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}logClientLostFocus\(\))\{.+?\}(logClientGainedFocus)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}logClientGainedFocus\(\))\{.+?\}(getPageInstanceId|addEventListeners)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}handleBackgroundStates\(\))\{.+?\}(startNavigation)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}createLoggingParams\([\w,]+\))\{.+?\}(async pullToLocal)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}initSendingEvents\(\))\{.+?\}(initializeContexts)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}flush\(\))\{.+\}(sendEvents)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}flush\(\w+=!0\))\{.+\}(flushAll)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}send\([\w,:=!\d{}]+\))\{.+?\}(hasContext)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}lastFlush\(\))\{.+?\}(flush\(\))`, "${1}{return;}${2}")

Expand Down Expand Up @@ -465,13 +466,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
}
Expand Down

0 comments on commit 1352f24

Please sign in to comment.