Skip to content

Commit

Permalink
v3.2 - ISDConnection encapsulations + Optimized GlobalSettingsManager…
Browse files Browse the repository at this point in the history
….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
  • Loading branch information
BarRaider committed Jan 20, 2021
1 parent 355dde4 commit 408da00
Show file tree
Hide file tree
Showing 9 changed files with 477 additions and 84 deletions.
18 changes: 4 additions & 14 deletions NUGET.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,10 @@
**Author's website and contact information:** [https://barraider.com](https://barraider.com)
** Samples of plugins using this framework: [Samples][1]

### Version 3.1 is out!
- Updated Logger class to include process name and thread id
- Updated [StreamDeck-Tools Template](https://github.com/BarRaider/streamdeck-tools/raw/master/utils/StreamDeck-Tools%20Template.vsix) for Visual Studio

### Version 3.0 is out!
- Updated file handling in `Tools.AutoPopulateSettings` and `Tools.FilenameFromPayload` methods
- Removed obsolete MD5 functions, use SHA512 functions instead
- `Tools.CenterText` function now has optional out `textFitsImage` value to verify the text does not exceed the image width
- New `Tools.FormatBytes` function converts bytes to human-readable value
- New `Tools.FormatNumber()` function converts 54265 to 54.27k
- New `Graphics.GetFontSizeWhereTextFitsImage` function helps locate the best size for a text to fit an image on 1 line
- New ExtensionMethods for `Graphics` object: `DrawAndMeasureString` / `GetTextCenter`
- Updated dependency packages to latest versions
- Bug fix where FileNameProperty attribute
### Version 3.2 is out!
- Created new `ISDConnection` interface which is now implemented by SDConnection and used by PluginAction.
- GlobalSettingsManager now has a short delay before calling GetGlobalSettings(), to reduce spamming the Stream Deck SDK.
- Updated dependencies to latest version

## Features
- Sample plugin now included in this project on Github
Expand Down
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@
* [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
* [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

### Version 3.1 is out!
- Updated Logger class to include process name and thread id
- Updated [StreamDeck-Tools Template](https://github.com/BarRaider/streamdeck-tools/raw/master/utils/StreamDeck-Tools%20Template.vsix) for Visual Studio

### Version 3.0 is out!
- Updated file handling in `Tools.AutoPopulateSettings` and `Tools.FilenameFromPayload` methods
- Removed obsolete MD5 functions, use SHA512 functions instead
- `Tools.CenterText` function now has optional out `textFitsImage` value to verify the text does not exceed the image width
- New `Tools.FormatBytes` function converts bytes to human-readable value
- New `Graphics.GetFontSizeWhereTextFitsImage` function helps locate the best size for a text to fit an image on 1 line
- Updated dependency packages to latest versions
- Bug fix where FileNameProperty attribute
### Version 3.2 is out!
- Created new `ISDConnection` interface which is now implemented by SDConnection and used by PluginAction.
- GlobalSettingsManager now has a short delay before calling GetGlobalSettings(), to reduce spamming the Stream Deck SDK.
- Updated dependencies to latest version

## Features
- Sample plugin now included in this project on Github
Expand Down Expand Up @@ -317,6 +309,7 @@ private void SetGlobalSettings()
```

# Change Log

### Version 3.1 is out!
- Updated Logger class to include process name and thread id

Expand Down
12 changes: 7 additions & 5 deletions SamplePlugin/PluginAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ private class PluginSettings
{
public static PluginSettings CreateDefaultSettings()
{
PluginSettings instance = new PluginSettings();
instance.OutputFileName = String.Empty;
instance.InputString = String.Empty;
PluginSettings instance = new PluginSettings
{
OutputFileName = String.Empty,
InputString = String.Empty
};
return instance;
}

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

#region Private Members

private PluginSettings settings;
private readonly PluginSettings settings;

#endregion
public PluginAction(SDConnection connection, InitialPayload payload) : base(connection, payload)
public PluginAction(ISDConnection connection, InitialPayload payload) : base(connection, payload)
{
if (payload.Settings == null || payload.Settings.Count == 0)
{
Expand Down
204 changes: 204 additions & 0 deletions barraider-sdtools/Backend/ISDConnection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
using BarRaider.SdTools.Events;
using BarRaider.SdTools.Wrappers;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;

namespace BarRaider.SdTools
{
/// <summary>
/// Interface for a Stream Deck connection
/// </summary>
public interface ISDConnection : IDisposable
{
#region Events

/// <summary>
/// Event received by the plugin when the Property Inspector uses the sendToPlugin event.
/// </summary>
event EventHandler<SDEventReceivedEventArgs<SendToPlugin>> OnSendToPlugin;
/// <summary>
/// Event received when the user changes the title or title parameters.
/// </summary>
event EventHandler<SDEventReceivedEventArgs<TitleParametersDidChange>> OnTitleParametersDidChange;
/// <summary>
/// Event received when a monitored application is terminated
/// </summary>
event EventHandler<SDEventReceivedEventArgs<ApplicationDidTerminate>> OnApplicationDidTerminate;
/// <summary>
/// Event received when a monitored application is launched
/// </summary>
event EventHandler<SDEventReceivedEventArgs<ApplicationDidLaunch>> OnApplicationDidLaunch;
/// <summary>
/// Event received when a device is unplugged from the computer
/// </summary>
event EventHandler<SDEventReceivedEventArgs<DeviceDidDisconnect>> OnDeviceDidDisconnect;
/// <summary>
/// Event received when a device is plugged to the computer.
/// </summary>
event EventHandler<SDEventReceivedEventArgs<DeviceDidConnect>> OnDeviceDidConnect;
/// <summary>
/// Event received when the Property Inspector appears in the Stream Deck software user interface, for example when selecting a new instance.
/// </summary>
event EventHandler<SDEventReceivedEventArgs<PropertyInspectorDidAppear>> OnPropertyInspectorDidAppear;
/// <summary>
/// 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.
/// </summary>
event EventHandler<SDEventReceivedEventArgs<PropertyInspectorDidDisappear>> OnPropertyInspectorDidDisappear;

#endregion

#region Methods

/// <summary>
/// Send settings to the PropertyInspector
/// </summary>
/// <param name="settings"></param>
/// <returns></returns>
Task SendToPropertyInspectorAsync(JObject settings);

/// <summary>
/// Persists your plugin settings
/// </summary>
/// <param name="settings"></param>
/// <returns></returns>
Task SetSettingsAsync(JObject settings);

/// <summary>
/// Persists your global plugin settings
/// </summary>
/// <param name="settings">Settings to save globally</param>
/// <param name="triggerDidReceiveGlobalSettings">Boolean whether to also trigger a didReceiveGlobalSettings event. Default is true</param>
/// <returns></returns>
Task SetGlobalSettingsAsync(JObject settings, bool triggerDidReceiveGlobalSettings = true);

/// <summary>
/// Persists your global plugin settings
/// </summary>
/// <returns></returns>
Task GetGlobalSettingsAsync();

/// <summary>
/// Sets an image on the StreamDeck key.
/// </summary>
/// <param name="base64Image">Base64 encoded image</param>
/// <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>
/// <param name="forceSendToStreamdeck">Should image be sent even if it is identical to the one sent previously. Default is false</param>
/// <returns></returns>
Task SetImageAsync(string base64Image, int? state = null, bool forceSendToStreamdeck = false);

/// <summary>
/// Sets an image on the StreamDeck key
/// </summary>
/// <param name="image">Image object</param>
/// <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>
/// <param name="forceSendToStreamdeck">Should image be sent even if it is identical to the one sent previously. Default is false</param>
/// <returns></returns>
Task SetImageAsync(Image image, int? state = null, bool forceSendToStreamdeck = false);

/// <summary>
/// Sets the default image for this state, as configured in the manifest
/// </summary>
/// <returns></returns>
Task SetDefaultImageAsync();

/// <summary>
/// Sets a title on the StreamDeck key
/// </summary>
/// <param name="title"></param>
/// <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>
/// <returns></returns>
Task SetTitleAsync(string title, int? state = null);

/// <summary>
/// Switches to one of the plugin's built-in profiles
/// </summary>
/// <param name="profileName"></param>
/// <returns></returns>
Task SwitchProfileAsync(string profileName);

/// <summary>
/// Switches to one of the plugin's built-in profiles. Allows to choose which device to switch it on.
/// </summary>
/// <param name="profileName"></param>
/// <param name="deviceId"></param>
/// <returns></returns>
Task SwitchProfileAsync(string profileName, string deviceId);

/// <summary>
/// Shows the Alert (Yellow Triangle) on the StreamDeck key
/// </summary>
/// <returns></returns>
Task ShowAlert();

/// <summary>
/// Shows the Success (Green checkmark) on the StreamDeck key
/// </summary>
/// <returns></returns>
Task ShowOk();

/// <summary>
/// Add a message to the Stream Deck log. This is the log located at: %appdata%\Elgato\StreamDeck\logs\StreamDeck0.log
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
Task LogSDMessage(string message);

/// <summary>
/// Gets the Stream Deck device's info
/// </summary>
/// <returns></returns>
StreamDeckDeviceInfo DeviceInfo();

/// <summary>
/// Tells Stream Deck to return the current plugin settings via the ReceivedSettings function
/// </summary>
/// <returns></returns>
Task GetSettingsAsync();

/// <summary>
/// Opens a URI in the user's browser
/// </summary>
/// <param name="uri"></param>
/// <returns></returns>
Task OpenUrlAsync(string uri);

/// <summary>
/// Opens a URI in the user's browser
/// </summary>
/// <param name="uri"></param>
/// <returns></returns>
Task OpenUrlAsync(Uri uri);

/// <summary>
/// Sets the plugin to a specific state which is pre-configured in the manifest file
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
Task SetStateAsync(uint state);

#endregion

/// <summary>
/// An opaque value identifying the plugin. This value is received during the Registration procedure
/// </summary>
[JsonIgnore]
String ContextId { get; }

/// <summary>
/// An opaque value identifying the device the plugin is launched on.
/// </summary>
[JsonIgnore]
String DeviceId { get; }

/// <summary>
/// StreamDeckConnection object, initialized based on the args received when launching the program
/// </summary>
[JsonIgnore]
streamdeck_client_csharp.StreamDeckConnection StreamDeckConnection { get; }
}
}
38 changes: 17 additions & 21 deletions barraider-sdtools/Backend/SDConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@ namespace BarRaider.SdTools
/// <summary>
/// Connection object which handles your communication with the Stream Deck app
/// </summary>
public class SDConnection : IDisposable
public class SDConnection : ISDConnection
{
#region Private Methods
#region Private Members

private string previousImageHash = null;

[JsonIgnore]
private readonly string actionId;

/// <summary>
/// An opaque value identifying the plugin. Received as an argument when the executable was launched.
/// </summary>
[JsonIgnore]
private readonly string pluginUUID;

/// <summary>
/// Holds information about the devices connected to the computer
/// </summary>
[JsonIgnore]
private readonly StreamDeckInfo deviceInfo;

#endregion

#region Public Events
Expand Down Expand Up @@ -396,24 +411,5 @@ private void Connection_OnSendToPlugin(object sender, streamdeck_client_csharp.S
}

#endregion

#region Private Members

[JsonIgnore]
private readonly string actionId;

/// <summary>
/// An opaque value identifying the plugin. Received as an argument when the executable was launched.
/// </summary>
[JsonIgnore]
private readonly string pluginUUID;

/// <summary>
/// Holds information about the devices connected to the computer
/// </summary>
[JsonIgnore]
private readonly StreamDeckInfo deviceInfo;

#endregion
}
}
Loading

0 comments on commit 408da00

Please sign in to comment.