Skip to content

Commit 3e5dc5b

Browse files
rxriDelusoire
andcommitted
feat(cmd): add block-updates cmd to block spotify updates
Co-authored-by: Delusoire <[email protected]>
1 parent f005f8a commit 3e5dc5b

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

spicetify.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,22 @@ func main() {
150150
}
151151
return
152152

153+
case "block-updates":
154+
commands = commands[1:]
155+
if len(commands) == 0 {
156+
utils.PrintError("No parameter given. It has to be \"on\" or \"off\".")
157+
return
158+
}
159+
param := commands[0]
160+
if param == "on" {
161+
cmd.BlockSpotifyUpdates(true)
162+
} else if param == "off" {
163+
cmd.BlockSpotifyUpdates(false)
164+
} else {
165+
utils.PrintError("Invalid parameter. It has to be \"on\" or \"off\".")
166+
}
167+
return
168+
153169
case "path":
154170
commands = commands[1:]
155171
path, err := (func() (string, error) {
@@ -355,6 +371,8 @@ watch Enter watch mode.
355371
restart Restart Spotify client.
356372
357373
` + utils.Bold("NON-CHAINABLE COMMANDS") + `
374+
block-updates Blocks Spotify updates. Patches spotify executable. Accepts "on" or "off" as parameter.
375+
358376
path Prints path of Spotify's executable, userdata, and more.
359377
1. Print executable path:
360378
spicetify path
@@ -381,7 +399,6 @@ path Prints path of Spotify's executable, userdata, and more.
381399
"-c" (for config.ini)
382400
options: N/A.
383401
384-
385402
config 1. Print all config fields and values:
386403
spicetify config
387404

src/cmd/block-updates.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package cmd
2+
3+
import (
4+
"bytes"
5+
"os"
6+
"path/filepath"
7+
"runtime"
8+
"strings"
9+
10+
"github.com/spicetify/cli/src/utils"
11+
)
12+
13+
// Block spotify updates. Taken from https://github.com/Delusoire/bespoke-cli/blob/main/cmd/spotify/update.go
14+
func BlockSpotifyUpdates(enabled bool) {
15+
spotifyExecPath := GetSpotifyPath()
16+
switch runtime.GOOS {
17+
case "windows":
18+
spotifyExecPath = filepath.Join(spotifyExecPath, "Spotify.exe")
19+
case "linux":
20+
spotifyExecPath = filepath.Join(spotifyExecPath, "spotify")
21+
case "darwin":
22+
spotifyExecPath = filepath.Join(spotifyExecPath, "Spotify")
23+
}
24+
25+
file, err := os.OpenFile(spotifyExecPath, os.O_RDWR, 0644)
26+
if err != nil {
27+
utils.Fatal(err)
28+
return
29+
}
30+
defer file.Close()
31+
32+
buf := new(bytes.Buffer)
33+
buf.ReadFrom(file)
34+
content := buf.String()
35+
36+
i := strings.Index(content, "desktop-update/")
37+
if i == -1 {
38+
utils.PrintError("Can't find update endpoint in executable")
39+
return
40+
}
41+
var str, msg string
42+
if enabled {
43+
str = "v2/update"
44+
msg = "Enabled"
45+
} else {
46+
str = "no/thanks"
47+
msg = "Disabled"
48+
}
49+
file.WriteAt([]byte(str), int64(i+15))
50+
utils.PrintSuccess(msg + " Spotify updates!")
51+
}

0 commit comments

Comments
 (0)