From 0637b2f8169ad7153c49e81ac75601910387c97f Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Wed, 6 Sep 2023 16:01:15 -0500 Subject: [PATCH] fix: Fix panic if initial connection fails --- internal/device/watch.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/device/watch.go b/internal/device/watch.go index 1475dfa..f2aa387 100644 --- a/internal/device/watch.go +++ b/internal/device/watch.go @@ -211,13 +211,14 @@ func (d *Device) tick() error { func (d *Device) connect(opts ...application.ApplicationOption) error { if d.app != nil { _ = d.app.Close(false) + d.app = nil } opts = append( opts, application.WithSkipadSleep(config.Default.PlayingInterval), application.WithSkipadRetries(int(time.Minute/config.Default.PlayingInterval)), ) - d.app = application.NewApplication(opts...) + app := application.NewApplication(opts...) d.app.AddMessageFunc(d.onMessage) if err := util.Retry(d.ctx, 6, 500*time.Millisecond, func(try uint) error { @@ -239,6 +240,8 @@ func (d *Device) connect(opts ...application.ApplicationOption) error { d.logger.Info("Connected to cast device.") } + d.app = app + return nil }