Showing with 101 additions and 91 deletions.
  1. +2 −1 Extensions/bookmark.js
  2. +7 −1 css-map.json
  3. +0 −4 globals.d.ts
  4. +2 −2 go.mod
  5. +4 −4 go.sum
  6. +43 −64 jsHelper/spicetifyWrapper.js
  7. +3 −1 spicetify.go
  8. +1 −1 src/cmd/cmd.go
  9. +33 −5 src/preprocess/preprocess.go
  10. +1 −2 src/utils/path-utils.go
  11. +3 −4 src/utils/utils.go
  12. +2 −2 src/utils/vcs.go
3 changes: 2 additions & 1 deletion Extensions/bookmark.js
Expand Up @@ -285,7 +285,8 @@
} else {
meta.description = Player.data.item.metadata.artist_name;
}
const contextUri = URI.fromString(Spicetify.Player.data.context_uri);
const playerState = Spicetify.Player.data;
const contextUri = URI.fromString(playerState.context_uri ?? playerState.context.uri);
if (contextUri && (contextUri.type === URI.Type.PLAYLIST || contextUri.type === URI.Type.PLAYLIST_V2 || contextUri.type === URI.Type.ALBUM)) {
meta.context = `/${contextUri.toURLPath()}?uid=${Player.data.item.uid}`;
}
Expand Down
8 changes: 7 additions & 1 deletion css-map.json
Expand Up @@ -2548,5 +2548,11 @@
"Cjga8q3TFvtKCu9qfm27": "main-contextMenu-menuItemStatic",
"wtEUrk4Sxa5e3QZhvbrs": "main-contextMenu-subMenuLeading",
"ibA08TpSVrM0wThmotVd": "main-contextMenu-loadingContainer",
"zL6hQR4mukVUUQaa_7K1": "main-nowPlayingView-coverArtContainer"
"zL6hQR4mukVUUQaa_7K1": "main-nowPlayingView-coverArtContainer",
"jXeqeqkxEBVeFjA2YydA": "x-categoryCard-CategoryCard",
"Op2n2H4o1iY0Xo2wAUH9": "x-categoryCard-image",
"bQthUEx0_U98DJkT1saO": "x-categoryCard-title",
"eEZSnYlv7__34b2yulfm": "volume-bar",
"FZhaXNtbN3Crwrgd0TA7": "volume-bar__icon-button",
"x1jWng8HDweDS840aiIA": "volume-bar__slider-container"
}
4 changes: 0 additions & 4 deletions globals.d.ts
Expand Up @@ -190,10 +190,6 @@ declare namespace Spicetify {
playbackId: string;
sessionId: string;
signals?: any[];
/**
* @deprecated Use `item` instead. This will be removed in the future.
*/
track: PlayerTrack;
};
type PlayerContext = {
uri: string;
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Expand Up @@ -5,11 +5,11 @@ go 1.21
require (
github.com/go-ini/ini v1.67.0
github.com/mattn/go-colorable v0.1.13
golang.org/x/net v0.18.0
golang.org/x/net v0.19.0
)

require (
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/stretchr/testify v1.7.1 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/sys v0.15.0 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Expand Up @@ -11,11 +11,11 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
107 changes: 43 additions & 64 deletions jsHelper/spicetifyWrapper.js
Expand Up @@ -69,12 +69,15 @@ window.Spicetify = {
},
getMute: () => Spicetify.Player.getVolume() === 0,
toggleMute: () => {
document.querySelector(".volume-bar__icon-button").click();
Spicetify.Player.setMute(!Spicetify.Player.getMute());
},
setMute: b => {
const isMuted = Spicetify.Player.getMute();
if ((b && !isMuted) || (!b && isMuted)) {
Spicetify.Player.toggleMute();
if (b) {
const volume = Spicetify.Player.getVolume();
if (volume > 0) Spicetify.Player._volumeBeforeMute = volume;
Spicetify.Player.setVolume(0);
} else {
Spicetify.Player.setVolume(Spicetify.Player._volumeBeforeMute);
}
},
formatTime: ms => {
Expand All @@ -83,7 +86,7 @@ window.Spicetify = {
seconds -= minutes * 60;
return `${minutes}:${seconds > 9 ? "" : "0"}${String(seconds)}`;
},
getHeart: () => document.querySelector(".control-button-heart")?.ariaChecked === "true",
getHeart: () => Spicetify.Player.origin._state.item.metadata["collection.in_collection"] === "true",
pause: () => {
Spicetify.Player.origin.pause();
},
Expand Down Expand Up @@ -111,8 +114,16 @@ window.Spicetify = {
skipForward: (amount = 15e3) => {
Spicetify.Player.origin.seekForward(amount);
},
setHeart: b => {
const uris = [Spicetify.Player.origin._state.item.uri];
if (b) {
Spicetify.Platform.LibraryAPI.add({ uris });
} else {
Spicetify.Platform.LibraryAPI.remove({ uris });
}
},
toggleHeart: () => {
document.querySelector(".control-button-heart")?.click();
Spicetify.Player.setHeart(!Spicetify.Player.getHeart());
}
},
test: () => {
Expand Down Expand Up @@ -202,7 +213,9 @@ window.Spicetify = {
"toggleRepeat",
"toggleShuffle",
"origin",
"playUri"
"playUri",
"setHeart",
"_volumeBeforeMute"
];

const REACT_COMPONENT = [
Expand Down Expand Up @@ -433,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 @@ -508,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 Expand Up @@ -686,10 +705,6 @@ window.Spicetify = {
playerState.current = Spicetify.Platform.PlayerAPI._state;
Spicetify.Player.data = playerState.current;

// for compatibility reasons
// TODO: remove in the future
Spicetify.Player.data["track"] = Spicetify.Player.data.item;

if (playerState.cache?.item.uri !== playerState.current?.item?.uri) {
const event = new Event("songchange");
event.data = Spicetify.Player.data;
Expand Down Expand Up @@ -717,6 +732,21 @@ window.Spicetify = {
Spicetify.removeFromQueue = uri => {
return Spicetify.Player.origin._queue.removeFromQueue(uri);
};

Spicetify.Player._volumeBeforeMute = Spicetify.Player.getVolume() || 0.7;
})();

(function waitForPlaybackAPI() {
if (!Spicetify.Platform?.PlaybackAPI) {
setTimeout(waitForPlaybackAPI, 10);
return;
}

Spicetify.Platform.PlaybackAPI._events.addListener("volume", ({ data: { volume } }) => {
if (volume > 0) {
Spicetify.Player._volumeBeforeMute = volume;
}
});
})();

Spicetify.getAudioData = async uri => {
Expand Down Expand Up @@ -1955,7 +1985,7 @@ Spicetify.Topbar = (function () {
}
}

function waitForTopbarMounted() {
(function waitForTopbarMounted() {
leftContainer = document.querySelector(".main-topBar-historyButtons");
rightContainer = document.querySelector(".main-noConnection");
if (!leftContainer || !rightContainer) {
Expand All @@ -1964,26 +1994,6 @@ Spicetify.Topbar = (function () {
}
leftContainer.append(...leftButtonsStash);
rightContainer.after(...rightButtonsStash);
}

waitForTopbarMounted();

(function attachObserver() {
const topBar = document.querySelector(".Root__top-bar");
if (!topBar) {
setTimeout(attachObserver, 300);
return;
}
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.removedNodes.length > 0) {
leftContainer = null;
rightContainer = null;
waitForTopbarMounted();
}
});
});
observer.observe(topBar, { childList: true });
})();

return { Button };
Expand Down Expand Up @@ -2357,37 +2367,6 @@ Spicetify.Playbar = (function () {
Spicetify.Panel.subPanelState(() => clearTimeout(refreshTimeout));
})();

(function waitForHistoryAPI() {
const main = document.querySelector(".main-view-container__scroll-node-child > main");
if (!main || !Spicetify.Platform?.History) {
setTimeout(waitForHistoryAPI, 300);
return;
}

let currentPath;
const observer = new MutationObserver(() => {
const child = main.lastElementChild;
const isPlaceholder = child?.tagName === "DIV" && !child?.children.length;
if (!isPlaceholder) {
const event = new Event("appchange");
event.data = {
path: currentPath,
container: child
};
Spicetify.Player.dispatchEvent(event);
observer.disconnect();
}
});

Spicetify.Platform.History.listen(({ pathname }) => {
if (!Spicetify.Player.eventListeners["appchange"]?.length) {
return;
}
currentPath = pathname;
observer.observe(main, { childList: true });
});
})();

(async function checkForUpdate() {
if (!Spicetify.Config) {
setTimeout(checkForUpdate, 300);
Expand Down
4 changes: 3 additions & 1 deletion spicetify.go
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"slices"
"strings"
Expand Down Expand Up @@ -239,7 +240,8 @@ func main() {
ex = "spicetify"
}

spotStat := spotifystatus.Get(utils.FindAppPath())
spotifyPath := filepath.Join(utils.FindAppPath(), "Apps")
spotStat := spotifystatus.Get(spotifyPath)
cmds := []string{"backup", "apply"}
if !spotStat.IsBackupable() {
cmds = append([]string{"restore"}, cmds...)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/cmd.go
Expand Up @@ -285,7 +285,7 @@ func ReadAnswer(info string, defaultAnswer bool, quietModeAnswer bool) bool {

// CheckUpdate fetches latest package version from Github API and inform user if there is new release
func CheckUpdate(version string) {
if !settingSection.Key("check_spicetify_update").MustBool() {
if !settingSection.Key("check_spicetify_update").MustBool() || version == "Dev" {
return
}

Expand Down
38 changes: 33 additions & 5 deletions src/preprocess/preprocess.go
Expand Up @@ -237,7 +237,31 @@ func disableSentry(input string) string {
func disableLogging(input string) string {
utils.Replace(&input, `sp://logging/v3/\w+`, "")
utils.Replace(&input, `[^"\/]+\/[^"\/]+\/(public\/)?v3\/events`, "")
utils.Replace(&input, `(\(e,\s*t\))\s*{(\s*return\s*this\.storageAdapter\.setItem\([${}\w."`+"`"+`()]+,\s*t\)\s*)}`, "${1}{return null}")

utils.Replace(&input, `key:"registerEventListeners",value:function\(\)\{`, "${0}return;")
utils.Replace(&input, `key:"logInteraction",value:function\([\w,]+\)\{`, "${0}return{interactionId:null,pageInstanceId:null};")
utils.Replace(&input, `key:"logNonAuthInteraction",value:function\([\w,]+\)\{`, "${0}return{interactionId:null,pageInstanceId:null};")
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:"createLoggingParams",value:function\([\w,]+\)\{`, "${0}return;")
utils.Replace(&input, `key:"initSendingEvents",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, `(\}createLoggingParams\([\w,]+\))\{.+?\}(async pullToLocal)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}initSendingEvents\(\))\{.+?\}(initializeContexts)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}send\([\w,:=!\d{}]+\))\{.+?\}(hasContext)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}lastFlush\(\))\{.+?\}(flush\(\))`, "${1}{return;}${2}")

return input
}

Expand Down Expand Up @@ -346,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 @@ -439,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.enqueueSnackbar=${0}`)

utils.Replace(
&input,
`\w+\s*=\s*\w\.call\(this,[^)]+\)\s*\|\|\s*this\)\.enqueueSnackbar`,
`Spicetify.Snackbar=${0}`)
`\w+.closeSnackbar=function`,
`Spicetify.Snackbar.closeSnackbar=${0}`)

return input
}
Expand Down
3 changes: 1 addition & 2 deletions src/utils/path-utils.go
Expand Up @@ -2,7 +2,6 @@ package utils

import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -79,7 +78,7 @@ var userAppsFolder = GetUserFolder("CustomApps")
var userExtensionsFolder = GetUserFolder("Extensions")

func GetCustomAppSubfolderPath(folderPath string) string {
entries, err := ioutil.ReadDir(folderPath)
entries, err := os.ReadDir(folderPath)
if err != nil {
return ""
}
Expand Down
7 changes: 3 additions & 4 deletions src/utils/utils.go
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -83,7 +82,7 @@ func Unzip(src, dest string) error {

// Copy .
func Copy(src, dest string, recursive bool, filters []string) error {
dir, err := ioutil.ReadDir(src)
dir, err := os.ReadDir(src)
if err != nil {
return err
}
Expand Down Expand Up @@ -182,15 +181,15 @@ func ReplaceOnce(input *string, regexpTerm string, replaceTerm string) {
// ModifyFile opens file, changes file content by executing
// `repl` callback function and writes new content.
func ModifyFile(path string, repl func(string) string) {
raw, err := ioutil.ReadFile(path)
raw, err := os.ReadFile(path)
if err != nil {
log.Print(err)
return
}

content := repl(string(raw))

ioutil.WriteFile(path, []byte(content), 0700)
os.WriteFile(path, []byte(content), 0700)
}

// GetSpotifyVersion .
Expand Down