Exemplo n.º 1
0
 /// <summary>
 /// Send settings to the PropertyInspector
 /// </summary>
 /// <param name="settings"></param>
 /// <returns></returns>
 public async Task SendToPropertyInspectorAsync(JObject settings)
 {
     if (StreamDeckConnection != null && !String.IsNullOrEmpty(ContextId) && !String.IsNullOrEmpty(actionId))
     {
         await StreamDeckConnection.SendToPropertyInspectorAsync(actionId, settings, ContextId);
     }
 }
Exemplo n.º 2
0
        public void Run(int port, string uuid, string registerEvent)
        {
            this.connection = new StreamDeckConnection(port, uuid, registerEvent);

            this.connection.OnConnected               += Connection_OnConnected;
            this.connection.OnDisconnected            += Connection_OnDisconnected;
            this.connection.OnApplicationDidLaunch    += Connection_OnApplicationDidLaunch;
            this.connection.OnApplicationDidTerminate += Connection_OnApplicationDidTerminate;
            this.connection.OnKeyDown                  += Connection_OnKeyDown;
            this.connection.OnWillAppear               += Connection_OnWillAppear;
            this.connection.OnWillDisappear            += Connection_OnWillDisappear;
            this.connection.OnSendToPlugin             += Connection_OnSendToPlugin;
            this.connection.OnTitleParametersDidChange += Connection_OnTitleParametersDidChange;

            // Start the connection
            connection.Run();

            // Wait for up to 10 seconds to connect, if it fails, the app will exit
            if (this.connectEvent.WaitOne(TimeSpan.FromSeconds(10)))
            {
                // We connected, loop every second until we disconnect
                while (!this.disconnectEvent.WaitOne(TimeSpan.FromMilliseconds(1000)))
                {
                    RunTick();
                }
            }
            else
            {
                Console.WriteLine("Mix It Up Plugin failed to connect to Stream Deck");
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Persists your plugin settings
 /// </summary>
 /// <param name="settings"></param>
 /// <returns></returns>
 public async Task SetSettingsAsync(JObject settings)
 {
     if (StreamDeckConnection != null && !String.IsNullOrEmpty(ContextId) && !String.IsNullOrEmpty(actionId))
     {
         await StreamDeckConnection.SetSettingsAsync(settings, ContextId);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Persists your global plugin settings
 /// </summary>
 /// <returns></returns>
 public async Task GetGlobalSettingsAsync()
 {
     if (StreamDeckConnection != null)
     {
         await StreamDeckConnection.GetGlobalSettingsAsync();
     }
 }
Exemplo n.º 5
0
        public void Run(StreamDeckOptions options)
        {
            pluginUUID = options.PluginUUID;
            deviceInfo = options.DeviceInfo;
            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.OnDidReceiveSettings       += Connection_OnDidReceiveSettings;
            connection.OnDidReceiveGlobalSettings += Connection_OnDidReceiveGlobalSettings;

            // Start the connection
            connection.Run();
            Logger.Instance.LogMessage(TracingLevel.INFO, "Connecting to Stream Deck");

            // Wait for up to 10 seconds to connect
            if (connectEvent.WaitOne(TimeSpan.FromSeconds(10)))
            {
                Logger.Instance.LogMessage(TracingLevel.INFO, "Connected to Stream Deck");

                // We connected, loop every second until we disconnect
                while (!disconnectEvent.WaitOne(TimeSpan.FromMilliseconds(1000)))
                {
                    RunTick();
                }
            }
            Logger.Instance.LogMessage(TracingLevel.INFO, "Plugin Disconnected - Exiting");
        }
Exemplo n.º 6
0
        public async Task RunAsync(int port, string uuid, string registerEvent)
        {
            m_Connection = new StreamDeckConnection(port, uuid, registerEvent);

            m_Connection.OnConnected     += Connection_OnConnected;
            m_Connection.OnDisconnected  += Connection_OnDisconnected;
            m_Connection.OnKeyDown       += Connection_OnKeyDown;
            m_Connection.OnKeyUp         += Connection_OnKeyUp;
            m_Connection.OnWillAppear    += Connection_OnWillAppear;
            m_Connection.OnWillDisappear += Connection_OnWillDisappear;
            m_Connection.OnSendToPlugin  += Connection_OnSendToPlugin;

            // Start the connection
            m_Connection.Run();

            // Wait for up to 10 seconds to connect, if it fails, the app will exit
            if (m_ConnectEvent.WaitOne(TimeSpan.FromSeconds(10)))
            {
                // We connected, loop every 1/2 second until we disconnect
                while (!m_DisconnectEvent.WaitOne(TimeSpan.FromMilliseconds(500)))
                {
                    await RunTickAsync();
                }
            }
            else
            {
                Console.WriteLine("Plugin failed to connect to Stream Deck");
            }
        }
Exemplo n.º 7
0
        public override async Task LoadAsync(StreamDeckConnection connection, string action, string context, JObject settings)
        {
            this.connection = connection;
            this.Action     = action;
            this.Context    = context;

            await this.connection.SetTitleAsync("Loading...", this.Context, SDKTarget.HardwareAndSoftware);
        }
Exemplo n.º 8
0
        internal void Initialize(StreamDeckConnection connection, int getGlobalSettingsDelayMs = GET_GLOBAL_SETTINGS_DELAY_MS)
        {
            this.connection = connection;
            this.connection.OnDidReceiveGlobalSettings += Connection_OnDidReceiveGlobalSettings;

            tmrGetGlobalSettings.Stop();
            tmrGetGlobalSettings.Interval = getGlobalSettingsDelayMs;
            Logger.Instance.LogMessage(TracingLevel.INFO, "GlobalSettingsManager initialized");
        }
        public override Task LoadAsync(StreamDeckConnection connection, string action, string context, JObject settings)
        {
            m_Connection = connection;
            m_Action     = action;
            m_Context    = context;
            m_Settings   = settings.ToObject <ClockActionSettings>();

            return(Task.FromResult(0));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Sets an image on the StreamDeck key.
        /// </summary>
        /// <param name="base64Image">Base64 encoded image</param>
        /// <returns></returns>
        public async Task SetImageAsync(string base64Image, bool forceSendToStreamdeck = false)
        {
            string hash = Tools.StringToMD5(base64Image);

            if (forceSendToStreamdeck || hash != previousImageHash)
            {
                previousImageHash = hash;
                await StreamDeckConnection.SetImageAsync(base64Image, ContextId, streamdeck_client_csharp.SDKTarget.HardwareAndSoftware);
            }
        }
Exemplo n.º 11
0
        /// <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>
        public async Task SetImageAsync(Image image, int?state = null, bool forceSendToStreamdeck = false)
        {
            string hash = Tools.ImageToSHA512(image);

            if (forceSendToStreamdeck || hash != previousImageHash)
            {
                previousImageHash = hash;
                await StreamDeckConnection.SetImageAsync(image, ContextId, streamdeck_client_csharp.SDKTarget.HardwareAndSoftware, state);
            }
        }
Exemplo n.º 12
0
        /// <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>
        public async Task SetGlobalSettingsAsync(JObject settings, bool triggerDidReceiveGlobalSettings = true)
        {
            if (StreamDeckConnection != null)
            {
                await StreamDeckConnection.SetGlobalSettingsAsync(settings);

                if (triggerDidReceiveGlobalSettings)
                {
                    await GetGlobalSettingsAsync();
                }
            }
        }
Exemplo n.º 13
0
        public override async Task LoadAsync(StreamDeckConnection connection, string action, string context, JObject settings)
        {
            this.connection = connection;
            this.Action     = action;
            this.Context    = context;

            if (settings != null)
            {
                this.actionSettings = settings.ToObject <RunCommandSettings>();
            }

            await this.connection.SetTitleAsync("Loading...", this.Context, SDKTarget.HardwareAndSoftware);

            await this.RefreshTitleAsync();
        }
Exemplo n.º 14
0
        public Soundboard(Options options)
        {
            _connection = new StreamDeckConnection(options.Port,
                                                   options.PluginUUID,
                                                   options.RegisterEvent);

            _connection.OnApplicationDidLaunch    += OnStreamDeckLaunched;
            _connection.OnConnected               += OnStreamDeckConnected;
            _connection.OnDeviceDidConnect        += OnStreamDeckDeviceConnected;
            _connection.OnWillAppear              += OnItemAppear;
            _connection.OnWillDisappear           += OnItemDisappear;
            _connection.OnDeviceDidDisconnect     += OnStreamDeckDeviceDisconnected;
            _connection.OnDisconnected            += OnStreamDeckDisconnected;
            _connection.OnApplicationDidTerminate += OnStreamDeckTerminated;

            _connection.OnPropertyInspectorDidAppear += OnPropertyInspectorAppeared;
            _connection.OnDidReceiveSettings         += OnReceiveSettings;
            _connection.OnDidReceiveGlobalSettings   += OnReceiveGlobalSettings;
            _connection.OnKeyDown += OnKeyDown;

            _connection.Run();
            IsRunning = true;
        }
Exemplo n.º 15
0
 /// <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>
 public async Task LogSDMessage(string message)
 {
     await StreamDeckConnection.LogMessageAsync(message);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Shows the Success (Green checkmark) on the StreamDeck key
 /// </summary>
 /// <returns></returns>
 public async Task ShowOk()
 {
     await StreamDeckConnection.ShowOkAsync(ContextId);
 }
Exemplo n.º 17
0
 /// <summary>
 /// Shows the Alert (Yellow Triangle) on the StreamDeck key
 /// </summary>
 /// <returns></returns>
 public async Task ShowAlert()
 {
     await StreamDeckConnection.ShowAlertAsync(ContextId);
 }
Exemplo n.º 18
0
 /// <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>
 public async Task SwitchProfileAsync(string profileName, string deviceId)
 {
     await StreamDeckConnection.SwitchToProfileAsync(deviceId, profileName, this.pluginUUID);
 }
Exemplo n.º 19
0
 public override Task LoadAsync(StreamDeckConnection connection, string action, string context, JObject settings)
 {
     m_Connection = connection;
     m_Context    = context;
     return(Task.FromResult(0));
 }
Exemplo n.º 20
0
 /// <summary>
 /// Sets the plugin to a specific state which is pre-configured in the manifest file
 /// </summary>
 /// <param name="state"></param>
 /// <returns></returns>
 public async Task SetStateAsync(uint state)
 {
     await StreamDeckConnection.SetStateAsync(state, ContextId);
 }
Exemplo n.º 21
0
 /// <summary>
 /// Opens a URI in the user's browser
 /// </summary>
 /// <param name="uri"></param>
 /// <returns></returns>
 public async Task OpenUrlAsync(Uri uri)
 {
     await StreamDeckConnection.OpenUrlAsync(uri);
 }
Exemplo n.º 22
0
 /// <summary>
 /// Tells Stream Deck to return the current plugin settings via the ReceivedSettings function
 /// </summary>
 /// <returns></returns>
 public async Task GetSettingsAsync()
 {
     await StreamDeckConnection.GetSettingsAsync(ContextId);
 }
 /// <summary>
 /// Sets an image on the StreamDeck key
 /// </summary>
 /// <param name="image">Image object</param>
 /// <returns></returns>
 public async Task SetImageAsync(Image image)
 {
     await StreamDeckConnection.SetImageAsync(image, ContextId, streamdeck_client_csharp.SDKTarget.HardwareAndSoftware);
 }
Exemplo n.º 24
0
        static void RunPlugin(Options options)
        {
            ManualResetEvent connectEvent    = new ManualResetEvent(false);
            ManualResetEvent disconnectEvent = new ManualResetEvent(false);

            StreamDeckConnection connection = new StreamDeckConnection(options.Port, options.PluginUUID, options.RegisterEvent);

            connection.OnConnected += (sender, args) =>
            {
                connectEvent.Set();
            };

            connection.OnDisconnected += (sender, args) =>
            {
                disconnectEvent.Set();
            };

            connection.OnApplicationDidLaunch += (sender, args) =>
            {
                System.Diagnostics.Debug.WriteLine($"App Launch: {args.Event.Payload.Application}");
            };

            connection.OnApplicationDidTerminate += (sender, args) =>
            {
                System.Diagnostics.Debug.WriteLine($"App Terminate: {args.Event.Payload.Application}");
            };


            Dictionary <string, int>     counters = new Dictionary <string, int>();
            Dictionary <string, int>     clickers = new Dictionary <string, int>();
            List <string>                images   = new List <string>();
            Dictionary <string, JObject> settings = new Dictionary <string, JObject>();

            connection.OnWillAppear += (sender, args) =>
            {
                switch (args.Event.Action)
                {
                case "com.fourofour.testplugin.actions.counter":
                    lock (counters)
                    {
                        counters[args.Event.Context] = 0;
                    }
                    break;

                case "com.fourofour.testplugin.actions.clicker":
                    clickers[args.Event.Context] = 0;
                    connection.SetTitleAsync(clickers[args.Event.Context].ToString(), args.Event.Context, SDKTarget.HardwareAndSoftware, null);
                    break;
                }
            };

            connection.OnWillDisappear += (sender, args) =>
            {
                lock (counters)
                {
                    if (counters.ContainsKey(args.Event.Context))
                    {
                        counters.Remove(args.Event.Context);
                    }
                }
            };

            connection.OnKeyDown += (sender, args) =>
            {
                switch (args.Event.Action)
                {
                case "com.fourofour.testplugin.actions.clicker":
                    foreach (KeyValuePair <string, int> kvp in clickers)
                    {
                        clickers[args.Event.Context]++;
                        connection.SetTitleAsync(clickers[args.Event.Context].ToString(), kvp.Key, SDKTarget.HardwareAndSoftware, null);
                    }
                    break;
                }
            };

            // Start the connection
            connection.Run();

            // Current Directory is the base Stream Deck Install path.
            // For example: C:\Program Files\Elgato\StreamDeck\
            Image image = Image.FromFile(@"Images\TyDidIt40x40.png");

            // 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)))
                {
                    lock (counters)
                    {
                        foreach (KeyValuePair <string, int> kvp in counters.ToArray())
                        {
                            _ = connection.SetTitleAsync(kvp.Value.ToString(), kvp.Key, SDKTarget.HardwareAndSoftware, null);
                            counters[kvp.Key]++;
                        }
                    }
                }
            }
        }
Exemplo n.º 25
0
        static void RunPlugin(Options options)
        {
            ManualResetEvent connectEvent    = new ManualResetEvent(false);
            ManualResetEvent disconnectEvent = new ManualResetEvent(false);

            StreamDeckConnection connection = new StreamDeckConnection(options.Port, options.PluginUUID, options.RegisterEvent);

            connection.OnConnected += (sender, args) =>
            {
                connectEvent.Set();
            };

            connection.OnDisconnected += (sender, args) =>
            {
                disconnectEvent.Set();
            };

            connection.OnApplicationDidLaunch += (sender, args) =>
            {
                System.Diagnostics.Debug.WriteLine($"App Launch: {args.Event.Payload.Application}");
            };

            connection.OnApplicationDidTerminate += (sender, args) =>
            {
                System.Diagnostics.Debug.WriteLine($"App Terminate: {args.Event.Payload.Application}");
            };

            Dictionary <string, JObject> settings = new Dictionary <string, JObject>();

            connection.OnKeyUp += (sender, args) =>
            {
                JObject c_settings = args.Event.Payload.Settings;
                Thread  thread     = new Thread(() => Clipboard.SetText(System.Net.WebUtility.UrlDecode(args.Event.Payload.Settings["textDemoValue"].ToString())));
                thread.SetApartmentState(ApartmentState.STA); //Set the thread to STA
                thread.Start();
                thread.Join();
                System.Windows.Forms.SendKeys.SendWait("^(V)");
            };


            connection.OnDidReceiveSettings += (sender, args) =>
            {
            };

            connection.OnWillDisappear += (sender, args) =>
            {
                lock (settings)
                {
                    if (settings.ContainsKey(args.Event.Context))
                    {
                        settings.Remove(args.Event.Context);
                    }
                }
            };

            // 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)))
                {
                }
            }
        }
Exemplo n.º 26
0
 public abstract Task LoadAsync(StreamDeckConnection connection, string action, string context, JObject settings);
Exemplo n.º 27
0
        static void RunPlugin(Options options)
        {
            ManualResetEvent connectEvent    = new ManualResetEvent(false);
            ManualResetEvent disconnectEvent = new ManualResetEvent(false);

            StreamDeckConnection connection = new StreamDeckConnection(options.Port, options.PluginUUID, options.RegisterEvent);

            connection.OnConnected += (sender, args) =>
            {
                connectEvent.Set();
            };

            connection.OnDisconnected += (sender, args) =>
            {
                disconnectEvent.Set();
            };

            connection.OnApplicationDidLaunch += (sender, args) =>
            {
                System.Diagnostics.Debug.WriteLine($"App Launch: {args.Event.Payload.Application}");
            };

            connection.OnApplicationDidTerminate += (sender, args) =>
            {
                System.Diagnostics.Debug.WriteLine($"App Terminate: {args.Event.Payload.Application}");
            };

            Dictionary <string, int>     counters = new Dictionary <string, int>();
            List <string>                images   = new List <string>();
            Dictionary <string, JObject> settings = new Dictionary <string, JObject>();

            string allplayers = "allplayer";
            string guild      = "guild";

            connection.OnWillAppear += (sender, args) =>
            {
                switch (args.Event.Action)
                {
                case "com.tyren.testplugin.counter":
                    lock (counters)
                    {
                        counters[args.Event.Context] = 0;
                    }
                    break;

                case "com.tyren.testplugin.changeimage":
                    lock (images)
                    {
                        images.Add(args.Event.Context);
                    }
                    break;

                case "com.tyren.dnw.playercounter":
                    lock (images)
                    {
                        counters[args.Event.Context] = GetPlayerCount("allplayers");
                        allplayers = args.Event.Context;
                    }
                    break;

                case "com.tyren.dnw.guildcounter":
                    lock (images)
                    {
                        counters[args.Event.Context] = GetPlayerCount("guild");
                        guild = args.Event.Context;
                    }
                    break;
                }
            };

            connection.OnDidReceiveSettings += (sender, args) =>
            {
                switch (args.Event.Action)
                {
                    //case "com.tyren.testplugin.pidemo":
                    //    lock (settings)
                    //    {
                    //        settings[args.Event.Context] = args.Event.Payload.Settings;
                    //        if (settings[args.Event.Context] == null)
                    //        {
                    //            settings[args.Event.Context] = new JObject();
                    //        }
                    //        if (settings[args.Event.Context]["selectedValue"] == null)
                    //        {
                    //            settings[args.Event.Context]["selectedValue"] = JValue.CreateString("20");
                    //        }
                    //        if (settings[args.Event.Context]["textDemoValue"] == null)
                    //        {
                    //            settings[args.Event.Context]["textDemoValue"] = JValue.CreateString("");
                    //        }
                    //    }
                    //    break;
                }
            };

            connection.OnWillDisappear += (sender, args) =>
            {
                lock (counters)
                {
                    if (counters.ContainsKey(args.Event.Context))
                    {
                        counters.Remove(args.Event.Context);
                    }
                }

                lock (images)
                {
                    if (images.Contains(args.Event.Context))
                    {
                        images.Remove(args.Event.Context);
                    }
                }

                lock (settings)
                {
                    if (settings.ContainsKey(args.Event.Context))
                    {
                        settings.Remove(args.Event.Context);
                    }
                }
            };

            // Start the connection
            connection.Run();

            // Current Directory is the base Stream Deck Install path.
            // For example: C:\Program Files\Elgato\StreamDeck\
            Image image = Image.FromFile(@"Images\TyDidIt40x40.png");

            // Wait for up to 10 seconds to connect
            if (connectEvent.WaitOne(TimeSpan.FromSeconds(10)))
            {
                // We connected, loop every xxxx until we disconnect
                while (!disconnectEvent.WaitOne(TimeSpan.FromSeconds(2)))
                {
                    lock (counters)
                    {
                        foreach (KeyValuePair <string, int> kvp in counters.ToArray())
                        {
                            if (allplayers.Contains(kvp.Key))
                            {
                                counters[kvp.Key] = GetPlayerCount("allplayers");
                                _ = connection.SetTitleAsync(kvp.Value.ToString(), kvp.Key, SDKTarget.HardwareAndSoftware, null);
                            }
                            else if (guild.Contains(kvp.Key))
                            {
                                counters[kvp.Key] = GetPlayerCount("guild");
                                _ = connection.SetTitleAsync(kvp.Value.ToString(), kvp.Key, SDKTarget.HardwareAndSoftware, null);
                            }
                            else
                            {
                                _ = connection.SetTitleAsync(kvp.Value.ToString(), kvp.Key, SDKTarget.HardwareAndSoftware, null);
                                counters[kvp.Key]++;
                            }
                        }
                    }

                    lock (images)
                    {
                        foreach (string imageContext in images)
                        {
                            _ = connection.SetImageAsync(image, imageContext, SDKTarget.HardwareAndSoftware, null);
                        }

                        images.Clear();
                    }
                }
            }
        }
Exemplo n.º 28
0
 /// <summary>
 /// Sets a title on the StreamDeck key
 /// </summary>
 /// <param name="title"></param>
 /// <returns></returns>
 public async Task SetTitleAsync(string title)
 {
     await StreamDeckConnection.SetTitleAsync(title, ContextId, streamdeck_client_csharp.SDKTarget.HardwareAndSoftware);
 }
Exemplo n.º 29
0
 public void Initialize(StreamDeckConnection connection)
 {
     this.connection = connection;
     this.connection.OnDidReceiveGlobalSettings += Connection_OnDidReceiveGlobalSettings;
     Logger.Instance.LogMessage(TracingLevel.INFO, "GlobalSettingsManager initialized");
 }
        static void RunPlugin(Options options)
        {
            ManualResetEvent connectEvent    = new ManualResetEvent(false);
            ManualResetEvent disconnectEvent = new ManualResetEvent(false);

            connection = new StreamDeckConnection(options.Port, options.PluginUUID, options.RegisterEvent);

            connection.OnConnected += (sender, args) =>
            {
                connectEvent.Set();
            };

            connection.OnDisconnected += (sender, args) =>
            {
                disconnectEvent.Set();
            };

            connection.OnApplicationDidLaunch += (sender, args) =>
            {
                System.Diagnostics.Debug.WriteLine($"App Launch: {args.Event.Payload.Application}");
            };

            connection.OnApplicationDidTerminate += (sender, args) =>
            {
                System.Diagnostics.Debug.WriteLine($"App Terminate: {args.Event.Payload.Application}");
            };

            Dictionary <string, JObject> settings = new Dictionary <string, JObject>();

            connection.OnWillAppear += (sender, args) =>
            {
                lock (settings)
                {
                    settings[args.Event.Context] = args.Event.Payload.Settings;

                    if (settings[args.Event.Context] == null)
                    {
                        settings[args.Event.Context] = new JObject();
                    }

                    switch (args.Event.Action)
                    {
                    case "wtf.tas.tasagentbot.vfx":
                        if (!settings[args.Event.Context].ContainsKey("voiceEffect") || string.IsNullOrEmpty(settings[args.Event.Context]["voiceEffect"].Value <string>()))
                        {
                            settings[args.Event.Context]["voiceEffect"] = JValue.CreateString("none");
                        }
                        break;

                    case "wtf.tas.tasagentbot.sfx":
                        if (!settings[args.Event.Context].ContainsKey("soundEffect") || string.IsNullOrEmpty(settings[args.Event.Context]["soundEffect"].Value <string>()))
                        {
                            settings[args.Event.Context]["soundEffect"] = JValue.CreateString("sephiroth");
                        }
                        break;

                    case "wtf.tas.tasagentbot.rest":
                        if (!settings[args.Event.Context].ContainsKey("endPoint") || string.IsNullOrEmpty(settings[args.Event.Context]["endPoint"].Value <string>()))
                        {
                            settings[args.Event.Context]["endPoint"] = JValue.CreateString("/TASagentBotAPI/SFX/Skip");
                        }

                        if (!settings[args.Event.Context].ContainsKey("jsonBody") || string.IsNullOrEmpty(settings[args.Event.Context]["jsonBody"].Value <string>()))
                        {
                            settings[args.Event.Context]["jsonBody"] = JValue.CreateString("{\n  \"effect\": \"None\"\n}");
                        }
                        break;

                    case "wtf.tas.tasagentbot.micmonitor":
                        try
                        {
                            connection.SetImageAsync(CurrentMicImage, args.Event.Context, SDKTarget.HardwareAndSoftware, null);
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine($"Mic SetImage Exception: {ex}");
                        }

                        lock (micTesters)
                        {
                            micTesters.Add(args.Event.Context);
                        }
                        break;

                    case "wtf.tas.tasagentbot.lockdownmonitor":
                        try
                        {
                            connection.SetImageAsync(CurrentLockImage, args.Event.Context, SDKTarget.HardwareAndSoftware, null);
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine($"Lock SetImage Exception: {ex}");
                        }

                        lock (lockTesters)
                        {
                            lockTesters.Add(args.Event.Context);
                        }
                        break;
                    }
                }
            };

            connection.OnDidReceiveSettings += (sender, args) =>
            {
                lock (settings)
                {
                    settings[args.Event.Context] = args.Event.Payload.Settings;

                    if (settings[args.Event.Context] == null)
                    {
                        settings[args.Event.Context] = new JObject();
                    }

                    switch (args.Event.Action)
                    {
                    case "wtf.tas.tasagentbot.vfx":
                        if (!settings[args.Event.Context].ContainsKey("voiceEffect") || string.IsNullOrEmpty(settings[args.Event.Context]["voiceEffect"].Value <string>()))
                        {
                            settings[args.Event.Context]["voiceEffect"] = JValue.CreateString("none");
                        }
                        break;

                    case "wtf.tas.tasagentbot.sfx":
                        if (!settings[args.Event.Context].ContainsKey("soundEffect") || string.IsNullOrEmpty(settings[args.Event.Context]["soundEffect"].Value <string>()))
                        {
                            settings[args.Event.Context]["soundEffect"] = JValue.CreateString("sephiroth");
                        }
                        break;

                    case "wtf.tas.tasagentbot.rest":
                        if (!settings[args.Event.Context].ContainsKey("endPoint") || string.IsNullOrEmpty(settings[args.Event.Context]["endPoint"].Value <string>()))
                        {
                            settings[args.Event.Context]["endPoint"] = JValue.CreateString("/TASagentBotAPI/SFX/Skip");
                        }

                        if (!settings[args.Event.Context].ContainsKey("jsonBody") || string.IsNullOrEmpty(settings[args.Event.Context]["jsonBody"].Value <string>()))
                        {
                            settings[args.Event.Context]["jsonBody"] = JValue.CreateString("{\n  \"effect\": \"None\"\n}");
                        }
                        break;
                    }
                }
            };

            connection.OnDidReceiveGlobalSettings += (sender, args) =>
            {
                globalSettings = args.Event.Payload.Settings;

                if (globalSettings == null)
                {
                    globalSettings = new JObject();
                }

                if (!globalSettings.ContainsKey("botURL"))
                {
                    globalSettings.Add("botURL", JValue.CreateString("http://*****:*****@"Images\MicMonitorIcon.png");
            normalMicImage       = Image.FromFile(@"Images\NormalMic.png");
            moddedMicImage       = Image.FromFile(@"Images\ModdedMic.png");

            noConnectionLockImage = Image.FromFile(@"Images\UndeterminedLockIcon.png");
            unlockedImage         = Image.FromFile(@"Images\UnlockedIcon.png");
            lockedImage           = Image.FromFile(@"Images\LockedIcon.png");

            // Wait for up to 10 seconds to connect
            if (connectEvent.WaitOne(TimeSpan.FromSeconds(10)))
            {
                connection.GetGlobalSettingsAsync().Wait();

                // We connected, loop every three seconds until we disconnect
                while (!disconnectEvent.WaitOne(TimeSpan.FromMilliseconds(1000)))
                {
                    if (micTesters.Count > 0)
                    {
                        TestMicSettings();
                    }

                    if (lockTesters.Count > 0)
                    {
                        TestLockSettings();
                    }
                }
            }
        }