diff --git a/DelayedText/DelayedText.csproj b/DelayedText/DelayedText.csproj index b12123a..a7ea193 100644 --- a/DelayedText/DelayedText.csproj +++ b/DelayedText/DelayedText.csproj @@ -33,9 +33,6 @@ 4 - - ..\..\barraider-sdtools\barraider-sdtools\bin\Release\barraider-sdtools.dll - ..\packages\CommandLineParser.2.4.3\lib\netstandard2.0\CommandLine.dll @@ -63,7 +60,6 @@ - @@ -74,7 +70,12 @@ - + + + {dabbd97d-6687-4cbd-a19e-ac9ffa3cef03} + barraider-sdtools + + PreserveNewest diff --git a/DelayedText/DelayedTextInput.cs b/DelayedText/DelayedTextInput.cs index 6fecbeb..029ad91 100644 --- a/DelayedText/DelayedTextInput.cs +++ b/DelayedText/DelayedTextInput.cs @@ -11,13 +11,13 @@ namespace Delayedtext { - public class DelayedTextInput : IPluginable + public class DelayedTextInput : PluginBase { - private class InspectorSettings : SettingsBase + private class PluginSettings { - public static InspectorSettings CreateDefaultSettings() + public static PluginSettings CreateDefaultSettings() { - InspectorSettings instance = new InspectorSettings(); + PluginSettings instance = new PluginSettings(); instance.InputText = String.Empty; ; instance.Delay = 1; instance.EnterMode = false; @@ -40,29 +40,25 @@ public static InspectorSettings CreateDefaultSettings() private const int RESET_COUNTER_KEYPRESS_LENGTH = 1; private bool inputRunning = false; - private InspectorSettings settings; + private PluginSettings settings; #endregion #region Public Methods - public DelayedTextInput(streamdeck_client_csharp.StreamDeckConnection connection, string action, string context, JObject settings) + public DelayedTextInput(SDConnection connection, JObject settings) : base(connection, settings) { if (settings == null || settings.Count == 0) { - this.settings = InspectorSettings.CreateDefaultSettings(); + this.settings = PluginSettings.CreateDefaultSettings(); } else { - this.settings = settings.ToObject(); + this.settings = settings.ToObject(); } - - this.settings.StreamDeckConnection = connection; - this.settings.ActionId = action; - this.settings.ContextId = context; } - public void KeyPressed() + public override void KeyPressed() { if (inputRunning) { @@ -72,37 +68,37 @@ public void KeyPressed() SendInput(); } - public void KeyReleased() + public override void KeyReleased() { } - public void OnTick() + public override void OnTick() { } - public void Dispose() + public override void Dispose() { } - public void UpdateSettings(JObject payload) + public override void UpdateSettings(JObject payload) { if (payload["property_inspector"] != null) { switch (payload["property_inspector"].ToString().ToLower()) { case "propertyinspectorconnected": - settings.SendToPropertyInspectorAsync(); + Connection.SendToPropertyInspectorAsync(JObject.FromObject(settings)); break; case "propertyinspectorwilldisappear": - settings.SetSettingsAsync(); + Connection.SetSettingsAsync(JObject.FromObject(settings)); break; case "updatesettings": settings.Delay = (int)payload["delay"]; settings.InputText = (string)payload["inputText"]; settings.EnterMode = (bool)payload["enterMode"]; - settings.SetSettingsAsync(); + Connection.SetSettingsAsync(JObject.FromObject(settings)); break; } } diff --git a/DelayedText/PluginContainer.cs b/DelayedText/PluginContainer.cs deleted file mode 100644 index ff6dcd9..0000000 --- a/DelayedText/PluginContainer.cs +++ /dev/null @@ -1,155 +0,0 @@ -using BarRaider.SdTools; -using Newtonsoft.Json; -using streamdeck_client_csharp; -using streamdeck_client_csharp.Events; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace Delayedtext -{ - class PluginContainer - { - private StreamDeckConnection connection; - private ManualResetEvent connectEvent = new ManualResetEvent(false); - private ManualResetEvent disconnectEvent = new ManualResetEvent(false); - private SemaphoreSlim instancesLock = new SemaphoreSlim(1); - - // Holds all instances of plugin - private static Dictionary instances = new Dictionary(); - - - public void Run(StreamDeckOptions options) - { - connection = new StreamDeckConnection(options.Port, options.PluginUUID, options.RegisterEvent); - - // Register for events - connection.OnConnected += Connection_OnConnected; - connection.OnDisconnected += Connection_OnDisconnected; - connection.OnKeyDown += Connection_OnKeyDown; - connection.OnKeyUp += Connection_OnKeyUp; - connection.OnWillAppear += Connection_OnWillAppear; - connection.OnWillDisappear += Connection_OnWillDisappear; - - // Settings changed - connection.OnSendToPlugin += Connection_OnSendToPlugin; - - // Start the connection - connection.Run(); - - // Wait for up to 10 seconds to connect - if (connectEvent.WaitOne(TimeSpan.FromSeconds(10))) - { - // We connected, loop every second until we disconnect - while (!disconnectEvent.WaitOne(TimeSpan.FromMilliseconds(1000))) - { - RunTick(); - } - } - } - - // Button pressed - private async void Connection_OnKeyDown(object sender, StreamDeckEventReceivedEventArgs e) - { - await instancesLock.WaitAsync(); - try - { - if (instances.ContainsKey(e.Event.Context)) - { - instances[e.Event.Context].KeyPressed(); - } - } - finally - { - instancesLock.Release(); - } - } - - // Button released - private async void Connection_OnKeyUp(object sender, StreamDeckEventReceivedEventArgs e) - { - await instancesLock.WaitAsync(); - try - { - if (instances.ContainsKey(e.Event.Context)) - { - instances[e.Event.Context].KeyReleased(); - } - } - finally - { - instancesLock.Release(); - } - } - - - // Function runs every second, used to update UI - private void RunTick() - { - } - - // Stopwatch instance created - private async void Connection_OnWillAppear(object sender, StreamDeckEventReceivedEventArgs e) - { - await instancesLock.WaitAsync(); - try - { - instances[e.Event.Context] = new DelayedTextInput(connection, e.Event.Action, e.Event.Context, e.Event.Payload.Settings); - } - finally - { - instancesLock.Release(); - } - } - - // Stopwatch instance no longer shown - private async void Connection_OnWillDisappear(object sender, StreamDeckEventReceivedEventArgs e) - { - await instancesLock.WaitAsync(); - try - { - if (instances.ContainsKey(e.Event.Context)) - { - instances.Remove(e.Event.Context); - } - } - finally - { - instancesLock.Release(); - } - } - - // Settings updated - private async void Connection_OnSendToPlugin(object sender, StreamDeckEventReceivedEventArgs e) - { - - await instancesLock.WaitAsync(); - try - { - if (instances.ContainsKey(e.Event.Context)) - { - instances[e.Event.Context].UpdateSettings(e.Event.Payload); - } - } - finally - { - instancesLock.Release(); - } - System.Diagnostics.Debug.WriteLine($"PLUGIN: {JsonConvert.SerializeObject(e.Event)}"); - - } - - private void Connection_OnConnected(object sender, EventArgs e) - { - connectEvent.Set(); - } - - private void Connection_OnDisconnected(object sender, EventArgs e) - { - disconnectEvent.Set(); - } - } -} diff --git a/DelayedText/Program.cs b/DelayedText/Program.cs index df34943..ebd61b4 100644 --- a/DelayedText/Program.cs +++ b/DelayedText/Program.cs @@ -1,54 +1,20 @@ using BarRaider.SdTools; using CommandLine; using System; +using System.Collections.Generic; namespace Delayedtext { class Program { - /************************************************************************ - * Initial configuration copied from TyrenDe's streamdeck-client-csharp example: - * https://github.com/TyrenDe/streamdeck-client-csharp - * and SaviorXTanren's MixItUp.StreamDeckPlugin: - * https://github.com/SaviorXTanren/mixer-mixitup/ - *************************************************************************/ - - // Handles all the communication with the plugin - private static PluginContainer container; - - // StreamDeck launches the plugin with these details - // -port [number] -pluginUUID [GUID] -registerEvent [string?] -info [json] static void Main(string[] args) { // Uncomment this line of code to allow for debugging //while (!System.Diagnostics.Debugger.IsAttached) { System.Threading.Thread.Sleep(100); } - // The command line args parser expects all args to use `--`, so, let's append - for (int count = 0; count < args.Length; count++) - { - if (args[count].StartsWith("-") && !args[count].StartsWith("--")) - { - args[count] = $"-{args[count]}"; - } - } - - Parser parser = new Parser((with) => - { - with.EnableDashDash = true; - with.CaseInsensitiveEnumValues = true; - with.CaseSensitive = false; - with.IgnoreUnknownArguments = true; - with.HelpWriter = Console.Error; - }); - - ParserResult options = parser.ParseArguments(args); - options.WithParsed(o => RunPlugin(o)); - } - - static void RunPlugin(StreamDeckOptions options) - { - container = new PluginContainer(); - container.Run(options); + List supportedActionIds = new List(); + supportedActionIds.Add(new PluginActionId("com.barraider.delayedtext", typeof(DelayedTextInput))); + SDWrapper.Run(args, supportedActionIds.ToArray()); } } } diff --git a/DelayedText/manifest.json b/DelayedText/manifest.json index 150f822..2a4cc8b 100644 --- a/DelayedText/manifest.json +++ b/DelayedText/manifest.json @@ -21,7 +21,7 @@ "Name": "Delayed Text Input", "Icon": "Images/pluginIcon", "URL": "https://barraider.github.io/", - "Version": "1.01", + "Version": "1.2", "CodePath": "com.barraider.delayedtext", "Category": "BarRaider", "CategoryIcon": "Images/categoryIcon",