Quit by disabling all sources

This commit is contained in:
nemunaire 2023-11-15 12:10:11 +01:00
parent d2090bee67
commit bfd0bb866a

22
app.go
View File

@ -10,6 +10,7 @@ import (
"git.nemunai.re/nemunaire/hathoris/api" "git.nemunai.re/nemunaire/hathoris/api"
"git.nemunai.re/nemunaire/hathoris/config" "git.nemunai.re/nemunaire/hathoris/config"
"git.nemunai.re/nemunaire/hathoris/sources"
"git.nemunai.re/nemunaire/hathoris/ui" "git.nemunai.re/nemunaire/hathoris/ui"
) )
@ -60,6 +61,27 @@ func (app *App) Start() {
} }
func (app *App) Stop() { func (app *App) Stop() {
// Disable all sources
someEnabled := false
for k, src := range sources.SoundSources {
if src.IsEnabled() {
someEnabled = true
go func(k string, src sources.SoundSource) {
log.Printf("Stopping %s...", k)
err := src.Disable()
if err != nil {
log.Printf("Unable to disable %s source", k)
}
log.Printf("%s stopped", k)
}(k, src)
}
}
// Wait for fadeout
if someEnabled {
time.Sleep(2000 * time.Millisecond)
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
if err := app.srv.Shutdown(ctx); err != nil { if err := app.srv.Shutdown(ctx); err != nil {