summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go50
1 files changed, 31 insertions, 19 deletions
diff --git a/main.go b/main.go
index 00fd77b..727dad0 100644
--- a/main.go
+++ b/main.go
@@ -40,8 +40,9 @@ type State struct {
sync.Mutex
Config Config
Theme *material.Theme
+ IsPlaying bool
Title string
- UrlEditor widget.Editor
+ UrlSelector widget.Enum
PlayPauseButton widget.Clickable
PlayPauseButtonText string
PlayerContext context.Context
@@ -58,6 +59,8 @@ func NewUi(config Config) *Ui {
ui.State.Config = config
+ ui.State.IsPlaying = false
+
ui.State.Theme = material.NewTheme()
ui.Window = new(app.Window)
@@ -99,15 +102,19 @@ func (ui *Ui) HandleInputs(gtx layout.Context) {
defer ui.State.Unlock()
if ui.State.PlayPauseButton.Clicked(gtx) {
- if ui.State.UrlEditor.ReadOnly {
+ if ui.State.IsPlaying {
ui.State.PlayerCancel()
} else {
- ui.State.PlayerContext, ui.State.PlayerCancel = context.WithCancel(context.Background())
- var targets []net.HardwareAddr
- for _, entry := range ui.State.Config.Soundboxes {
- targets = append(targets, net.HardwareAddr(entry.Mac))
+ if ui.State.UrlSelector.Value == "" {
+ log.Println("A URL has to be selected.")
+ } else {
+ ui.State.PlayerContext, ui.State.PlayerCancel = context.WithCancel(context.Background())
+ var targets []net.HardwareAddr
+ for _, entry := range ui.State.Config.Soundboxes {
+ targets = append(targets, net.HardwareAddr(entry.Mac))
+ }
+ go play(ui.State.PlayerContext, ui.State.UrlSelector.Value, targets, ui)
}
- go play(ui.State.PlayerContext, ui.State.UrlEditor.Text(), targets, ui)
}
}
}
@@ -127,19 +134,24 @@ func (ui *Ui) Layout(gtx layout.Context) layout.Dimensions {
h1.Color = color.NRGBA{R: 88, G: 88, B: 88, A: 255}
h1.Alignment = text.Middle
- editor := material.Editor(ui.State.Theme, &ui.State.UrlEditor, "Audio stream URL")
- editor.Editor.Alignment = text.Middle
-
button := material.Button(ui.State.Theme, &ui.State.PlayPauseButton, ui.State.PlayPauseButtonText)
+ entries := []layout.FlexChild{
+ layout.Rigid(h1.Layout),
+ layout.Rigid(layout.Spacer{Height: unit.Dp(25)}.Layout),
+ }
+
+ for _, url := range ui.State.Config.URLs {
+ entries = append(entries, layout.Rigid(material.RadioButton(
+ ui.State.Theme, &ui.State.UrlSelector,
+ url.Url, url.Name).Layout))
+ }
+
+ entries = append(entries, layout.Rigid(layout.Spacer{Height: unit.Dp(25)}.Layout))
+ entries = append(entries, layout.Rigid(button.Layout))
+
return inset.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
- return flex.Layout(gtx,
- layout.Rigid(h1.Layout),
- layout.Rigid(layout.Spacer{Height: unit.Dp(25)}.Layout),
- layout.Rigid(editor.Layout),
- layout.Rigid(layout.Spacer{Height: unit.Dp(25)}.Layout),
- layout.Rigid(button.Layout),
- )
+ return flex.Layout(gtx, entries...)
})
}
@@ -149,8 +161,8 @@ func play(ctx context.Context, url string, targets []net.HardwareAddr, ui *Ui) {
defer ui.Window.Invalidate()
defer ui.State.Unlock()
- ui.State.UrlEditor.ReadOnly = isPlaying
- if isPlaying {
+ ui.State.IsPlaying = isPlaying
+ if ui.State.IsPlaying {
ui.State.PlayPauseButtonText = "Stop"
} else {
ui.State.PlayPauseButtonText = "Play"