MCPcopy
hub / github.com/spicetify/cli / BlockSpotifyUpdates

Function BlockSpotifyUpdates

src/cmd/block-updates.go:15–77  ·  view source on GitHub ↗

Block spotify updates. Taken from https://github.com/Delusoire/bespoke-cli/blob/main/cmd/spotify/update.go

(disabled bool)

Source from the content-addressed store, hash-verified

13
14// Block spotify updates. Taken from https://github.com/Delusoire/bespoke-cli/blob/main/cmd/spotify/update.go
15func BlockSpotifyUpdates(disabled bool) {
16 if runtime.GOOS == "linux" {
17 utils.PrintError("Auto-updates on linux should be disabled in package manager you installed spotify with.")
18 return
19 }
20 spotifyExecPath := GetSpotifyPath()
21 switch runtime.GOOS {
22 case "windows":
23 spotifyExecPath = filepath.Join(spotifyExecPath, "Spotify.exe")
24 case "darwin":
25 spotifyExecPath = filepath.Join(spotifyExecPath, "..", "MacOS", "Spotify")
26 }
27
28 var str, msg string
29 if runtime.GOOS == "darwin" {
30 homeDir, err := os.UserHomeDir()
31 if err != nil {
32 utils.PrintError("Cannot get user home directory")
33 return
34 }
35 updateDir := homeDir + "/Library/Application Support/Spotify/PersistentCache/Update"
36 if disabled {
37 exec.Command("pkill", "Spotify").Run()
38 exec.Command("mkdir", "-p", updateDir).Run()
39 exec.Command("chflags", "uchg", updateDir).Run()
40 msg = "Disabled"
41 } else {
42 exec.Command("pkill", "Spotify").Run()
43 exec.Command("mkdir", "-p", updateDir).Run()
44 exec.Command("chflags", "nouchg", updateDir).Run()
45 msg = "Enabled"
46 }
47
48 utils.PrintSuccess(msg + " Spotify updates!")
49 return
50 }
51
52 file, err := os.OpenFile(spotifyExecPath, os.O_RDWR, 0644)
53 if err != nil {
54 utils.Fatal(err)
55 return
56 }
57 defer file.Close()
58
59 buf := new(bytes.Buffer)
60 buf.ReadFrom(file)
61 content := buf.String()
62
63 i := strings.Index(content, "desktop-update/")
64 if i == -1 {
65 utils.PrintError("Can't find update endpoint in executable")
66 return
67 }
68 if disabled {
69 str = "no/thanks"
70 msg = "Disabled"
71 } else {
72 str = "v2/update"

Callers 1

mainFunction · 0.92

Calls 4

PrintErrorFunction · 0.92
PrintSuccessFunction · 0.92
FatalFunction · 0.92
GetSpotifyPathFunction · 0.85

Tested by

no test coverage detected