forked from spicetify/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spicetify.go
517 lines (416 loc) · 14.1 KB
/
spicetify.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
package main
import (
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"runtime"
"strings"
"sync"
colorable "github.com/mattn/go-colorable"
"github.com/spicetify/spicetify-cli/src/cmd"
spotifystatus "github.com/spicetify/spicetify-cli/src/status/spotify"
"github.com/spicetify/spicetify-cli/src/utils"
)
var (
version string
)
var (
flags = []string{}
commands = []string{}
quiet = false
extensionFocus = false
appFocus = false
styleFocus = false
noRestart = false
liveUpdate = false
)
func init() {
if runtime.GOOS != "windows" &&
runtime.GOOS != "darwin" &&
runtime.GOOS != "linux" {
utils.PrintError("Unsupported OS.")
os.Exit(1)
}
if version == "" {
version = "Dev"
}
log.SetFlags(0)
// Supports print color output for Windows
log.SetOutput(colorable.NewColorableStdout())
// Separates flags and commands
for _, v := range os.Args[1:] {
if v[0] == '-' && v != "-1" {
if v[1] != '-' && len(v) > 2 {
for _, char := range v[1:] {
flags = append(flags, "-"+string(char))
}
} else {
flags = append(flags, v)
}
} else {
commands = append(commands, v)
}
}
for _, v := range flags {
switch v {
case "-c", "--config":
fmt.Println(cmd.GetConfigPath())
os.Exit(0)
case "-h", "--help":
kind := ""
if len(commands) > 0 {
kind = commands[0]
}
if kind == "config" {
helpConfig()
} else {
help()
}
os.Exit(0)
case "-v", "--version":
fmt.Println(version)
os.Exit(0)
case "-e", "--extension":
extensionFocus = true
liveUpdate = true
case "-a", "--app":
appFocus = true
liveUpdate = true
case "-q", "--quiet":
quiet = true
case "-n", "--no-restart":
noRestart = true
case "-s", "--style":
styleFocus = true
liveUpdate = true
case "-l", "--live-update":
extensionFocus = true
appFocus = true
styleFocus = true
liveUpdate = true
case "--check-update":
upgradeStatus := cmd.Upgrade(version)
if upgradeStatus {
ex, err := os.Executable()
if err != nil {
ex = "spicetify"
}
spotStat := spotifystatus.Get(utils.FindAppPath())
cmds := []string{"backup", "apply"}
if !spotStat.IsBackupable() {
cmds = append([]string{"restore"}, cmds...)
}
cmd := exec.Command(ex, cmds...)
utils.CmdScanner(cmd)
cmd = exec.Command(ex, strings.Join(commands[:], " "))
utils.CmdScanner(cmd)
os.Exit(0)
}
}
}
if quiet {
log.SetOutput(ioutil.Discard)
os.Stdout = nil
}
utils.MigrateConfigFolder()
cmd.InitConfig(quiet)
if len(commands) < 1 {
help()
os.Exit(0)
}
}
func main() {
// Show config directory without needing to initialize config
switch commands[0] {
case "config-dir":
cmd.ShowConfigDirectory()
return
}
cmd.InitPaths()
// Unchainable commands
switch commands[0] {
case "config":
commands = commands[1:]
if len(commands) == 0 {
cmd.DisplayAllConfig()
} else if len(commands) == 1 {
cmd.DisplayConfig(commands[0])
} else {
cmd.EditConfig(commands)
}
return
case "color":
commands = commands[1:]
if len(commands) == 0 {
cmd.DisplayColors()
} else {
cmd.EditColor(commands)
}
return
case "path":
commands = commands[1:]
path, err := (func() (string, error) {
if styleFocus {
if len(commands) == 0 {
return cmd.ThemeAllAssetsPath()
}
return cmd.ThemeAssetPath(commands[0])
} else if extensionFocus {
if len(commands) == 0 {
return cmd.ExtensionAllPath()
}
return cmd.ExtensionPath(commands[0])
} else if appFocus {
if len(commands) == 0 {
return cmd.AppAllPath()
}
return cmd.AppPath(commands[0])
} else {
if len(flags) != 0 && (flags[0] != "-e" ||
flags[0] != "-c" ||
flags[0] != "-a" ||
flags[0] != "-s") {
return "", errors.New("Invalid Flag\nAvailable Flags: -e, -c, -a, -s")
}
if len(commands) == 0 && len(flags) == 0 {
return utils.GetExecutableDir(), nil
} else if commands[0] == "all" {
return cmd.AllPaths()
} else if commands[0] == "userdata" {
return utils.GetSpicetifyFolder(), nil
}
return "", errors.New("Invalid Option\nAvailable Options: all, userdata")
}
})()
if err != nil {
utils.Fatal(err)
}
log.Println(path)
return
case "upgrade":
cmd.Upgrade(version)
return
case "watch":
var name []string
if len(commands) > 1 {
name = commands[1:]
}
var watchGroup sync.WaitGroup
if extensionFocus {
watchGroup.Add(1)
go func(name []string, liveUpdate bool) {
defer watchGroup.Done()
cmd.WatchExtensions(name, liveUpdate)
}(name, liveUpdate)
}
if appFocus {
watchGroup.Add(1)
go func(name []string, liveUpdate bool) {
defer watchGroup.Done()
cmd.WatchCustomApp(name, liveUpdate)
}(name, liveUpdate)
}
if styleFocus {
watchGroup.Add(1)
go func(liveUpdate bool) {
defer watchGroup.Done()
cmd.Watch(liveUpdate)
}(liveUpdate)
}
watchGroup.Wait()
return
}
utils.PrintBold("spicetify v" + version)
cmd.CheckUpgrade(version)
// Chainable commands
for _, v := range commands {
switch v {
case "backup":
cmd.Backup(version)
case "clear":
cmd.Clear()
case "apply":
cmd.Apply(version)
restartSpotify()
case "update":
if extensionFocus {
cmd.UpdateAllExtension()
} else {
cmd.UpdateTheme()
}
case "restore":
cmd.Restore()
restartSpotify()
case "enable-devtools":
cmd.SetDevTools()
cmd.EvalSpotifyRestart(true)
case "restart":
cmd.EvalSpotifyRestart(false)
case "auto":
cmd.Auto(version)
cmd.EvalSpotifyRestart(true)
default:
utils.PrintError(`Command "` + v + `" not found.`)
utils.PrintInfo(`Run "spicetify -h" for list of valid commands.`)
os.Exit(1)
}
}
}
func restartSpotify() {
if !noRestart {
cmd.EvalSpotifyRestart(false)
}
}
func help() {
utils.PrintBold("spicetify v" + version)
log.Println(utils.Bold("USAGE") + "\n" +
"spicetify [-q] [-e] [-a] \x1B[4mcommand\033[0m...\n" +
"spicetify {-c | --config} | {-v | --version} | {-h | --help}\n\n" +
utils.Bold("DESCRIPTION") + "\n" +
"Customize Spotify client UI and functionality\n\n" +
utils.Bold("CHAINABLE COMMANDS") + `
backup Start backup and preprocessing app files.
apply Apply customization.
update By default, updates theme's CSS, JS, colors, and assets.
Use with flag "-e" to update extensions.
restore Restore Spotify to original state.
clear Clear current backup files.
enable-devtools Enable Spotify's developer tools.
Press Ctrl + Shift + I (Windows/Linux) or Cmd + Option + I (macOS) in the Spotify client to start using.
watch Enter watch mode.
To update on change, use with any combination of the following flags:
"-e" (for extensions),
"-a" (for custom apps),
"-s" (for the active theme; color.ini, user.css, theme.js, and assets)
"-l" (for extensions, custom apps, and active theme)
restart Restart Spotify client.
` + utils.Bold("NON-CHAINABLE COMMANDS") + `
path Prints path of Spotify's executable, userdata, and more.
1. Print executable path:
spicetify path
2. Print userdata path:
spicetify path userdata
3. Print all paths:
spicetify path all
4. Toggle focus with flags:
spicetify path <flag> <option>
Available Flags and Options:
"-e" (for extensions),
options: root, extension name, blank for all.
"-a" (for custom apps),
options: root, <app-name>, blank for all.
"-s" (for the active theme)
options: root, folder, color, css, js, assets, blank for all.
"-c" (for config.ini)
options: N/A.
config 1. Print all config fields and values:
spicetify config
2. Print one config field's value:
spicetify config <field>
Example usage:
spicetify config color_scheme
spicetify config custom_apps
3. Change value of one or multiple config fields.
spicetify config <field> <value> [<field> <value> ...]
"extensions" and "custom_apps" fields are arrays of values,
so <value> will be appended to those fields' current value.
To remove one of array's values, postfix "-" to <value>.
Example usage:
- Enable "disable_sentry" preprocess:
spicetify config disable_sentry 1
- Add extension "myFakeExt.js" to current extensions list:
spicetify config extensions myFakeExt.js
- Remove extension "wrongname.js" from extensions list:
spicetify config extensions wrongname.js-
- Disable "inject_css" and enable "song_page"
spicetify config inject_css 0 song_page 1
color 1. Print all color fields and values.
spicetify color
Color boxes require 24-bit color (True color) supported
terminal to show colors correctly.
2. Change theme's one or multiple color values.
spicetify color <field> <value> [<field> <value> ...]
<value> can be in hex or decimal (rrr,ggg,bbb) format.
Example usage:
- Change main to ff0000
spicetify color main ff0000
- Change sidebar to 00ff00 and button to 0000ff
spicetify color sidebar 00ff00 button 0000ff
config-dir Shows config directory in file viewer
upgrade Upgrade spicetify latest version
` + utils.Bold("FLAGS") + `
-q, --quiet Quiet mode (no output). Be careful, dangerous operations
like clear backup, restore will proceed without prompting
permission.
-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).
-e, --extension Use with "update", "watch" or "path" command to
focus on extensions. Use with "watch" command to auto-reload Spotify when changes are made to extensions.
-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.
-n, --no-restart Do not restart Spotify after running command(s), except
"restart" command.
-l, --live-update Use with "watch" command to auto-reload Spotify when changes are made to any custom component (color.ini, user.css, extensions, apps).
-c, --config Print config file path and quit
-h, --help Print this help text and quit
-v, --version Print version number and quit
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").
For config information, run "spicetify -h config".
For more information and bug report: https://github.com/spicetify/spicetify-cli/`)
}
func helpConfig() {
utils.PrintBold("CONFIG MEANING")
log.Println(utils.Bold("[Setting]") + `
spotify_path
Path to Spotify directory
prefs_path
Path to Spotify's "prefs" file
current_theme
Name of folder of your theme
color_scheme
Color config section name in color.ini file.
If color_scheme is blank, first section in color.ini file would be used.
inject_css <0 | 1>
Whether custom css from user.css in theme folder is applied
inject_theme_js <0 | 1>
Whether custom js from theme.js in theme folder is applied
replace_colors <0 | 1>
Whether custom colors is applied
spotify_launch_flags
Command-line flags used when launching/restarting Spotify.
Separate each flag with "|".
List of valid flags: https://spicetify.app/docs/development/spotify-cli-flags
` + utils.Bold("[Preprocesses]") + `
disable_sentry <0 | 1>
Prevents Sentry and Amazon Qualaroo to send console log/error/warning to Spotify developers.
Enable if you don't want to catch their attention when developing extension or app.
disable_ui_logging <0 | 1>
Various elements logs every user clicks, scrolls.
Enable to stop logging and improve user experience.
remove_rtl_rule <0 | 1>
To support Arabic and other Right-To-Left language, Spotify added a lot of
CSS rules that are obsoleted to Left-To-Right users.
Enable to remove all of them and improve render speed.
expose_apis <0 | 1>
Leaks some Spotify's API, functions, objects to Spicetify global object that
are useful for making extensions to extend Spotify functionality.
disable_upgrade_check <0 | 1>
Prevent Spotify checking new version and visually notifying user.
[Windows] Note: Automatic update still works if you don't manually delete "SpotifyMigrator.exe" and "SpotifyUpdate.exe".
` + utils.Bold("[AdditionalOptions]") + `
custom_apps <string>
List of custom apps. Separate each app with "|".
extensions <string>
List of Javascript files to be executed along with Spotify main script.
Separate each extension with "|".
experimental_features <0 | 1>
Enable ability to activate unfinished or work-in-progress features that would eventually be released in future Spotify updates.
Open "Experimental features" popup in Profile menu.
home_config <0 | 1>
Enable ability to re-arrange sections in Home page.
Navigate to Home page, turn "Home config" mode on in Profile menu and hover on sections to show customization buttons.
sidebar_config <0 | 1>
Enable ability to stick, hide, re-arrange sidebar items.
Turn "Sidebar config" mode on in Profile menu and hover on sidebar items to show customization buttons.`)
}