fix race condition on exit: disable UI playback state callbacks
This commit is contained in:
+2
-1
@@ -151,7 +151,8 @@ func (a *App) LoginToDefaultServer(string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) Shutdown() {
|
func (a *App) Shutdown() {
|
||||||
a.Player.Stop()
|
a.PlaybackManager.DisableCallbacks()
|
||||||
|
a.Player.Stop() // will trigger scrobble check
|
||||||
a.Config.LocalPlayback.Volume = a.Player.GetVolume()
|
a.Config.LocalPlayback.Volume = a.Player.GetVolume()
|
||||||
a.cancel()
|
a.cancel()
|
||||||
a.Player.Destroy()
|
a.Player.Destroy()
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ type PlaybackManager struct {
|
|||||||
|
|
||||||
playTimeStopwatch util.Stopwatch
|
playTimeStopwatch util.Stopwatch
|
||||||
curTrackTime float64
|
curTrackTime float64
|
||||||
|
callbacksDisabled bool
|
||||||
|
|
||||||
playQueue []*subsonic.Child
|
playQueue []*subsonic.Child
|
||||||
nowPlayingIdx int64
|
nowPlayingIdx int64
|
||||||
@@ -99,6 +100,12 @@ func (p *PlaybackManager) IsSeeking() bool {
|
|||||||
return p.player.IsSeeking()
|
return p.player.IsSeeking()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Should only be called before quitting.
|
||||||
|
// Disables playback state callbacks being sent
|
||||||
|
func (p *PlaybackManager) DisableCallbacks() {
|
||||||
|
p.callbacksDisabled = true
|
||||||
|
}
|
||||||
|
|
||||||
// Gets the curently playing song, if any.
|
// Gets the curently playing song, if any.
|
||||||
func (p *PlaybackManager) NowPlaying() *subsonic.Child {
|
func (p *PlaybackManager) NowPlaying() *subsonic.Child {
|
||||||
if len(p.playQueue) == 0 || p.player.GetStatus().State == player.Stopped {
|
if len(p.playQueue) == 0 || p.player.GetStatus().State == player.Stopped {
|
||||||
@@ -310,6 +317,9 @@ func (p *PlaybackManager) sendNowPlayingScrobble() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PlaybackManager) invokeOnSongChangeCallbacks() {
|
func (p *PlaybackManager) invokeOnSongChangeCallbacks() {
|
||||||
|
if p.callbacksDisabled {
|
||||||
|
return
|
||||||
|
}
|
||||||
for _, cb := range p.onSongChange {
|
for _, cb := range p.onSongChange {
|
||||||
cb(p.NowPlaying(), p.lastScrobbled)
|
cb(p.NowPlaying(), p.lastScrobbled)
|
||||||
}
|
}
|
||||||
@@ -337,6 +347,9 @@ func (p *PlaybackManager) startPollTimePos() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PlaybackManager) doUpdateTimePos() {
|
func (p *PlaybackManager) doUpdateTimePos() {
|
||||||
|
if p.callbacksDisabled {
|
||||||
|
return
|
||||||
|
}
|
||||||
s := p.player.GetStatus()
|
s := p.player.GetStatus()
|
||||||
for _, cb := range p.onPlayTimeUpdate {
|
for _, cb := range p.onPlayTimeUpdate {
|
||||||
cb(s.TimePos, s.Duration)
|
cb(s.TimePos, s.Duration)
|
||||||
|
|||||||
Reference in New Issue
Block a user