Skip to content

Commit

Permalink
Merge pull request #2 from ivanpointer/issues/#1/abstract-action-uuid…
Browse files Browse the repository at this point in the history
…-option

Fixes #1 - Make using the ActionUuidAttribute more flexible by allowi…
  • Loading branch information
ivanpointer authored Aug 6, 2021
2 parents 5e34a21 + de9ac48 commit d215f40
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ The Stream Deck Toolkit provides the functionality that communicates directly wi

2. BaseStreamDeckActionWithSettingsModel<T> - this class inherits from BaseStreamDeckAction, this class will automate the population of model properties, where type T is defined as the data that is stored when issuing a 'setSettings' event to the Stream Deck software. The property **SettingsModel** will automatically instantiate an instance of class T, so it is best to assign default values when defining your class T. Also, when using the Property Inspector and passing data back and forth, ensure that the properties defined in the settingsModel in JavaScript matches those that you have defined in T for the automatic mapping to occur between both environments.

Your project may contain any number of actions, inheriting from one of the classes above. In order for the Action to be automatically registered on start up, it must bear the **[ActionUuid(Uuid="com.fritzanfriends.pluginname.anotheraction")]** attribute.
Your project may contain any number of actions, inheriting from one of the classes above. In order for the Action to be automatically registered on start up, it must bear the **[StreamDeckAction(Uuid="com.fritzanfriends.pluginname.anotheraction")]** attribute, and have a UUID set via the attribute, or by overloading `ActionUuid` in your `BaseStreamDeckAction` implementation.

Actions must also be manually registered in the **manifest.json** file, with the Uuid that matches ActionUuid attribute.
Actions must also be manually registered in the **manifest.json** file, with the Uuid that matches the one set with the `StreamDeckActionAttribute`, or an `ActionUuid` overload of the `BaseStreamDeckAction.ActionUuid` property.

<!-- Reference Links -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace _StreamDeckPlugin_
{
[ActionUuid(Uuid="$(UUID).DefaultPluginAction")]
[StreamDeckAction(Uuid="$(UUID).DefaultPluginAction")]
public class $(PluginName)Action : BaseStreamDeckActionWithSettingsModel<Models.CounterSettingsModel>
{
public override async Task OnKeyUp(StreamDeckEventPayload args)
Expand Down
4 changes: 2 additions & 2 deletions docs/articles/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ The Stream Deck Toolkit provides the functionality that communicates directly wi

2. `BaseStreamDeckActionWithSettingsModel<T>` - this class inherits from BaseStreamDeckAction, this class will automate the population of model properties, where type T is defined as the data that is stored when issuing a 'setSettings' event to the Stream Deck software. The property **`SettingsModel`** will automatically instantiate an instance of class T, so it is best to assign default values when defining your class T. Also, when using the Property Inspector and passing data back and forth, ensure that the properties defined in the settingsModel in JavaScript matches those that you have defined in T for the automatic mapping to occur between both environments.

Your project may contain any number of actions, inheriting from one of the classes above. In order for the Action to be automatically registered on start up, it must bear the **`[ActionUuid(Uuid="com.fritzanfriends.pluginname.anotheraction")]`** attribute.
Your project may contain any number of actions, inheriting from one of the classes above. In order for the Action to be automatically registered on start up, it must bear the **[StreamDeckAction(Uuid="com.fritzanfriends.pluginname.anotheraction")]** attribute, and have a UUID set via the attribute, or by overloading `ActionUuid` in your `BaseStreamDeckAction` implementation.

Actions must also be manually registered in the **`manifest.json`** file, with the Uuid that matches ActionUuid attribute.
Actions must also be manually registered in the **manifest.json** file, with the Uuid that matches the one set with the `StreamDeckActionAttribute`, or an `ActionUuid` overload of the `BaseStreamDeckAction.ActionUuid` property.
2 changes: 1 addition & 1 deletion docs/articles/template/action.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You will also have a model created `CounterSettingsModel` which will be set.

### Attribute

[ActionUuid(Uuid="com.yourcompany.pluginname.actionname")]
[StreamDeckAction(Uuid="com.yourcompany.pluginname.actionname")]

### Class Name

Expand Down
2 changes: 1 addition & 1 deletion src/SampleDIPlugin/MySamplePluginAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace SampleDIPlugin
{
[ActionUuid(Uuid = "com.csharpfritz.samplePlugin.action")]
[StreamDeckAction(Uuid = "com.csharpfritz.samplePlugin.action")]
public class MySamplePluginAction : BaseStreamDeckActionWithSettingsModel<CounterSettingsModel>
{

Expand Down
2 changes: 1 addition & 1 deletion src/SampleDIPlugin/MySamplePluginAction2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace SampleDIPlugin
{
[ActionUuid(Uuid = "com.csharpfritz.samplePlugin.action2")]
[StreamDeckAction(Uuid = "com.csharpfritz.samplePlugin.action2")]
public class MySamplePluginAction2 : BaseStreamDeckActionWithSettingsModel<CounterSettingsModel>
{

Expand Down
2 changes: 1 addition & 1 deletion src/SamplePlugin/MySamplePluginAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace SamplePlugin
{
[ActionUuid(Uuid = "com.csharpfritz.samplePlugin.action")]
[StreamDeckAction(Uuid = "com.csharpfritz.samplePlugin.action")]
public class MySamplePluginAction : BaseStreamDeckActionWithSettingsModel<CounterSettingsModel>
{

Expand Down
2 changes: 1 addition & 1 deletion src/SamplePlugin/MySamplePluginAction2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace SamplePlugin
{
[ActionUuid(Uuid = "com.csharpfritz.samplePlugin.action2")]
[StreamDeckAction(Uuid = "com.csharpfritz.samplePlugin.action2")]
public class MySamplePluginAction2 : BaseStreamDeckActionWithSettingsModel<CounterSettingsModel>
{

Expand Down
2 changes: 1 addition & 1 deletion src/SampleWebPlugin/MySamplePluginAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace SampleWebPlugin
{
[ActionUuid(Uuid = "com.csharpfritz.samplePlugin.action")]
[StreamDeckAction(Uuid = "com.csharpfritz.samplePlugin.action")]
public class MySamplePluginAction : BaseStreamDeckActionWithSettingsModel<CounterSettingsModel>
{

Expand Down
2 changes: 1 addition & 1 deletion src/SampleWebPlugin/MySamplePluginAction2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace SampleWebPlugin
{
[ActionUuid(Uuid = "com.csharpfritz.samplePlugin.action2")]
[StreamDeckAction(Uuid = "com.csharpfritz.samplePlugin.action2")]
public class MySamplePluginAction2 : BaseStreamDeckActionWithSettingsModel<CounterSettingsModel>
{

Expand Down
2 changes: 1 addition & 1 deletion src/StreamDeckLib.Test/Stubs/StubAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace StreamDeckLib.Test
{

[ActionUuid(Uuid = "Test UUID")]
[StreamDeckAction(Uuid = "Test UUID")]
public class StubAction : BaseStreamDeckAction
{
public int Counter = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/StreamDeckLib/ActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public ActionManager RegisterActionType(string actionUuid, Type actionType)
throw new DuplicateActionRegistrationException(actionUuid);
}

// Ensure that the type we're registering inherits from BaseStreamDeckAction.
// Ensure that the type we're registering inherits from BaseStreamDeckAction.
if (!actionType.IsSubclassOf(typeof(BaseStreamDeckAction)))
{
throw new TypeDoesNotInheritFromBaseStreamDeckAction(actionType.Name, actionType.FullName, actionType.Assembly.FullName);
Expand All @@ -105,7 +105,7 @@ public ActionManager RegisterActionType(string actionUuid, Type actionType)


/// <summary>
/// Registers all actions which are decorated with an <seealso cref="ActionUuidAttribute"/>
/// Registers all actions which are decorated with an <seealso cref="StreamDeckActionAttribute"/>
/// withn a given <seealso cref="Assembly"/>.
/// </summary>
/// <returns>The instance of <seealso cref="ActionManager"/>.</returns>
Expand All @@ -114,10 +114,10 @@ public ActionManager RegisterAllActions(Assembly actionsAssembly)
{
this._Logger?.LogTrace($"{nameof(ActionManager)}.{nameof(RegisterAllActions)}(assembly)");

var actions = actionsAssembly.GetTypes().Where(type => Attribute.IsDefined(type, typeof(ActionUuidAttribute)));
var actions = actionsAssembly.GetTypes().Where(type => Attribute.IsDefined(type, typeof(StreamDeckActionAttribute)));
foreach (var actionType in actions)
{
var attr = actionType.GetCustomAttributes(typeof(ActionUuidAttribute), true).FirstOrDefault() as ActionUuidAttribute;
var attr = actionType.GetCustomAttributes(typeof(StreamDeckActionAttribute), true).FirstOrDefault() as StreamDeckActionAttribute;
this._Logger?.LogTrace($"{nameof(ActionManager)}.{nameof(RegisterAllActions)}({actionType}) {attr.Uuid}");
this.RegisterActionType(attr.Uuid, actionType);
}
Expand Down
15 changes: 7 additions & 8 deletions src/StreamDeckLib/ActionUuidAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace StreamDeckLib
{
public class ActionUuidAttribute : Attribute
{
private string _uuid;
public ActionUuidAttribute(string uuid = "")
/// <summary>
/// An extension of the <see cref="StreamDeckActionAttribute"/>, so that we don't immediately break people who update
/// their NuGet packages...
/// </summary>
[Obsolete("This is being replaced by StreamDeckActionAttribute, use that instead.")]
public class ActionUuidAttribute : StreamDeckActionAttribute
{
this.Uuid = uuid;
}

public string Uuid { get => _uuid; set => _uuid = value; }
}
}
}
4 changes: 2 additions & 2 deletions src/StreamDeckLib/BaseStreamDeckAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public abstract class BaseStreamDeckAction
/// Gets the UUID which uniquely identifies the individual actions within a plugin.
/// </summary>
/// <value>The UUID representing the action, which matches the value in the &quot;manifest.json&quot; file.</value>
public string ActionUuid
public virtual string ActionUuid
{
get
{
return this.GetType().GetCustomAttributes(typeof(ActionUuidAttribute), true).FirstOrDefault() is ActionUuidAttribute attr && !string.IsNullOrWhiteSpace(attr.Uuid)
return this.GetType().GetCustomAttributes(typeof(StreamDeckActionAttribute), true).FirstOrDefault() is StreamDeckActionAttribute attr && !string.IsNullOrWhiteSpace(attr.Uuid)
? attr.Uuid
: string.Empty;
}
Expand Down
15 changes: 15 additions & 0 deletions src/StreamDeckLib/StreamDeckActionAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace StreamDeckLib
{
public class StreamDeckActionAttribute : Attribute
{
private string _uuid;
public StreamDeckActionAttribute(string uuid = "")
{
this.Uuid = uuid;
}

public string Uuid { get => _uuid; set => _uuid = value; }
}
}

0 comments on commit d215f40

Please sign in to comment.