|
9 | 9 | using BarRaider.SdTools.Payloads; |
10 | 10 | using BarRaider.SdTools.Communication; |
11 | 11 | using BarRaider.SdTools.Communication.SDEvents; |
| 12 | +using System.Collections.Generic; |
12 | 13 |
|
13 | 14 | namespace BarRaider.SdTools |
14 | 15 | { |
@@ -79,7 +80,95 @@ public class SDConnection : ISDConnection |
79 | 80 |
|
80 | 81 | #endregion |
81 | 82 |
|
82 | | - #region Public Implementations |
| 83 | + #region Public Properties |
| 84 | + |
| 85 | + |
| 86 | + /// <summary> |
| 87 | + /// An opaque value identifying the plugin. This value is received during the Registration procedure |
| 88 | + /// </summary> |
| 89 | + [JsonIgnore] |
| 90 | + public String ContextId { get; private set; } |
| 91 | + |
| 92 | + /// <summary> |
| 93 | + /// An opaque value identifying the device the plugin is launched on. |
| 94 | + /// </summary> |
| 95 | + [JsonIgnore] |
| 96 | + public String DeviceId { get; private set; } |
| 97 | + |
| 98 | + /// <summary> |
| 99 | + /// StreamDeckConnection object, initialized based on the args received when launching the program |
| 100 | + /// </summary> |
| 101 | + [JsonIgnore] |
| 102 | + public StreamDeckConnection StreamDeckConnection { get; private set; } |
| 103 | + |
| 104 | + #endregion |
| 105 | + |
| 106 | + /// <summary> |
| 107 | + /// Public constructor, a StreamDeckConnection object is required along with the current action and context IDs |
| 108 | + /// These will be used to correctly communicate with the StreamDeck App |
| 109 | + /// </summary> |
| 110 | + /// <param name="connection"></param> |
| 111 | + /// <param name="pluginUUID"></param> |
| 112 | + /// <param name="deviceInfo"></param> |
| 113 | + /// <param name="actionId"></param> |
| 114 | + /// <param name="contextId"></param> |
| 115 | + /// /// <param name="deviceId"></param> |
| 116 | + public SDConnection(StreamDeckConnection connection, string pluginUUID, StreamDeckInfo deviceInfo, string actionId, string contextId, string deviceId) |
| 117 | + { |
| 118 | + StreamDeckConnection = connection; |
| 119 | + this.pluginUUID = pluginUUID; |
| 120 | + this.deviceInfo = deviceInfo; |
| 121 | + this.actionId = actionId; |
| 122 | + this.ContextId = contextId; |
| 123 | + this.DeviceId = deviceId; |
| 124 | + |
| 125 | + StreamDeckConnection.OnSendToPlugin += Connection_OnSendToPlugin; |
| 126 | + StreamDeckConnection.OnTitleParametersDidChange += Connection_OnTitleParametersDidChange; |
| 127 | + StreamDeckConnection.OnApplicationDidTerminate += Connection_OnApplicationDidTerminate; |
| 128 | + StreamDeckConnection.OnApplicationDidLaunch += Connection_OnApplicationDidLaunch; |
| 129 | + StreamDeckConnection.OnDeviceDidDisconnect += Connection_OnDeviceDidDisconnect; |
| 130 | + StreamDeckConnection.OnDeviceDidConnect += Connection_OnDeviceDidConnect; |
| 131 | + StreamDeckConnection.OnPropertyInspectorDidAppear += Connection_OnPropertyInspectorDidAppear; |
| 132 | + StreamDeckConnection.OnPropertyInspectorDidDisappear += Connection_OnPropertyInspectorDidDisappear; |
| 133 | + StreamDeckConnection.OnSystemDidWakeUp += StreamDeckConnection_OnSystemDidWakeUp; |
| 134 | + } |
| 135 | + |
| 136 | + #region Public Methods |
| 137 | + |
| 138 | + /// <summary> |
| 139 | + /// Dispose (Destructor) function |
| 140 | + /// </summary> |
| 141 | + public void Dispose() |
| 142 | + { |
| 143 | + StreamDeckConnection.OnSendToPlugin -= Connection_OnSendToPlugin; |
| 144 | + StreamDeckConnection.OnTitleParametersDidChange -= Connection_OnTitleParametersDidChange; |
| 145 | + StreamDeckConnection.OnApplicationDidTerminate -= Connection_OnApplicationDidTerminate; |
| 146 | + StreamDeckConnection.OnApplicationDidLaunch -= Connection_OnApplicationDidLaunch; |
| 147 | + StreamDeckConnection.OnDeviceDidDisconnect -= Connection_OnDeviceDidDisconnect; |
| 148 | + StreamDeckConnection.OnDeviceDidConnect -= Connection_OnDeviceDidConnect; |
| 149 | + StreamDeckConnection.OnPropertyInspectorDidAppear -= Connection_OnPropertyInspectorDidAppear; |
| 150 | + StreamDeckConnection.OnPropertyInspectorDidDisappear -= Connection_OnPropertyInspectorDidDisappear; |
| 151 | + StreamDeckConnection.OnSystemDidWakeUp -= StreamDeckConnection_OnSystemDidWakeUp; |
| 152 | + } |
| 153 | + |
| 154 | + /// <summary> |
| 155 | + /// Gets the Stream Deck device's info |
| 156 | + /// </summary> |
| 157 | + /// <returns></returns> |
| 158 | + public StreamDeckDeviceInfo DeviceInfo() |
| 159 | + { |
| 160 | + if (deviceInfo == null || string.IsNullOrEmpty(DeviceId)) |
| 161 | + { |
| 162 | + Logger.Instance.LogMessage(TracingLevel.ERROR, $"Could not get DeviceInfo for DeviceId: {DeviceId} Devices: {deviceInfo?.Devices?.Length}"); |
| 163 | + return null; |
| 164 | + } |
| 165 | + |
| 166 | + return deviceInfo.Devices.Where(d => d.Id == DeviceId).FirstOrDefault(); |
| 167 | + } |
| 168 | + |
| 169 | + #endregion |
| 170 | + |
| 171 | + #region Public Requests |
83 | 172 |
|
84 | 173 | /// <summary> |
85 | 174 | /// Send settings to the PropertyInspector |
@@ -241,21 +330,6 @@ public async Task LogSDMessage(string message) |
241 | 330 | await StreamDeckConnection.LogMessageAsync(message); |
242 | 331 | } |
243 | 332 |
|
244 | | - /// <summary> |
245 | | - /// Gets the Stream Deck device's info |
246 | | - /// </summary> |
247 | | - /// <returns></returns> |
248 | | - public StreamDeckDeviceInfo DeviceInfo() |
249 | | - { |
250 | | - if (deviceInfo == null || string.IsNullOrEmpty(DeviceId)) |
251 | | - { |
252 | | - Logger.Instance.LogMessage(TracingLevel.ERROR, $"Could not get DeviceInfo for DeviceId: {DeviceId} Devices: {deviceInfo?.Devices?.Length}"); |
253 | | - return null; |
254 | | - } |
255 | | - |
256 | | - return deviceInfo.Devices.Where(d => d.Id == DeviceId).FirstOrDefault(); |
257 | | - } |
258 | | - |
259 | 333 | /// <summary> |
260 | 334 | /// Tells Stream Deck to return the current plugin settings via the ReceivedSettings function |
261 | 335 | /// </summary> |
@@ -295,72 +369,27 @@ public async Task SetStateAsync(uint state) |
295 | 369 | await StreamDeckConnection.SetStateAsync(state, ContextId); |
296 | 370 | } |
297 | 371 |
|
298 | | - #endregion |
299 | | - |
300 | | - /// <summary> |
301 | | - /// An opaque value identifying the plugin. This value is received during the Registration procedure |
302 | | - /// </summary> |
303 | | - [JsonIgnore] |
304 | | - public String ContextId { get; private set; } |
305 | | - |
306 | | - /// <summary> |
307 | | - /// An opaque value identifying the device the plugin is launched on. |
308 | | - /// </summary> |
309 | | - [JsonIgnore] |
310 | | - public String DeviceId { get; private set; } |
311 | | - |
312 | | - /// <summary> |
313 | | - /// StreamDeckConnection object, initialized based on the args received when launching the program |
314 | | - /// </summary> |
315 | | - [JsonIgnore] |
316 | | - public StreamDeckConnection StreamDeckConnection { get; private set; } |
317 | | - |
318 | 372 | /// <summary> |
319 | | - /// Public constructor, a StreamDeckConnection object is required along with the current action and context IDs |
320 | | - /// These will be used to correctly communicate with the StreamDeck App |
| 373 | + /// Sets the values of touchpad layouts items |
321 | 374 | /// </summary> |
322 | | - /// <param name="connection"></param> |
323 | | - /// <param name="pluginUUID"></param> |
324 | | - /// <param name="deviceInfo"></param> |
325 | | - /// <param name="actionId"></param> |
326 | | - /// <param name="contextId"></param> |
327 | | - /// /// <param name="deviceId"></param> |
328 | | - public SDConnection(StreamDeckConnection connection, string pluginUUID, StreamDeckInfo deviceInfo, string actionId, string contextId, string deviceId) |
| 375 | + /// <param name="dictKeyValues"></param> |
| 376 | + /// <returns></returns> |
| 377 | + public async Task SetFeedbackAsync(Dictionary<string, string> dictKeyValues) |
329 | 378 | { |
330 | | - StreamDeckConnection = connection; |
331 | | - this.pluginUUID = pluginUUID; |
332 | | - this.deviceInfo = deviceInfo; |
333 | | - this.actionId = actionId; |
334 | | - this.ContextId = contextId; |
335 | | - this.DeviceId = deviceId; |
336 | | - |
337 | | - StreamDeckConnection.OnSendToPlugin += Connection_OnSendToPlugin; |
338 | | - StreamDeckConnection.OnTitleParametersDidChange += Connection_OnTitleParametersDidChange; |
339 | | - StreamDeckConnection.OnApplicationDidTerminate += Connection_OnApplicationDidTerminate; |
340 | | - StreamDeckConnection.OnApplicationDidLaunch += Connection_OnApplicationDidLaunch; |
341 | | - StreamDeckConnection.OnDeviceDidDisconnect += Connection_OnDeviceDidDisconnect; |
342 | | - StreamDeckConnection.OnDeviceDidConnect += Connection_OnDeviceDidConnect; |
343 | | - StreamDeckConnection.OnPropertyInspectorDidAppear += Connection_OnPropertyInspectorDidAppear; |
344 | | - StreamDeckConnection.OnPropertyInspectorDidDisappear += Connection_OnPropertyInspectorDidDisappear; |
345 | | - StreamDeckConnection.OnSystemDidWakeUp += StreamDeckConnection_OnSystemDidWakeUp; |
| 379 | + await StreamDeckConnection.SetFeedbackAsync(dictKeyValues, ContextId); |
346 | 380 | } |
347 | 381 |
|
348 | 382 | /// <summary> |
349 | | - /// Dispose (Destructor) function |
| 383 | + /// Sets the value of a single touchpad layout item |
350 | 384 | /// </summary> |
351 | | - public void Dispose() |
| 385 | + /// <param name="dictKeyValues"></param> |
| 386 | + /// <returns></returns> |
| 387 | + public async Task SetFeedbackAsync(string layoutItemKey, string value) |
352 | 388 | { |
353 | | - StreamDeckConnection.OnSendToPlugin -= Connection_OnSendToPlugin; |
354 | | - StreamDeckConnection.OnTitleParametersDidChange -= Connection_OnTitleParametersDidChange; |
355 | | - StreamDeckConnection.OnApplicationDidTerminate -= Connection_OnApplicationDidTerminate; |
356 | | - StreamDeckConnection.OnApplicationDidLaunch -= Connection_OnApplicationDidLaunch; |
357 | | - StreamDeckConnection.OnDeviceDidDisconnect -= Connection_OnDeviceDidDisconnect; |
358 | | - StreamDeckConnection.OnDeviceDidConnect -= Connection_OnDeviceDidConnect; |
359 | | - StreamDeckConnection.OnPropertyInspectorDidAppear -= Connection_OnPropertyInspectorDidAppear; |
360 | | - StreamDeckConnection.OnPropertyInspectorDidDisappear -= Connection_OnPropertyInspectorDidDisappear; |
361 | | - StreamDeckConnection.OnSystemDidWakeUp -= StreamDeckConnection_OnSystemDidWakeUp; |
| 389 | + await StreamDeckConnection.SetFeedbackAsync(new Dictionary<string, string>() { { layoutItemKey, value } }, ContextId); |
362 | 390 | } |
363 | 391 |
|
| 392 | + #endregion |
364 | 393 |
|
365 | 394 | #region Event Wrappers |
366 | 395 |
|
|
0 commit comments