Skip to content

Commit 32a27dc

Browse files
committed
fix(watch): properly handle goroutine for logging
1 parent fc73d04 commit 32a27dc

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

spicetify.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,12 @@ func main() {
178178
return
179179
}
180180
param := commands[0]
181-
if param == "block" {
181+
switch param {
182+
case "block":
182183
cmd.BlockSpotifyUpdates(true)
183-
} else if param == "unblock" {
184+
case "unblock":
184185
cmd.BlockSpotifyUpdates(false)
185-
} else {
186+
default:
186187
utils.PrintError("Invalid parameter. It has to be \"block\" or \"unblock\".")
187188
}
188189
return

src/cmd/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func InitSetting() {
193193

194194
schemeSection, err := colorCfg.GetSection(schemeName)
195195
if err != nil {
196-
println("Err")
196+
utils.PrintWarning("Color scheme '" + schemeName + "' not found; using first scheme")
197197
colorSection = sections[1]
198198
return
199199
}

src/cmd/watch.go

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"os"
66
"path/filepath"
7+
"sync"
78
"time"
89

910
spotifystatus "github.com/spicetify/cli/src/status/spotify"
@@ -13,6 +14,8 @@ import (
1314
var (
1415
debuggerURL string
1516
autoReloadFunc func()
17+
watchQueue chan func()
18+
watchQueueOnce sync.Once
1619
)
1720

1821
// Watch .
@@ -54,8 +57,13 @@ func Watch(liveUpdate bool) {
5457
utils.Fatal(err)
5558
}
5659

57-
refreshThemeJS()
58-
}, autoReloadFunc)
60+
enqueueWatchJob(func() {
61+
refreshThemeJS()
62+
if autoReloadFunc != nil {
63+
autoReloadFunc()
64+
}
65+
})
66+
}, nil)
5967
}
6068
}
6169

@@ -68,8 +76,13 @@ func Watch(liveUpdate bool) {
6876
utils.Fatal(err)
6977
}
7078

71-
refreshThemeAssets()
72-
}, autoReloadFunc)
79+
enqueueWatchJob(func() {
80+
refreshThemeAssets()
81+
if autoReloadFunc != nil {
82+
autoReloadFunc()
83+
}
84+
})
85+
}, nil)
7386
}
7487
}
7588

@@ -78,9 +91,14 @@ func Watch(liveUpdate bool) {
7891
utils.Fatal(err)
7992
}
8093

81-
InitSetting()
82-
refreshThemeCSS()
83-
}, autoReloadFunc)
94+
enqueueWatchJob(func() {
95+
InitSetting()
96+
refreshThemeCSS()
97+
if autoReloadFunc != nil {
98+
autoReloadFunc()
99+
}
100+
})
101+
}, nil)
84102
}
85103

86104
// WatchExtensions .
@@ -233,3 +251,15 @@ func startDebugger() {
233251
}
234252
}
235253
}
254+
255+
func enqueueWatchJob(job func()) {
256+
watchQueueOnce.Do(func() {
257+
watchQueue = make(chan func(), 64)
258+
go func() {
259+
for fn := range watchQueue {
260+
fn()
261+
}
262+
}()
263+
})
264+
watchQueue <- job
265+
}

0 commit comments

Comments
 (0)