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