Communicate current title if the player is compatible
This commit is contained in:
parent
a591ed17a6
commit
b8bff830ca
@ -13,10 +13,11 @@ import (
|
||||
)
|
||||
|
||||
type SourceState struct {
|
||||
Name string `json:"name"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Active *bool `json:"active,omitempty"`
|
||||
Controlable bool `json:"controlable,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Active *bool `json:"active,omitempty"`
|
||||
Controlable bool `json:"controlable,omitempty"`
|
||||
CurrentTitle string `json:"currentTitle,omitempty"`
|
||||
}
|
||||
|
||||
func declareSourcesRoutes(cfg *config.Config, router *gin.RouterGroup) {
|
||||
@ -27,11 +28,17 @@ func declareSourcesRoutes(cfg *config.Config, router *gin.RouterGroup) {
|
||||
active := src.IsActive()
|
||||
_, controlable := src.(inputs.ControlableInput)
|
||||
|
||||
var title string
|
||||
if s, ok := src.(sources.PlayingSource); ok && active {
|
||||
title = s.CurrentlyPlaying()
|
||||
}
|
||||
|
||||
ret[k] = &SourceState{
|
||||
Name: src.GetName(),
|
||||
Enabled: src.IsEnabled(),
|
||||
Active: &active,
|
||||
Controlable: controlable,
|
||||
Name: src.GetName(),
|
||||
Enabled: src.IsEnabled(),
|
||||
Active: &active,
|
||||
Controlable: controlable,
|
||||
CurrentTitle: title,
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,11 +52,19 @@ func declareSourcesRoutes(cfg *config.Config, router *gin.RouterGroup) {
|
||||
src := c.MustGet("source").(sources.SoundSource)
|
||||
|
||||
active := src.IsActive()
|
||||
_, controlable := src.(inputs.ControlableInput)
|
||||
|
||||
var title string
|
||||
if s, ok := src.(sources.PlayingSource); ok && active {
|
||||
title = s.CurrentlyPlaying()
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, &SourceState{
|
||||
Name: src.GetName(),
|
||||
Enabled: src.IsEnabled(),
|
||||
Active: &active,
|
||||
Name: src.GetName(),
|
||||
Enabled: src.IsEnabled(),
|
||||
Active: &active,
|
||||
Controlable: controlable,
|
||||
CurrentTitle: title,
|
||||
})
|
||||
})
|
||||
sourcesRoutes.GET("/settings", func(c *gin.Context) {
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
@ -285,7 +284,6 @@ func (cc *CardControl) CsetAmixer(values ...string) error {
|
||||
fmt.Sprintf("numid=%d", cc.NumID),
|
||||
}
|
||||
opts = append(opts, strings.Join(values, ","))
|
||||
log.Println(opts)
|
||||
cmd := exec.Command("amixer", opts...)
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
|
@ -4,16 +4,12 @@
|
||||
|
||||
<ul class="list-group list-group-flush">
|
||||
{#each $activeSources as source}
|
||||
<li class="list-group-item py-3 d-flex justify-content-between">
|
||||
<li class="list-group-item py-3 d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<strong>{source.name}</strong>
|
||||
{#await source.currently()}
|
||||
<div class="spinner-border spinner-border-sm" role="status">
|
||||
<span class="visually-hidden">Loading...</span>
|
||||
</div>
|
||||
{:then title}
|
||||
<span class="text-muted">{title}</span>
|
||||
{/await}
|
||||
{#if source.currentTitle}
|
||||
<span class="text-muted">{source.currentTitle}</span>
|
||||
{/if}
|
||||
</div>
|
||||
{#if source.controlable}
|
||||
<div>
|
||||
|
@ -6,11 +6,12 @@ export class Source {
|
||||
}
|
||||
}
|
||||
|
||||
update({ name, enabled, active, controlable }) {
|
||||
update({ name, enabled, active, controlable, currentTitle }) {
|
||||
this.name = name;
|
||||
this.enabled = enabled;
|
||||
this.active = active;
|
||||
this.controlable = controlable;
|
||||
this.currentTitle = currentTitle;
|
||||
}
|
||||
|
||||
async activate() {
|
||||
|
@ -24,15 +24,11 @@
|
||||
<div class="d-inline-block me-3">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
{#await source.currently()}
|
||||
<div class="spinner-border spinner-border-sm" role="status">
|
||||
<span class="visually-hidden">Loading...</span>
|
||||
</div> <span class="text-muted">@ {source.name}</span>
|
||||
{:then title}
|
||||
<strong>{title}</strong> <span class="text-muted">@ {source.name}</span>
|
||||
{:catch error}
|
||||
{#if source.currentTitle}
|
||||
<strong>{source.currentTitle}</strong> <span class="text-muted">@ {source.name}</span>
|
||||
{:else}
|
||||
{source.name} activée
|
||||
{/await}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user