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

Function Watch

src/cmd/watch.go:22–102  ·  view source on GitHub ↗

Watch .

(liveUpdate bool)

Source from the content-addressed store, hash-verified

20
21// Watch .
22func Watch(liveUpdate bool) {
23 if !isValidForWatching() {
24 os.Exit(1)
25 }
26
27 InitSetting()
28
29 if liveUpdate {
30 startDebugger()
31 }
32
33 if len(themeFolder) == 0 {
34 utils.PrintError(`Config "current_theme" is blank. No theme asset to watch`)
35 os.Exit(1)
36 }
37
38 colorPath := filepath.Join(themeFolder, "color.ini")
39 cssPath := filepath.Join(themeFolder, "user.css")
40
41 fileList := []string{}
42 if replaceColors {
43 fileList = append(fileList, colorPath)
44 }
45
46 if injectCSS {
47 fileList = append(fileList, cssPath)
48 }
49
50 if injectJS {
51 jsPath := filepath.Join(themeFolder, "theme.js")
52 pathArr := []string{jsPath}
53
54 if _, err := os.Stat(jsPath); err == nil {
55 go utils.Watch(pathArr, func(_ string, err error) {
56 if err != nil {
57 utils.Fatal(err)
58 }
59
60 enqueueWatchJob(func() {
61 refreshThemeJS()
62 if autoReloadFunc != nil {
63 autoReloadFunc()
64 }
65 })
66 }, nil)
67 }
68 }
69
70 if overwriteAssets {
71 assetPath := filepath.Join(themeFolder, "assets")
72
73 if _, err := os.Stat(assetPath); err == nil {
74 go utils.WatchRecursive(assetPath, func(_ string, err error) {
75 if err != nil {
76 utils.Fatal(err)
77 }
78
79 enqueueWatchJob(func() {

Callers 1

mainFunction · 0.92

Calls 11

PrintErrorFunction · 0.92
WatchFunction · 0.92
FatalFunction · 0.92
WatchRecursiveFunction · 0.92
isValidForWatchingFunction · 0.85
InitSettingFunction · 0.85
startDebuggerFunction · 0.85
enqueueWatchJobFunction · 0.85
refreshThemeJSFunction · 0.85
refreshThemeAssetsFunction · 0.85
refreshThemeCSSFunction · 0.85

Tested by

no test coverage detected