From 630f958bd2c296f6bd2e47fe1c25cf7b34c36649 Mon Sep 17 00:00:00 2001 From: Dance Mom Date: Thu, 29 Sep 2022 14:00:37 -0500 Subject: [PATCH 1/2] Add plugin command to toggle connection --- MareSynchronos/Plugin.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/MareSynchronos/Plugin.cs b/MareSynchronos/Plugin.cs index 74d5bf8..86d2be9 100644 --- a/MareSynchronos/Plugin.cs +++ b/MareSynchronos/Plugin.cs @@ -204,6 +204,33 @@ namespace MareSynchronos if (string.IsNullOrEmpty(args)) { OpenUi(); + return; + } + + var splitArgs = args.ToLowerInvariant().Trim().Split(); + + if (splitArgs.Length == 0) + { + // Interpret this as toggling the UI + OpenUi(); + return; + } + + if (splitArgs[0] == "toggle") + { + var fullPause = splitArgs.Length > 1 ? splitArgs[1] switch + { + "on" => false, + "off" => true, + _ => !_configuration.FullPause, + } : !_configuration.FullPause; + + if (fullPause != _configuration.FullPause) + { + _configuration.FullPause = fullPause; + _configuration.Save(); + _ = _apiController.CreateConnections(); + } } } From 0bafb510af33a7de82137a7db76a01c13603757a Mon Sep 17 00:00:00 2001 From: Dance Mom Date: Thu, 29 Sep 2022 14:50:05 -0500 Subject: [PATCH 2/2] Slash command - remove duplicate codepath --- MareSynchronos/Plugin.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/MareSynchronos/Plugin.cs b/MareSynchronos/Plugin.cs index 86d2be9..e4e8743 100644 --- a/MareSynchronos/Plugin.cs +++ b/MareSynchronos/Plugin.cs @@ -201,15 +201,9 @@ namespace MareSynchronos private void OnCommand(string command, string args) { - if (string.IsNullOrEmpty(args)) - { - OpenUi(); - return; - } + var splitArgs = args?.ToLowerInvariant().Trim().Split(); - var splitArgs = args.ToLowerInvariant().Trim().Split(); - - if (splitArgs.Length == 0) + if (splitArgs == null || splitArgs.Length == 0) { // Interpret this as toggling the UI OpenUi();