diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 36 |
1 files changed, 17 insertions, 19 deletions
@@ -20,7 +20,12 @@ import ( ) func main() { - ui := NewUi() + config, err := loadConfig() + if err != nil { + log.Fatal(err) + } + + ui := NewUi(config) go func() { err := ui.Run() if err != nil { @@ -33,6 +38,7 @@ func main() { type State struct { sync.Mutex + Config GlobalConfig Theme *material.Theme Title string UrlEditor widget.Editor @@ -47,9 +53,11 @@ type Ui struct { State State } -func NewUi() *Ui { +func NewUi(config GlobalConfig) *Ui { ui := Ui{} + ui.State.Config = config + ui.State.Theme = material.NewTheme() ui.Window = new(app.Window) @@ -95,7 +103,11 @@ func (ui *Ui) HandleInputs(gtx layout.Context) { ui.State.PlayerCancel() } else { ui.State.PlayerContext, ui.State.PlayerCancel = context.WithCancel(context.Background()) - go play(ui.State.PlayerContext, ui.State.UrlEditor.Text(), ui) + 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.UrlEditor.Text(), targets, ui) } } } @@ -131,7 +143,7 @@ func (ui *Ui) Layout(gtx layout.Context) layout.Dimensions { }) } -func play(ctx context.Context, url string, ui *Ui) { +func play(ctx context.Context, url string, targets []net.HardwareAddr, ui *Ui) { setPlayingState := func(isPlaying bool) { ui.State.Lock() defer ui.Window.Invalidate() @@ -148,21 +160,7 @@ func play(ctx context.Context, url string, ui *Ui) { setPlayingState(true) defer setPlayingState(false) - config, err := loadConfig() - if err != nil { - log.Println(err) - } - - var devices []net.HardwareAddr - for _, entry := range config.Soundboxes { - mac, err := net.ParseMAC(entry.Mac) - if err != nil { - log.Printf("Failed to parse MAC: %v", err) - } - devices = append(devices, mac) - } - - err = soundbox.StreamURLContext(ctx, url, devices) + err := soundbox.StreamURLContext(ctx, url, targets) if err != nil { log.Println(err) } |