Skip to content

Commit 408da00

Browse files
committed
v3.2 - ISDConnection encapsulations + Optimized GlobalSettingsManager.GetGlobalSettings()
3.2 - 1. Created new ISDConnection interface which is now implemented by SDConnection and used by PluginAction. 2. GlobalSettingsManager now has a short delay before calling GetGlobalSettings, to reduce spamming the Stream Deck SDK. 3. Updated dependencies to latest version
1 parent 355dde4 commit 408da00

9 files changed

Lines changed: 477 additions & 84 deletions

File tree

NUGET.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,10 @@
77
**Author's website and contact information:** [https://barraider.com](https://barraider.com)
88
** Samples of plugins using this framework: [Samples][1]
99

10-
### Version 3.1 is out!
11-
- Updated Logger class to include process name and thread id
12-
- Updated [StreamDeck-Tools Template](https://github.com/BarRaider/streamdeck-tools/raw/master/utils/StreamDeck-Tools%20Template.vsix) for Visual Studio
13-
14-
### Version 3.0 is out!
15-
- Updated file handling in `Tools.AutoPopulateSettings` and `Tools.FilenameFromPayload` methods
16-
- Removed obsolete MD5 functions, use SHA512 functions instead
17-
- `Tools.CenterText` function now has optional out `textFitsImage` value to verify the text does not exceed the image width
18-
- New `Tools.FormatBytes` function converts bytes to human-readable value
19-
- New `Tools.FormatNumber()` function converts 54265 to 54.27k
20-
- New `Graphics.GetFontSizeWhereTextFitsImage` function helps locate the best size for a text to fit an image on 1 line
21-
- New ExtensionMethods for `Graphics` object: `DrawAndMeasureString` / `GetTextCenter`
22-
- Updated dependency packages to latest versions
23-
- Bug fix where FileNameProperty attribute
10+
### Version 3.2 is out!
11+
- Created new `ISDConnection` interface which is now implemented by SDConnection and used by PluginAction.
12+
- GlobalSettingsManager now has a short delay before calling GetGlobalSettings(), to reduce spamming the Stream Deck SDK.
13+
- Updated dependencies to latest version
2414

2515
## Features
2616
- Sample plugin now included in this project on Github

README.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,10 @@
1414
* [StreamDeck-Tools Template](https://github.com/BarRaider/streamdeck-tools/raw/master/utils/StreamDeck-Tools%20Template.vsix) for Visual Studio - Automatically creates a project with all the files needed to compile a plugin
1515
* [Profiles](https://barraider.com/profiles) Downloadable empty profiles for the XL (32-key), Classic (15-key), Mini (6-key) and Mobile devices at https://barraider.com/profiles
1616

17-
### Version 3.1 is out!
18-
- Updated Logger class to include process name and thread id
19-
- Updated [StreamDeck-Tools Template](https://github.com/BarRaider/streamdeck-tools/raw/master/utils/StreamDeck-Tools%20Template.vsix) for Visual Studio
20-
21-
### Version 3.0 is out!
22-
- Updated file handling in `Tools.AutoPopulateSettings` and `Tools.FilenameFromPayload` methods
23-
- Removed obsolete MD5 functions, use SHA512 functions instead
24-
- `Tools.CenterText` function now has optional out `textFitsImage` value to verify the text does not exceed the image width
25-
- New `Tools.FormatBytes` function converts bytes to human-readable value
26-
- New `Graphics.GetFontSizeWhereTextFitsImage` function helps locate the best size for a text to fit an image on 1 line
27-
- Updated dependency packages to latest versions
28-
- Bug fix where FileNameProperty attribute
17+
### Version 3.2 is out!
18+
- Created new `ISDConnection` interface which is now implemented by SDConnection and used by PluginAction.
19+
- GlobalSettingsManager now has a short delay before calling GetGlobalSettings(), to reduce spamming the Stream Deck SDK.
20+
- Updated dependencies to latest version
2921

3022
## Features
3123
- Sample plugin now included in this project on Github
@@ -317,6 +309,7 @@ private void SetGlobalSettings()
317309
```
318310

319311
# Change Log
312+
320313
### Version 3.1 is out!
321314
- Updated Logger class to include process name and thread id
322315

SamplePlugin/PluginAction.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ private class PluginSettings
1919
{
2020
public static PluginSettings CreateDefaultSettings()
2121
{
22-
PluginSettings instance = new PluginSettings();
23-
instance.OutputFileName = String.Empty;
24-
instance.InputString = String.Empty;
22+
PluginSettings instance = new PluginSettings
23+
{
24+
OutputFileName = String.Empty,
25+
InputString = String.Empty
26+
};
2527
return instance;
2628
}
2729

@@ -35,10 +37,10 @@ public static PluginSettings CreateDefaultSettings()
3537

3638
#region Private Members
3739

38-
private PluginSettings settings;
40+
private readonly PluginSettings settings;
3941

4042
#endregion
41-
public PluginAction(SDConnection connection, InitialPayload payload) : base(connection, payload)
43+
public PluginAction(ISDConnection connection, InitialPayload payload) : base(connection, payload)
4244
{
4345
if (payload.Settings == null || payload.Settings.Count == 0)
4446
{
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
using BarRaider.SdTools.Events;
2+
using BarRaider.SdTools.Wrappers;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Linq;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Drawing;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
namespace BarRaider.SdTools
12+
{
13+
/// <summary>
14+
/// Interface for a Stream Deck connection
15+
/// </summary>
16+
public interface ISDConnection : IDisposable
17+
{
18+
#region Events
19+
20+
/// <summary>
21+
/// Event received by the plugin when the Property Inspector uses the sendToPlugin event.
22+
/// </summary>
23+
event EventHandler<SDEventReceivedEventArgs<SendToPlugin>> OnSendToPlugin;
24+
/// <summary>
25+
/// Event received when the user changes the title or title parameters.
26+
/// </summary>
27+
event EventHandler<SDEventReceivedEventArgs<TitleParametersDidChange>> OnTitleParametersDidChange;
28+
/// <summary>
29+
/// Event received when a monitored application is terminated
30+
/// </summary>
31+
event EventHandler<SDEventReceivedEventArgs<ApplicationDidTerminate>> OnApplicationDidTerminate;
32+
/// <summary>
33+
/// Event received when a monitored application is launched
34+
/// </summary>
35+
event EventHandler<SDEventReceivedEventArgs<ApplicationDidLaunch>> OnApplicationDidLaunch;
36+
/// <summary>
37+
/// Event received when a device is unplugged from the computer
38+
/// </summary>
39+
event EventHandler<SDEventReceivedEventArgs<DeviceDidDisconnect>> OnDeviceDidDisconnect;
40+
/// <summary>
41+
/// Event received when a device is plugged to the computer.
42+
/// </summary>
43+
event EventHandler<SDEventReceivedEventArgs<DeviceDidConnect>> OnDeviceDidConnect;
44+
/// <summary>
45+
/// Event received when the Property Inspector appears in the Stream Deck software user interface, for example when selecting a new instance.
46+
/// </summary>
47+
event EventHandler<SDEventReceivedEventArgs<PropertyInspectorDidAppear>> OnPropertyInspectorDidAppear;
48+
/// <summary>
49+
/// Event received when the Property Inspector for an instance is removed from the Stream Deck software user interface, for example when selecting a different instance.
50+
/// </summary>
51+
event EventHandler<SDEventReceivedEventArgs<PropertyInspectorDidDisappear>> OnPropertyInspectorDidDisappear;
52+
53+
#endregion
54+
55+
#region Methods
56+
57+
/// <summary>
58+
/// Send settings to the PropertyInspector
59+
/// </summary>
60+
/// <param name="settings"></param>
61+
/// <returns></returns>
62+
Task SendToPropertyInspectorAsync(JObject settings);
63+
64+
/// <summary>
65+
/// Persists your plugin settings
66+
/// </summary>
67+
/// <param name="settings"></param>
68+
/// <returns></returns>
69+
Task SetSettingsAsync(JObject settings);
70+
71+
/// <summary>
72+
/// Persists your global plugin settings
73+
/// </summary>
74+
/// <param name="settings">Settings to save globally</param>
75+
/// <param name="triggerDidReceiveGlobalSettings">Boolean whether to also trigger a didReceiveGlobalSettings event. Default is true</param>
76+
/// <returns></returns>
77+
Task SetGlobalSettingsAsync(JObject settings, bool triggerDidReceiveGlobalSettings = true);
78+
79+
/// <summary>
80+
/// Persists your global plugin settings
81+
/// </summary>
82+
/// <returns></returns>
83+
Task GetGlobalSettingsAsync();
84+
85+
/// <summary>
86+
/// Sets an image on the StreamDeck key.
87+
/// </summary>
88+
/// <param name="base64Image">Base64 encoded image</param>
89+
/// <param name="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.</param>
90+
/// <param name="forceSendToStreamdeck">Should image be sent even if it is identical to the one sent previously. Default is false</param>
91+
/// <returns></returns>
92+
Task SetImageAsync(string base64Image, int? state = null, bool forceSendToStreamdeck = false);
93+
94+
/// <summary>
95+
/// Sets an image on the StreamDeck key
96+
/// </summary>
97+
/// <param name="image">Image object</param>
98+
/// <param name="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.</param>
99+
/// <param name="forceSendToStreamdeck">Should image be sent even if it is identical to the one sent previously. Default is false</param>
100+
/// <returns></returns>
101+
Task SetImageAsync(Image image, int? state = null, bool forceSendToStreamdeck = false);
102+
103+
/// <summary>
104+
/// Sets the default image for this state, as configured in the manifest
105+
/// </summary>
106+
/// <returns></returns>
107+
Task SetDefaultImageAsync();
108+
109+
/// <summary>
110+
/// Sets a title on the StreamDeck key
111+
/// </summary>
112+
/// <param name="title"></param>
113+
/// <param name="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.</param>
114+
/// <returns></returns>
115+
Task SetTitleAsync(string title, int? state = null);
116+
117+
/// <summary>
118+
/// Switches to one of the plugin's built-in profiles
119+
/// </summary>
120+
/// <param name="profileName"></param>
121+
/// <returns></returns>
122+
Task SwitchProfileAsync(string profileName);
123+
124+
/// <summary>
125+
/// Switches to one of the plugin's built-in profiles. Allows to choose which device to switch it on.
126+
/// </summary>
127+
/// <param name="profileName"></param>
128+
/// <param name="deviceId"></param>
129+
/// <returns></returns>
130+
Task SwitchProfileAsync(string profileName, string deviceId);
131+
132+
/// <summary>
133+
/// Shows the Alert (Yellow Triangle) on the StreamDeck key
134+
/// </summary>
135+
/// <returns></returns>
136+
Task ShowAlert();
137+
138+
/// <summary>
139+
/// Shows the Success (Green checkmark) on the StreamDeck key
140+
/// </summary>
141+
/// <returns></returns>
142+
Task ShowOk();
143+
144+
/// <summary>
145+
/// Add a message to the Stream Deck log. This is the log located at: %appdata%\Elgato\StreamDeck\logs\StreamDeck0.log
146+
/// </summary>
147+
/// <param name="message"></param>
148+
/// <returns></returns>
149+
Task LogSDMessage(string message);
150+
151+
/// <summary>
152+
/// Gets the Stream Deck device's info
153+
/// </summary>
154+
/// <returns></returns>
155+
StreamDeckDeviceInfo DeviceInfo();
156+
157+
/// <summary>
158+
/// Tells Stream Deck to return the current plugin settings via the ReceivedSettings function
159+
/// </summary>
160+
/// <returns></returns>
161+
Task GetSettingsAsync();
162+
163+
/// <summary>
164+
/// Opens a URI in the user's browser
165+
/// </summary>
166+
/// <param name="uri"></param>
167+
/// <returns></returns>
168+
Task OpenUrlAsync(string uri);
169+
170+
/// <summary>
171+
/// Opens a URI in the user's browser
172+
/// </summary>
173+
/// <param name="uri"></param>
174+
/// <returns></returns>
175+
Task OpenUrlAsync(Uri uri);
176+
177+
/// <summary>
178+
/// Sets the plugin to a specific state which is pre-configured in the manifest file
179+
/// </summary>
180+
/// <param name="state"></param>
181+
/// <returns></returns>
182+
Task SetStateAsync(uint state);
183+
184+
#endregion
185+
186+
/// <summary>
187+
/// An opaque value identifying the plugin. This value is received during the Registration procedure
188+
/// </summary>
189+
[JsonIgnore]
190+
String ContextId { get; }
191+
192+
/// <summary>
193+
/// An opaque value identifying the device the plugin is launched on.
194+
/// </summary>
195+
[JsonIgnore]
196+
String DeviceId { get; }
197+
198+
/// <summary>
199+
/// StreamDeckConnection object, initialized based on the args received when launching the program
200+
/// </summary>
201+
[JsonIgnore]
202+
streamdeck_client_csharp.StreamDeckConnection StreamDeckConnection { get; }
203+
}
204+
}

barraider-sdtools/Backend/SDConnection.cs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,27 @@ namespace BarRaider.SdTools
1313
/// <summary>
1414
/// Connection object which handles your communication with the Stream Deck app
1515
/// </summary>
16-
public class SDConnection : IDisposable
16+
public class SDConnection : ISDConnection
1717
{
18-
#region Private Methods
18+
#region Private Members
1919

2020
private string previousImageHash = null;
2121

22+
[JsonIgnore]
23+
private readonly string actionId;
24+
25+
/// <summary>
26+
/// An opaque value identifying the plugin. Received as an argument when the executable was launched.
27+
/// </summary>
28+
[JsonIgnore]
29+
private readonly string pluginUUID;
30+
31+
/// <summary>
32+
/// Holds information about the devices connected to the computer
33+
/// </summary>
34+
[JsonIgnore]
35+
private readonly StreamDeckInfo deviceInfo;
36+
2237
#endregion
2338

2439
#region Public Events
@@ -396,24 +411,5 @@ private void Connection_OnSendToPlugin(object sender, streamdeck_client_csharp.S
396411
}
397412

398413
#endregion
399-
400-
#region Private Members
401-
402-
[JsonIgnore]
403-
private readonly string actionId;
404-
405-
/// <summary>
406-
/// An opaque value identifying the plugin. Received as an argument when the executable was launched.
407-
/// </summary>
408-
[JsonIgnore]
409-
private readonly string pluginUUID;
410-
411-
/// <summary>
412-
/// Holds information about the devices connected to the computer
413-
/// </summary>
414-
[JsonIgnore]
415-
private readonly StreamDeckInfo deviceInfo;
416-
417-
#endregion
418414
}
419415
}

0 commit comments

Comments
 (0)