Skip to content

Commit

Permalink
Add support for optional State parameter in SetImage and SetTitle events
Browse files Browse the repository at this point in the history
New optional state parameter in setTitle and setImage APIs,
state: A 0-based integer value representing the state of an action with multiple states. This is an optional parameter. If not specified, the title is set to all states.
  • Loading branch information
BarRaider committed Jun 21, 2020
1 parent c2c78bc commit d0edbf1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
10 changes: 7 additions & 3 deletions streamdeck-client-csharp/Messages/SetImageMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ internal class SetImageMessage : IMessage
[JsonProperty("payload")]
public IPayload Payload { get; private set; }

public SetImageMessage(string base64Image, string context, SDKTarget target)
public SetImageMessage(string base64Image, string context, SDKTarget target, int? state)
{
this.Context = context;
this.Payload = new PayloadClass(base64Image, target);
this.Payload = new PayloadClass(base64Image, target, state);
}

private class PayloadClass : IPayload
Expand All @@ -27,10 +27,14 @@ private class PayloadClass : IPayload
[JsonProperty("target")]
public SDKTarget Target { get; private set; }

public PayloadClass(string image, SDKTarget target)
[JsonProperty("state", NullValueHandling = NullValueHandling.Ignore)]
public int? State { get; private set; }

public PayloadClass(string image, SDKTarget target, int? state)
{
this.Image = image;
this.Target = target;
this.State = state;
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions streamdeck-client-csharp/Messages/SetTitleMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ internal class SetTitleMessage : IMessage
[JsonProperty("payload")]
public IPayload Payload { get; private set; }

public SetTitleMessage(string title, string context, SDKTarget target)
public SetTitleMessage(string title, string context, SDKTarget target, int? state)
{
this.Context = context;
this.Payload = new PayloadClass(title, target);
this.Payload = new PayloadClass(title, target, state);
}

private class PayloadClass : IPayload
Expand All @@ -27,10 +27,14 @@ private class PayloadClass : IPayload
[JsonProperty("target")]
public SDKTarget Target { get; private set; }

public PayloadClass(string title, SDKTarget target)
[JsonProperty("state", NullValueHandling = NullValueHandling.Ignore)]
public int? State { get; private set; }

public PayloadClass(string title, SDKTarget target, int? state)
{
this.Title = title;
this.Target = target;
this.State = state;
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions streamdeck-client-csharp/StreamDeckConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ public void Stop()
m_CancelSource.Cancel();
}

public Task SetTitleAsync(string title, string context, SDKTarget target)
public Task SetTitleAsync(string title, string context, SDKTarget target, int? state)
{
return SendAsync(new SetTitleMessage(title, context, target));
return SendAsync(new SetTitleMessage(title, context, target, state));
}

public Task LogMessageAsync(string message)
{
return SendAsync(new LogMessage(message));
}

public Task SetImageAsync(Image image, string context, SDKTarget target)
public Task SetImageAsync(Image image, string context, SDKTarget target, int? state)
{
using (MemoryStream memoryStream = new MemoryStream())
{
Expand All @@ -90,13 +90,13 @@ public Task SetImageAsync(Image image, string context, SDKTarget target)

// Convert byte[] to Base64 String
string base64String = $"data:image/png;base64,{Convert.ToBase64String(imageBytes)}";
return SetImageAsync(base64String, context, target);
return SetImageAsync(base64String, context, target, state);
}
}

public Task SetImageAsync(string base64Image, string context, SDKTarget target)
public Task SetImageAsync(string base64Image, string context, SDKTarget target, int? state)
{
return SendAsync(new SetImageMessage(base64Image, context, target));
return SendAsync(new SetImageMessage(base64Image, context, target, state));
}

public Task ShowAlertAsync(string context)
Expand Down

0 comments on commit d0edbf1

Please sign in to comment.