From 3e5dc5b9b6cdfe7c58eb4c7441bb15f718f44838 Mon Sep 17 00:00:00 2001 From: ririxi Date: Sat, 7 Sep 2024 20:12:49 +0200 Subject: [PATCH] feat(cmd): add `block-updates` cmd to block spotify updates Co-authored-by: Delusoire --- spicetify.go | 19 ++++++++++++++- src/cmd/block-updates.go | 51 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 src/cmd/block-updates.go diff --git a/spicetify.go b/spicetify.go index d42a5009a5..90860c92b2 100644 --- a/spicetify.go +++ b/spicetify.go @@ -150,6 +150,22 @@ func main() { } return + case "block-updates": + commands = commands[1:] + if len(commands) == 0 { + utils.PrintError("No parameter given. It has to be \"on\" or \"off\".") + return + } + param := commands[0] + if param == "on" { + cmd.BlockSpotifyUpdates(true) + } else if param == "off" { + cmd.BlockSpotifyUpdates(false) + } else { + utils.PrintError("Invalid parameter. It has to be \"on\" or \"off\".") + } + return + case "path": commands = commands[1:] path, err := (func() (string, error) { @@ -355,6 +371,8 @@ watch Enter watch mode. restart Restart Spotify client. ` + utils.Bold("NON-CHAINABLE COMMANDS") + ` +block-updates Blocks Spotify updates. Patches spotify executable. Accepts "on" or "off" as parameter. + path Prints path of Spotify's executable, userdata, and more. 1. Print executable path: spicetify path @@ -381,7 +399,6 @@ path Prints path of Spotify's executable, userdata, and more. "-c" (for config.ini) options: N/A. - config 1. Print all config fields and values: spicetify config diff --git a/src/cmd/block-updates.go b/src/cmd/block-updates.go new file mode 100644 index 0000000000..061143810c --- /dev/null +++ b/src/cmd/block-updates.go @@ -0,0 +1,51 @@ +package cmd + +import ( + "bytes" + "os" + "path/filepath" + "runtime" + "strings" + + "github.com/spicetify/cli/src/utils" +) + +// Block spotify updates. Taken from https://github.com/Delusoire/bespoke-cli/blob/main/cmd/spotify/update.go +func BlockSpotifyUpdates(enabled bool) { + spotifyExecPath := GetSpotifyPath() + switch runtime.GOOS { + case "windows": + spotifyExecPath = filepath.Join(spotifyExecPath, "Spotify.exe") + case "linux": + spotifyExecPath = filepath.Join(spotifyExecPath, "spotify") + case "darwin": + spotifyExecPath = filepath.Join(spotifyExecPath, "Spotify") + } + + file, err := os.OpenFile(spotifyExecPath, os.O_RDWR, 0644) + if err != nil { + utils.Fatal(err) + return + } + defer file.Close() + + buf := new(bytes.Buffer) + buf.ReadFrom(file) + content := buf.String() + + i := strings.Index(content, "desktop-update/") + if i == -1 { + utils.PrintError("Can't find update endpoint in executable") + return + } + var str, msg string + if enabled { + str = "v2/update" + msg = "Enabled" + } else { + str = "no/thanks" + msg = "Disabled" + } + file.WriteAt([]byte(str), int64(i+15)) + utils.PrintSuccess(msg + " Spotify updates!") +}