Skip to content

Commit

Permalink
feat(cmd): add block-updates cmd to block spotify updates
Browse files Browse the repository at this point in the history
Co-authored-by: Delusoire <deluso7re@outlook.com>
  • Loading branch information
rxri and Delusoire committed Sep 7, 2024
1 parent f005f8a commit 3e5dc5b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
19 changes: 18 additions & 1 deletion spicetify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
51 changes: 51 additions & 0 deletions src/cmd/block-updates.go
Original file line number Diff line number Diff line change
@@ -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!")
}

0 comments on commit 3e5dc5b

Please sign in to comment.