From f85551ae02f70cb2f94a02dcbc466f6061b31459 Mon Sep 17 00:00:00 2001 From: Daniel Prows Date: Thu, 10 Aug 2023 10:05:21 -0600 Subject: [PATCH] Fixing issue with feedback if there's more than one plugin on the stream deck. and also fixing the issue with view appear a different way --- src/main.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main.go b/src/main.go index d0d0db2..bd710a6 100644 --- a/src/main.go +++ b/src/main.go @@ -90,13 +90,12 @@ func setup(client *streamdeck.Client) { contexts[event.Context] = struct{}{} newSettings, err := volume.GetVolumeSettings() - _currentSettings = &volume.VolumeSettings{} if err != nil { return err } - return setFeedbackIfNeeded(ctx, client, newSettings) + return setFeedback(ctx, client, newSettings) }) action.RegisterHandler(streamdeck.WillDisappear, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error { @@ -120,17 +119,14 @@ func setup(client *streamdeck.Client) { ctx := context.Background() ctx = sdcontext.WithContext(ctx, ctxStr) - setFeedbackIfNeeded(ctx, client, newSettings) + setFeedback(ctx, client, newSettings) } + _currentSettings = newSettings } }() } -func setFeedbackIfNeeded(ctx context.Context, client *streamdeck.Client, newSettings *volume.VolumeSettings) error { - - if _currentSettings.OutputVolume == newSettings.OutputVolume && _currentSettings.OutputMuted == newSettings.OutputMuted { - return nil - } +func setFeedback(ctx context.Context, client *streamdeck.Client, newSettings *volume.VolumeSettings) error { payload := FeedbackPayload{} @@ -152,10 +148,19 @@ func setFeedbackIfNeeded(ctx context.Context, client *streamdeck.Client, newSett payload.Icon = ValueWithOpacity[any]{nil, opacity} - _currentSettings = newSettings return client.SetFeedback(ctx, payload) } +func setFeedbackIfNeeded(ctx context.Context, client *streamdeck.Client, newSettings *volume.VolumeSettings) error { + + if _currentSettings.OutputVolume == newSettings.OutputVolume && _currentSettings.OutputMuted == newSettings.OutputMuted { + return nil + } + + _currentSettings = newSettings + return setFeedback(ctx, client, newSettings) +} + type FeedbackPayload struct { Value ValueWithOpacity[string] `json:"value"` Indicator ValueWithOpacity[int] `json:"indicator"`