ensure casting playback stops when quitting app

This commit is contained in:
Drew Weymouth
2025-03-29 15:15:13 -07:00
parent ff455528d6
commit 6a7f06769d
3 changed files with 20 additions and 5 deletions
+1 -1
View File
@@ -463,7 +463,7 @@ func (a *App) Shutdown() {
a.WinSMTC.Shutdown() a.WinSMTC.Shutdown()
} }
a.PlaybackManager.DisableCallbacks() a.PlaybackManager.DisableCallbacks()
a.PlaybackManager.Stop() // will trigger scrobble check a.PlaybackManager.Shutdown() // will trigger scrobble check
a.cancel() a.cancel()
a.LocalPlayer.Destroy() a.LocalPlayer.Destroy()
} }
+12 -4
View File
@@ -31,10 +31,11 @@ const (
) )
type playbackCommand struct { type playbackCommand struct {
Type playbackCommandType Type playbackCommandType
Arg any Arg any
Arg2 any Arg2 any
Arg3 any Arg3 any
OnDone func()
} }
// playbackCommandQueue is a queue to accumulate player commands from the UI // playbackCommandQueue is a queue to accumulate player commands from the UI
@@ -65,6 +66,13 @@ func (c *playbackCommandQueue) Stop() {
playbackCommand{Type: cmdStop}) playbackCommand{Type: cmdStop})
} }
func (c *playbackCommandQueue) StopAndWait() {
done := make(chan struct{})
c.filterCommandsAndAdd([]playbackCommandType{cmdContinue, cmdPause, cmdStop},
playbackCommand{Type: cmdStop, OnDone: func() { close(done) }})
<-done
}
func (c *playbackCommandQueue) Continue() { func (c *playbackCommandQueue) Continue() {
c.filterCommandsAndAdd([]playbackCommandType{cmdContinue, cmdPause, cmdStop}, c.filterCommandsAndAdd([]playbackCommandType{cmdContinue, cmdPause, cmdStop},
playbackCommand{Type: cmdContinue}) playbackCommand{Type: cmdContinue})
+7
View File
@@ -512,6 +512,10 @@ func (p *PlaybackManager) Stop() {
p.cmdQueue.Stop() p.cmdQueue.Stop()
} }
func (p *PlaybackManager) Shutdown() {
p.cmdQueue.StopAndWait()
}
func (p *PlaybackManager) Pause() { func (p *PlaybackManager) Pause() {
p.cmdQueue.Pause() p.cmdQueue.Pause()
} }
@@ -662,6 +666,9 @@ func (p *PlaybackManager) runCmdQueue(ctx context.Context) {
mpv.ForceRestartPlayback() mpv.ForceRestartPlayback()
} }
} }
if c.OnDone != nil {
c.OnDone()
}
} }
} }
} }