Skip to content

Commit fc73d04

Browse files
feat: logging improvements and refactoring (#3493)
1 parent 40c2df3 commit fc73d04

25 files changed

+443
-438
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Follow the steps outlined in the [documentation](https://spicetify.app/docs/deve
9595
9696
### Improving The Documentation
9797
98-
To improve the [documentation](https://spicetify.app/docs/getting-started), navigate to the documentation [repository](https://github.com/spicetify/spicetify-docs).
98+
To improve the [documentation](https://spicetify.app/docs/getting-started), navigate to the documentation [repository](https://github.com/spicetify/docs).
9999
100100
### Commit Message Format
101101

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.24.2
55
require (
66
github.com/go-ini/ini v1.67.0
77
github.com/mattn/go-colorable v0.1.14
8-
github.com/pterm/pterm v0.12.81
8+
github.com/pterm/pterm v0.12.80
99
golang.org/x/net v0.44.0
1010
golang.org/x/sys v0.36.0
1111
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ github.com/pterm/pterm v0.12.31/go.mod h1:32ZAWZVXD7ZfG0s8qqHXePte42kdz8ECtRyEej
5454
github.com/pterm/pterm v0.12.33/go.mod h1:x+h2uL+n7CP/rel9+bImHD5lF3nM9vJj80k9ybiiTTE=
5555
github.com/pterm/pterm v0.12.36/go.mod h1:NjiL09hFhT/vWjQHSj1athJpx6H8cjpHXNAK5bUw8T8=
5656
github.com/pterm/pterm v0.12.40/go.mod h1:ffwPLwlbXxP+rxT0GsgDTzS3y3rmpAO1NMjUkGTYf8s=
57-
github.com/pterm/pterm v0.12.81 h1:ju+j5I2++FO1jBKMmscgh5h5DPFDFMB7epEjSoKehKA=
58-
github.com/pterm/pterm v0.12.81/go.mod h1:TyuyrPjnxfwP+ccJdBTeWHtd/e0ybQHkOS/TakajZCw=
57+
github.com/pterm/pterm v0.12.80 h1:mM55B+GnKUnLMUSqhdINe4s6tOuVQIetQ3my8JGyAIg=
58+
github.com/pterm/pterm v0.12.80/go.mod h1:c6DeF9bSnOSeFPZlfs4ZRAFcf5SCoTwvwQ5xaKGQlHo=
5959
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
6060
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
6161
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=

spicetify.go

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"errors"
5-
"fmt"
65
"io"
76
"log"
87
"os"
@@ -14,6 +13,7 @@ import (
1413
"sync"
1514

1615
colorable "github.com/mattn/go-colorable"
16+
"github.com/pterm/pterm"
1717
"github.com/spicetify/cli/src/cmd"
1818
spotifystatus "github.com/spicetify/cli/src/status/spotify"
1919
"github.com/spicetify/cli/src/utils"
@@ -53,8 +53,8 @@ func init() {
5353

5454
// Separates flags and commands
5555
for _, v := range os.Args[1:] {
56-
if len(v) > 0 && v[0] == '-' && v != "-1" {
57-
if v[1] != '-' && len(v) > 2 {
56+
if len(v) > 0 && v[0] == '-' {
57+
if len(v) > 2 && v[1] != '-' {
5858
for _, char := range v[1:] {
5959
flags = append(flags, "-"+string(char))
6060
}
@@ -71,7 +71,7 @@ func init() {
7171
case "--bypass-admin":
7272
bypassAdminCheck = true
7373
case "-c", "--config":
74-
fmt.Println(cmd.GetConfigPath())
74+
log.Println(cmd.GetConfigPath())
7575
os.Exit(0)
7676
case "-h", "--help":
7777
kind := ""
@@ -86,7 +86,7 @@ func init() {
8686

8787
os.Exit(0)
8888
case "-v", "--version":
89-
fmt.Println(version)
89+
log.Println(version)
9090
os.Exit(0)
9191
case "-e", "--extension":
9292
extensionFocus = true
@@ -112,14 +112,14 @@ func init() {
112112
if quiet {
113113
log.SetOutput(io.Discard)
114114
os.Stdout = nil
115+
pterm.DisableOutput()
115116
}
116117

117118
if isAdmin.Check(bypassAdminCheck) {
118-
utils.PrintError("Spicetify should not be run with administrator/root privileges")
119-
utils.PrintError("Running as admin can cause Spotify to show a black/blank window after applying spicetify")
119+
utils.PrintError("Spicetify should NOT be run with administrator or root privileges")
120+
utils.PrintError("Doing so can cause Spotify to show a black/blank window after applying!")
120121
utils.PrintError("This happens because Spotify (running as a normal user) can't access files modified with admin privileges")
121-
utils.PrintInfo("If you understand the risks and need to continue anyway, you can use the '--bypass-admin' flag.")
122-
utils.PrintInfo("Spicetify is now exiting...")
122+
utils.PrintInfo("If you understand the risks and need to continue, you can use the '--bypass-admin' flag.")
123123
os.Exit(1)
124124
}
125125

@@ -291,24 +291,27 @@ func main() {
291291

292292
spotStat := spotifystatus.Get(spotifyPath)
293293
if spotStat.IsBackupable() {
294-
utils.PrintNote("spicetify is already up-to-date! If you ran this command because spicetify disappeared after Spotify updated, we'll attempt to fix it for you right now.")
295-
cmd.Backup(version)
294+
utils.PrintNote("spicetify is up-to-date! If you ran this because spicetify disappeared after Spotify updated, we'll attempt to fix it for you right now.")
295+
cmd.Backup(version, true)
296296
cmd.CheckStates()
297297
cmd.InitSetting()
298298
cmd.Apply(version)
299-
restartSpotify()
299+
if !noRestart {
300+
cmd.SpotifyRestart()
301+
}
300302
}
301303

302304
return
303305
} else {
304306
cmd.CheckUpdate(version)
305307
}
306308

309+
var shouldRestart bool = false
307310
// Chainable commands
308311
for _, v := range commands {
309312
switch v {
310313
case "backup":
311-
cmd.Backup(version)
314+
cmd.Backup(version, slices.Contains(commands, "apply"))
312315

313316
case "clear":
314317
cmd.Clear()
@@ -317,7 +320,7 @@ func main() {
317320
cmd.CheckStates()
318321
cmd.InitSetting()
319322
cmd.Apply(version)
320-
restartSpotify()
323+
shouldRestart = true
321324

322325
case "refresh":
323326
cmd.CheckStates()
@@ -332,30 +335,27 @@ func main() {
332335

333336
case "restore":
334337
cmd.Restore()
335-
restartSpotify()
338+
shouldRestart = true
336339

337340
case "enable-devtools":
338-
cmd.SetDevTools()
339-
cmd.EvalSpotifyRestart(true)
341+
cmd.EnableDevTools()
342+
shouldRestart = true
340343

341344
case "restart":
342-
cmd.EvalSpotifyRestart(false)
345+
cmd.SpotifyRestart()
343346

344347
case "auto":
345348
cmd.Auto(version)
346-
cmd.EvalSpotifyRestart(true)
349+
shouldRestart = true
347350

348351
default:
349-
utils.PrintError(`Command "` + v + `" not found.`)
350-
utils.PrintInfo(`Run "spicetify -h" for list of valid commands.`)
351-
os.Exit(1)
352+
utils.Fatal(errors.New(`Command "` + v + `" not found.
353+
Run "spicetify -h" for a list of valid commands.`))
352354
}
353355
}
354-
}
355356

356-
func restartSpotify() {
357-
if !noRestart {
358-
cmd.EvalSpotifyRestart(false)
357+
if !noRestart && !slices.Contains(commands, "restart") && shouldRestart {
358+
cmd.SpotifyRestart()
359359
}
360360
}
361361

@@ -367,34 +367,35 @@ func help() {
367367
utils.Bold("DESCRIPTION") + "\n" +
368368
"Customize Spotify client UI and functionality\n\n" +
369369
utils.Bold("CHAINABLE COMMANDS") + `
370-
backup Start backup and preprocessing app files.
370+
backup Start backup and preprocessing of app files.
371371
372372
apply Apply customization.
373373
374374
refresh Refresh the theme's CSS, JS, colors, and assets.
375-
Use with flag "-e" to update extensions.
375+
Use with flag "-e" to update extensions or with flag "-a" to update custom apps.
376376
377377
restore Restore Spotify to original state.
378378
379379
clear Clear current backup files.
380380
381381
enable-devtools Enable Spotify's developer tools.
382-
Press Ctrl + Shift + I (Windows/Linux) or Cmd + Option + I (macOS) in the Spotify client to start using.
382+
Press Ctrl + Shift + I (Windows/Linux) or Cmd + Option + I (macOS) in the Spotify client to open.
383383
384384
watch Enter watch mode.
385385
To update on change, use with any combination of the following flags:
386386
"-e" (for extensions),
387387
"-a" (for custom apps),
388388
"-s" (for the active theme; color.ini, user.css, theme.js, and assets)
389-
"-l" (for extensions, custom apps, and active theme)
389+
"-l" (for all of the above)
390390
391391
392392
restart Restart Spotify client.
393393
394394
` + utils.Bold("NON-CHAINABLE COMMANDS") + `
395-
spotify-updates Blocks Spotify updates. Patches spotify executable. Accepts "block" or "unblock" as parameter.
395+
spotify-updates Block Spotify updates by patching spotify executable.
396+
Accepts "block" or "unblock" as the parameter.
396397
397-
path Prints path of Spotify's executable, userdata, and more.
398+
path Print path of Spotify's executable, userdata, and more.
398399
1. Print executable path:
399400
spicetify path
400401
@@ -407,7 +408,7 @@ path Prints path of Spotify's executable, userdata, and more.
407408
4. Toggle focus with flags:
408409
spicetify path <flag> <option>
409410
410-
Available Flags and Options:
411+
Available flags and options:
411412
"-e" (for extensions),
412413
options: root, extension name, blank for all.
413414
@@ -464,36 +465,38 @@ color 1. Print all color fields and values.
464465
- Change sidebar to 00ff00 and button to 0000ff
465466
spicetify color sidebar 00ff00 button 0000ff
466467
467-
config-dir Shows config directory in file viewer
468+
config-dir Show config directory in file viewer
468469
469-
upgrade|update Update spicetify latest version
470+
upgrade|update Update spicetify to the latest version if an update is available
470471
471472
` + utils.Bold("FLAGS") + `
472-
-q, --quiet Quiet mode (no output). Be careful, dangerous operations
473-
like clear backup, restore will proceed without prompting
474-
permission.
473+
-q, --quiet Quiet mode (no output).
475474
476-
-s, --style Use with "watch" command to auto-reload Spotify when changes are made to the active theme (color.ini, user.css, theme.js, assets).
475+
-s, --style Use with "watch" or "path" to focus on the active theme.
476+
Use with "watch" to auto-reload Spotify when changes are made to the active theme.
477477
478-
-e, --extension Use with "refresh", "watch" or "path" command to
479-
focus on extensions. Use with "watch" command to auto-reload Spotify when changes are made to extensions.
478+
-e, --extension Use with "refresh", "watch" or "path" to focus on extensions.
479+
Use with "watch" to auto-reload Spotify when changes are made to extensions.
480480
481-
-a, --app Use with "watch" or "path" to focus on custom apps. Use with "watch" command to auto-reload Spotify when changes are made to apps.
481+
-a, --app Use with "refresh", "watch" or "path" to focus on custom apps.
482+
Use with "watch" to auto-reload Spotify when changes are made to apps.
482483
483-
-n, --no-restart Do not restart Spotify after running command(s), except
484-
"restart" command.
484+
-l, --live-refresh Use with "watch" command to auto-reload Spotify when changes
485+
are made to any custom component.
485486
486-
-l, --live-refresh Use with "watch" command to auto-reload Spotify when changes are made to any custom component (color.ini, user.css, extensions, apps).
487+
-n, --no-restart Do not restart Spotify after running command(s),
488+
except for the "restart" command.
489+
490+
--bypass-admin Bypass admin or root (sudo) check. NOT RECOMMENDED
487491
488492
-c, --config Print config file path and quit
489493
490494
-h, --help Print this help text and quit
491495
492496
-v, --version Print version number and quit
493497
494-
When using the "watch" command, any combination of the style (-s), extension (-e), and app (-a) flags can be used (ex. "watch -s -e" or "watch -e -a").
495498
For config information, run "spicetify -h config".
496-
For more information and bug report: https://github.com/spicetify/cli/`)
499+
For more information and reporting bugs: https://github.com/spicetify/cli/`)
497500
}
498501

499502
func helpConfig() {
@@ -516,12 +519,12 @@ inject_css <0 | 1>
516519
Whether custom css from user.css in theme folder is applied
517520
518521
inject_theme_js <0 | 1>
519-
Whether custom js from theme.js in theme folder is applied
522+
Whether custom js from theme.js in theme folder is applied
520523
521524
replace_colors <0 | 1>
522525
Whether custom colors is applied
523526
524-
spotify_launch_flags
527+
spotify_launch_flags <string>
525528
Command-line flags used when launching/restarting Spotify.
526529
Separate each flag with "|".
527530
List of valid flags: https://spicetify.app/docs/development/spotify-cli-flags
@@ -530,7 +533,7 @@ always_enable_devtools <0 | 1>
530533
Whether Chrome DevTools is enabled when launching/restarting Spotify.
531534
532535
check_spicetify_update <0 | 1>
533-
Whether to check for CLI update when running Spicetify.
536+
Whether to always check for updates when running Spicetify.
534537
535538
` + utils.Bold("[Preprocesses]") + `
536539
disable_sentry <0 | 1>
@@ -568,5 +571,8 @@ home_config <0 | 1>
568571
569572
sidebar_config <0 | 1>
570573
Enable ability to stick, hide, re-arrange sidebar items.
571-
Turn "Sidebar config" mode on in Profile menu and hover on sidebar items to show customization buttons.`)
574+
Turn "Sidebar config" mode on in Profile menu and hover on sidebar items to show customization buttons.
575+
576+
` + utils.Bold("[Patch]") + `
577+
Allows you to apply custom patches to Spotify.`)
572578
}

src/apply/apply.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ func insertCustomApp(jsPath string, flags Flag) {
275275

276276
if (len(reactSymbs) < 2) || (len(eleSymbs) == 0) {
277277
utils.PrintError("Spotify version mismatch with Spicetify. Please report it on our github repository.")
278-
utils.PrintInfo("Spicetify might have been updated for this version already. Please run `spicetify update` to check for a new version. If one isn't available yet, please wait for the update to be released.")
278+
utils.PrintInfo("Spicetify might have been updated for this version already. Please run `spicetify update` to check for a new version.")
279+
utils.PrintInfo("If one isn't available yet, please wait for an update to be released or downgrade Spotify to a supported version.")
279280
return content
280281
}
281282

src/backup/backup.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func Start(appPath, backupPath string) error {
1414

1515
// Extract all SPA files from backupPath to extractPath
1616
func Extract(backupPath, extractPath string) {
17+
spinner, _ := utils.Spinner.Start("Extracting backup")
1718
for _, app := range []string{"xpui", "login"} {
1819
appPath := filepath.Join(backupPath, app+".spa")
1920
appExtractToFolder := filepath.Join(extractPath, app)
@@ -25,7 +26,9 @@ func Extract(backupPath, extractPath string) {
2526

2627
err = utils.Unzip(appPath, appExtractToFolder)
2728
if err != nil {
29+
spinner.Fail("Failed to extract backup")
2830
utils.Fatal(err)
2931
}
3032
}
33+
spinner.Success("Extracted backup")
3134
}

0 commit comments

Comments
 (0)