diff --git a/README.md b/README.md index 0c30c82..ba7d37c 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,9 @@ The Stream Deck Toolkit provides the functionality that communicates directly wi 2. BaseStreamDeckActionWithSettingsModel - 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. diff --git a/Templates/StreamDeck.PluginTemplate.Csharp/content/_PluginName_Action.cs b/Templates/StreamDeck.PluginTemplate.Csharp/content/_PluginName_Action.cs index c5c9455..be7ca14 100644 --- a/Templates/StreamDeck.PluginTemplate.Csharp/content/_PluginName_Action.cs +++ b/Templates/StreamDeck.PluginTemplate.Csharp/content/_PluginName_Action.cs @@ -7,7 +7,7 @@ namespace _StreamDeckPlugin_ { - [ActionUuid(Uuid="$(UUID).DefaultPluginAction")] + [StreamDeckAction(Uuid="$(UUID).DefaultPluginAction")] public class $(PluginName)Action : BaseStreamDeckActionWithSettingsModel { public override async Task OnKeyUp(StreamDeckEventPayload args) diff --git a/docs/articles/create.md b/docs/articles/create.md index 92cd64b..ca1f132 100644 --- a/docs/articles/create.md +++ b/docs/articles/create.md @@ -6,6 +6,6 @@ The Stream Deck Toolkit provides the functionality that communicates directly wi 2. `BaseStreamDeckActionWithSettingsModel` - 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. diff --git a/docs/articles/template/action.md b/docs/articles/template/action.md index 1684240..8479809 100644 --- a/docs/articles/template/action.md +++ b/docs/articles/template/action.md @@ -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 diff --git a/src/SampleDIPlugin/MySamplePluginAction.cs b/src/SampleDIPlugin/MySamplePluginAction.cs index 8a1f303..031d033 100644 --- a/src/SampleDIPlugin/MySamplePluginAction.cs +++ b/src/SampleDIPlugin/MySamplePluginAction.cs @@ -5,7 +5,7 @@ namespace SampleDIPlugin { - [ActionUuid(Uuid = "com.csharpfritz.samplePlugin.action")] + [StreamDeckAction(Uuid = "com.csharpfritz.samplePlugin.action")] public class MySamplePluginAction : BaseStreamDeckActionWithSettingsModel { diff --git a/src/SampleDIPlugin/MySamplePluginAction2.cs b/src/SampleDIPlugin/MySamplePluginAction2.cs index 64cb2d0..32b7e5f 100644 --- a/src/SampleDIPlugin/MySamplePluginAction2.cs +++ b/src/SampleDIPlugin/MySamplePluginAction2.cs @@ -5,7 +5,7 @@ namespace SampleDIPlugin { - [ActionUuid(Uuid = "com.csharpfritz.samplePlugin.action2")] + [StreamDeckAction(Uuid = "com.csharpfritz.samplePlugin.action2")] public class MySamplePluginAction2 : BaseStreamDeckActionWithSettingsModel { diff --git a/src/SamplePlugin/MySamplePluginAction.cs b/src/SamplePlugin/MySamplePluginAction.cs index d4aaf33..157da23 100644 --- a/src/SamplePlugin/MySamplePluginAction.cs +++ b/src/SamplePlugin/MySamplePluginAction.cs @@ -5,7 +5,7 @@ namespace SamplePlugin { - [ActionUuid(Uuid = "com.csharpfritz.samplePlugin.action")] + [StreamDeckAction(Uuid = "com.csharpfritz.samplePlugin.action")] public class MySamplePluginAction : BaseStreamDeckActionWithSettingsModel { diff --git a/src/SamplePlugin/MySamplePluginAction2.cs b/src/SamplePlugin/MySamplePluginAction2.cs index c912968..2655751 100644 --- a/src/SamplePlugin/MySamplePluginAction2.cs +++ b/src/SamplePlugin/MySamplePluginAction2.cs @@ -5,7 +5,7 @@ namespace SamplePlugin { - [ActionUuid(Uuid = "com.csharpfritz.samplePlugin.action2")] + [StreamDeckAction(Uuid = "com.csharpfritz.samplePlugin.action2")] public class MySamplePluginAction2 : BaseStreamDeckActionWithSettingsModel { diff --git a/src/SampleWebPlugin/MySamplePluginAction.cs b/src/SampleWebPlugin/MySamplePluginAction.cs index f60ee2a..061469b 100644 --- a/src/SampleWebPlugin/MySamplePluginAction.cs +++ b/src/SampleWebPlugin/MySamplePluginAction.cs @@ -5,7 +5,7 @@ namespace SampleWebPlugin { - [ActionUuid(Uuid = "com.csharpfritz.samplePlugin.action")] + [StreamDeckAction(Uuid = "com.csharpfritz.samplePlugin.action")] public class MySamplePluginAction : BaseStreamDeckActionWithSettingsModel { diff --git a/src/SampleWebPlugin/MySamplePluginAction2.cs b/src/SampleWebPlugin/MySamplePluginAction2.cs index 65490af..81226ba 100644 --- a/src/SampleWebPlugin/MySamplePluginAction2.cs +++ b/src/SampleWebPlugin/MySamplePluginAction2.cs @@ -5,7 +5,7 @@ namespace SampleWebPlugin { - [ActionUuid(Uuid = "com.csharpfritz.samplePlugin.action2")] + [StreamDeckAction(Uuid = "com.csharpfritz.samplePlugin.action2")] public class MySamplePluginAction2 : BaseStreamDeckActionWithSettingsModel { diff --git a/src/StreamDeckLib.Test/Stubs/StubAction.cs b/src/StreamDeckLib.Test/Stubs/StubAction.cs index 14b046a..b31bc67 100644 --- a/src/StreamDeckLib.Test/Stubs/StubAction.cs +++ b/src/StreamDeckLib.Test/Stubs/StubAction.cs @@ -4,7 +4,7 @@ namespace StreamDeckLib.Test { - [ActionUuid(Uuid = "Test UUID")] + [StreamDeckAction(Uuid = "Test UUID")] public class StubAction : BaseStreamDeckAction { public int Counter = 0; diff --git a/src/StreamDeckLib/ActionManager.cs b/src/StreamDeckLib/ActionManager.cs index 4b99b75..8579723 100644 --- a/src/StreamDeckLib/ActionManager.cs +++ b/src/StreamDeckLib/ActionManager.cs @@ -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); @@ -105,7 +105,7 @@ public ActionManager RegisterActionType(string actionUuid, Type actionType) /// - /// Registers all actions which are decorated with an + /// Registers all actions which are decorated with an /// withn a given . /// /// The instance of . @@ -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); } diff --git a/src/StreamDeckLib/ActionUuidAttribute.cs b/src/StreamDeckLib/ActionUuidAttribute.cs index b9e3144..43820e3 100644 --- a/src/StreamDeckLib/ActionUuidAttribute.cs +++ b/src/StreamDeckLib/ActionUuidAttribute.cs @@ -2,14 +2,13 @@ namespace StreamDeckLib { - public class ActionUuidAttribute : Attribute - { - private string _uuid; - public ActionUuidAttribute(string uuid = "") + /// + /// An extension of the , so that we don't immediately break people who update + /// their NuGet packages... + /// + [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; } - } + } } diff --git a/src/StreamDeckLib/BaseStreamDeckAction.cs b/src/StreamDeckLib/BaseStreamDeckAction.cs index f3c0817..954b7c6 100644 --- a/src/StreamDeckLib/BaseStreamDeckAction.cs +++ b/src/StreamDeckLib/BaseStreamDeckAction.cs @@ -19,11 +19,11 @@ public abstract class BaseStreamDeckAction /// Gets the UUID which uniquely identifies the individual actions within a plugin. /// /// The UUID representing the action, which matches the value in the "manifest.json" file. - 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; } diff --git a/src/StreamDeckLib/StreamDeckActionAttribute.cs b/src/StreamDeckLib/StreamDeckActionAttribute.cs new file mode 100644 index 0000000..f226233 --- /dev/null +++ b/src/StreamDeckLib/StreamDeckActionAttribute.cs @@ -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; } + } +}