From 7fb6b4c89c27d59b2d90e79ba94c52b0e159d005 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Tue, 17 Sep 2024 06:17:43 -0700 Subject: [PATCH] Process Starting --- .../FakeDeck/ButtonType/ProcessMacro.cs | 47 +++++++++++++++++++ FakeDeckUI/FakeDeck/Class/FakeDeckMain.cs | 34 ++++++++------ FakeDeckUI/FakeDeck/configuration.yaml | 16 +++++++ 3 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 FakeDeckUI/FakeDeck/ButtonType/ProcessMacro.cs diff --git a/FakeDeckUI/FakeDeck/ButtonType/ProcessMacro.cs b/FakeDeckUI/FakeDeck/ButtonType/ProcessMacro.cs new file mode 100644 index 0000000..9f2ba34 --- /dev/null +++ b/FakeDeckUI/FakeDeck/ButtonType/ProcessMacro.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; +using System.Windows; +using static System.Text.Json.JsonElement; + +namespace FakeDeck.ButtonType +{ + class ProcessMacro : Button + { + public static string getButton(string process, string arguments = "", string? icon = null, string? image = null) + { + Dictionary parameters = new Dictionary() { { "process", process } }; + if (!string.IsNullOrEmpty(arguments)) + { + parameters.Add("arguments", arguments); + } + + if (!string.IsNullOrEmpty(icon) || !string.IsNullOrEmpty(image)) + { + process = null; + } + + return getButtonHTML(icon, image, process, "button\\ProcessMacro", null, parameters); + } + + public static bool invokeAction(string process, string arguments = "") + { + if (!System.IO.File.ReadAllText("./configuration.yaml").Contains(process)) + { + Debug.WriteLine("not known process"); + return true; + } + + Process notePad = new Process(); + notePad.StartInfo.FileName = process; + notePad.StartInfo.Arguments = arguments; + notePad.Start(); + return true; + } + } +} diff --git a/FakeDeckUI/FakeDeck/Class/FakeDeckMain.cs b/FakeDeckUI/FakeDeck/Class/FakeDeckMain.cs index 58c050c..2f17717 100644 --- a/FakeDeckUI/FakeDeck/Class/FakeDeckMain.cs +++ b/FakeDeckUI/FakeDeck/Class/FakeDeckMain.cs @@ -14,19 +14,19 @@ namespace FakeDeck.Class { private static string cachePath = "./cache/"; public static string pageHeader = - "" + - "" + - " " + - " HttpListener Example" + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - "
"; + "" + + "" + + " " + + " HttpListener Example" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "
"; public static string pageFooter = "
" + " " + @@ -161,7 +161,13 @@ namespace FakeDeck.Class string pageContent = ""; foreach (JsonElement button in selectedPage.GetProperty("buttons").EnumerateArray()) { - pageContent += AbstractionHelper.getButtonVisual(button); + try + { + pageContent += AbstractionHelper.getButtonVisual(button); + } + catch (Exception ex) { + + } } if (Directory.Exists(cachePath)) diff --git a/FakeDeckUI/FakeDeck/configuration.yaml b/FakeDeckUI/FakeDeck/configuration.yaml index cb23c76..70aeca4 100644 --- a/FakeDeckUI/FakeDeck/configuration.yaml +++ b/FakeDeckUI/FakeDeck/configuration.yaml @@ -108,6 +108,22 @@ pages: - page: media buttons: + - button: notepad + function: ProcessMacro + parameters: + - name: process + value: "notepad.exe" + - name: image + value: "https://www.club386.com/wp-content/uploads/2021/12/notepad-icon-696x632.jpg" + + - button: cmd + function: ProcessMacro + parameters: + - name: process + value: "cmd.exe" + - name: image + value: "https://winaero.com/blog/wp-content/uploads/2019/06/WIndows-Terminal-icon.png" + - button: mute function: MediaMacro parameters: