diff --git a/FakeDeckUI/FakeDeck/ButtonType/ProcessMacro.cs b/FakeDeckUI/FakeDeck/ButtonType/ProcessMacro.cs new file mode 100644 index 0000000..0dbc210 --- /dev/null +++ b/FakeDeckUI/FakeDeck/ButtonType/ProcessMacro.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +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 (!File.ReadAllText("./configuration.yaml").Contains(process)) + { + Debug.WriteLine("not known process"); + return false; + } + + if (!File.ReadAllText("./configuration.yaml").Contains(arguments)) + { + Debug.WriteLine("not known arguments"); + return false; + } + + Process notePad = new Process(); + notePad.StartInfo.FileName = process; + notePad.StartInfo.Arguments = arguments; + notePad.Start(); + return true; + } + } +} diff --git a/FakeDeckUI/FakeDeck/Class/AutoUpdateHelper.cs b/FakeDeckUI/FakeDeck/Class/AutoUpdateHelper.cs index 5470aaa..996abea 100644 --- a/FakeDeckUI/FakeDeck/Class/AutoUpdateHelper.cs +++ b/FakeDeckUI/FakeDeck/Class/AutoUpdateHelper.cs @@ -20,6 +20,7 @@ namespace FakeDeck.Class AutoUpdater.ParseUpdateInfoEvent += AutoUpdaterOnParseUpdateInfoEvent; AutoUpdater.Synchronous = true; AutoUpdater.ShowRemindLaterButton = false; + AutoUpdater.ClearAppDirectory = false; //AutoUpdater.ReportErrors = Debugger.IsAttached; AutoUpdater.HttpUserAgent = ("FakeDeck-v" + Assembly.GetExecutingAssembly().GetName().Version); AutoUpdater.Start("https://api.github.com/repos/GamerClassN7/FakeDeck/releases/latest"); 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 269264b..aa57778 100644 --- a/FakeDeckUI/FakeDeck/configuration.yaml +++ b/FakeDeckUI/FakeDeck/configuration.yaml @@ -156,6 +156,24 @@ 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: arguments + value: "/C ping google.com -t" + - name: image + value: "https://winaero.com/blog/wp-content/uploads/2019/06/WIndows-Terminal-icon.png" + - button: mute function: MediaMacro parameters: diff --git a/README.md b/README.md index 3beae3a..5459352 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,16 @@ Just add desired macros to `configuration.yaml` and start the application, tahn - name: Key value: spacer ``` +### Process Macro +```yaml +- button: cmd + function: ProcessMacro + parameters: + - name: process + value: "cmd.exe" + - name: arguments #Optional Proces Arguments + value: "/C ipconfig" +``` ### Comon Macro Parameters ```yaml ...