diff --git a/ShareX/Program.cs b/ShareX/Program.cs index a5a956a..f7a4e43 100644 --- a/ShareX/Program.cs +++ b/ShareX/Program.cs @@ -34,6 +34,8 @@ static class Globals // global int public static string xpath; + public static bool missingx { get; internal set; } + public static string FindShareX() { foreach (var p in Process.GetProcesses()) @@ -60,31 +62,35 @@ static void Main(string[] args) if (File.Exists("C:\\Program Files\\ShareX\\sharex.exe")) { Globals.xpath = "C:\\Program Files\\ShareX\\sharex.exe"; + Globals.missingx = false; } else if (File.Exists("C:\\Program Files (x86)\\ShareX\\sharex.exe")) { Globals.xpath = "C:\\Program Files (x86)\\ShareX\\sharex.exe"; + Globals.missingx = false; } else if (File.Exists("C:\\Program Files (x86)\\Steam\\steamapps\\common\\ShareX\\sharex.exe")) { Globals.xpath = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\ShareX\\sharex.exe"; + Globals.missingx = false; } // Checks PATH to see if ShareX exists else if (File.Exists("sharex")) { Globals.xpath = "sharex"; + Globals.missingx = false; } // Checks currently running process for ShareX else if (Globals.FindShareX() != "") { Globals.xpath = Globals.FindShareX(); + Globals.missingx = false; } // Alert user that ShareX was unable to be found. else { - MessageBox.Show("Unable to find ShareX. Please try running ShareX first, then starting StreamDeck.", "Error in ShareX4StreamDeck", MessageBoxButtons.OK, MessageBoxIcon.Error); + Globals.missingx = true; } - SDWrapper.Run(args); } } diff --git a/ShareX/PropertyInspector/ShareX/ScreenRecord.html b/ShareX/PropertyInspector/ShareX/ScreenRecord.html index 3bd1200..ab08407 100644 --- a/ShareX/PropertyInspector/ShareX/ScreenRecord.html +++ b/ShareX/PropertyInspector/ShareX/ScreenRecord.html @@ -7,22 +7,44 @@ ShareX Screen Record + -
+ +
-
Screen Record
- -
- +
Screen Record
+ +
+ + diff --git a/ShareX/PropertyInspector/ShareX/Screenshot.html b/ShareX/PropertyInspector/ShareX/Screenshot.html index 4580f0e..188a15b 100644 --- a/ShareX/PropertyInspector/ShareX/Screenshot.html +++ b/ShareX/PropertyInspector/ShareX/Screenshot.html @@ -9,7 +9,12 @@ -
+ +
Screenshot
+ diff --git a/ShareX/PropertyInspector/ShareX/Workflow.html b/ShareX/PropertyInspector/ShareX/Workflow.html index bbd09e9..be4b460 100644 --- a/ShareX/PropertyInspector/ShareX/Workflow.html +++ b/ShareX/PropertyInspector/ShareX/Workflow.html @@ -9,12 +9,30 @@ -
+ +
+
+ If the button has a warning triangle, ShareX could not be found. Please, close StreamDeck, launch ShareX, then reopen StreamDeck. If you have any problems, please create an issue on Github. +
Workflow Name
+ diff --git a/ShareX/PropertyInspector/sdtools.common.js b/ShareX/PropertyInspector/sdtools.common.js index 450d8e9..1d80e0f 100644 --- a/ShareX/PropertyInspector/sdtools.common.js +++ b/ShareX/PropertyInspector/sdtools.common.js @@ -1,4 +1,5 @@ -var websocket = null, +// sdtools.common.js v1.0 +var websocket = null, uuid = null, registerEventName = null, actionInfo = {}, @@ -9,15 +10,20 @@ function connectElgatoStreamDeckSocket(inPort, inUUID, inRegisterEvent, inInfo, inActionInfo) { uuid = inUUID; registerEventName = inRegisterEvent; - console.log(uuid, inActionInfo); + console.log(inUUID, inActionInfo); actionInfo = JSON.parse(inActionInfo); // cache the info inInfo = JSON.parse(inInfo); - websocket = new WebSocket('ws://localhost:' + inPort); + websocket = new WebSocket('ws://127.0.0.1:' + inPort); addDynamicStyles(inInfo.colors); websocket.onopen = websocketOnOpen; websocket.onmessage = websocketOnMessage; + + // Allow others to get notified that the websocket is created + var event = new Event('websocketCreate'); + document.dispatchEvent(event); + loadConfiguration(actionInfo.payload.settings); } @@ -59,7 +65,27 @@ function loadConfiguration(payload) { elem.checked = payload[key]; } else if (elem.classList.contains("sdFile")) { // File - + var elemFile = document.getElementById(elem.id + "Filename"); + elemFile.innerText = payload[key]; + if (!elemFile.innerText) { + elemFile.innerText = "No file..."; + } + } + else if (elem.classList.contains("sdList")) { // Dynamic dropdown + var textProperty = elem.getAttribute("sdListTextProperty"); + var valueProperty = elem.getAttribute("sdListValueProperty"); + var valueField = elem.getAttribute("sdValueField"); + + var items = payload[key]; + elem.options.length = 0; + + for (var idx = 0; idx < items.length; idx++) { + var opt = document.createElement('option'); + opt.value = items[idx][valueProperty]; + opt.text = items[idx][textProperty]; + elem.appendChild(opt); + } + elem.value = payload[valueField]; } else { // Normal value elem.value = payload[key]; @@ -82,7 +108,20 @@ function setSettings() { payload[key] = elem.checked; } else if (elem.classList.contains("sdFile")) { // File - + var elemFile = document.getElementById(elem.id + "Filename"); + payload[key] = elem.value; + if (!elem.value) { + // Fetch innerText if file is empty (happens when we lose and regain focus to this key) + payload[key] = elemFile.innerText; + } + else { + // Set value on initial file selection + elemFile.innerText = elem.value; + } + } + else if (elem.classList.contains("sdList")) { // Dynamic dropdown + var valueField = elem.getAttribute("sdValueField"); + payload[valueField] = elem.value; } else { // Normal value payload[key] = elem.value; @@ -100,10 +139,25 @@ function setSettingsToPlugin(payload) { 'payload': payload }; websocket.send(JSON.stringify(json)); + var event = new Event('settingsUpdated'); + document.dispatchEvent(event); } } -// our method to pass values to the plugin +// Sends an entire payload to the sendToPlugin method +function sendPayloadToPlugin(payload) { + if (websocket && (websocket.readyState === 1)) { + const json = { + 'action': actionInfo['action'], + 'event': 'sendToPlugin', + 'context': uuid, + 'payload': payload + }; + websocket.send(JSON.stringify(json)); + } +} + +// Sends one value to the sendToPlugin method function sendValueToPlugin(value, param) { if (websocket && (websocket.readyState === 1)) { const json = { @@ -123,7 +177,7 @@ function openWebsite() { const json = { 'event': 'openUrl', 'payload': { - 'url': 'https://BarRaider.github.io' + 'url': 'https://github.com/reedhaffner/ShareX4StreamDeck' } }; websocket.send(JSON.stringify(json)); @@ -225,4 +279,4 @@ function fadeColor(col, amt) { const g = min(255, max((num & 0x0000FF) + amt, 0)); const b = min(255, max(((num >> 8) & 0x00FF) + amt, 0)); return '#' + (g | (b << 8) | (r << 16)).toString(16).padStart(6, 0); -} +} \ No newline at end of file diff --git a/ShareX/ScreenRecord.cs b/ShareX/ScreenRecord.cs index 5299c88..0ba0afd 100644 --- a/ShareX/ScreenRecord.cs +++ b/ShareX/ScreenRecord.cs @@ -20,13 +20,16 @@ private class PluginSettings public static PluginSettings CreateDefaultSettings() { PluginSettings instance = new PluginSettings(); - instance.Type = String.Empty; ; + instance.Type = "ScreenRecorder"; + instance.MissingX = Globals.missingx; return instance; } [JsonProperty(PropertyName = "type")] public string Type { get; set; } + [JsonProperty(PropertyName = "missingx")] + public bool MissingX { get; set; } } #region Private members @@ -45,11 +48,13 @@ public ScreenRecord(SDConnection connection, InitialPayload payload) : base(conn if (payload.Settings == null || payload.Settings.Count == 0) { this.settings = PluginSettings.CreateDefaultSettings(); - Connection.SetSettingsAsync(JObject.FromObject(settings)); + JObject settingsobject = JObject.FromObject(settings); + Connection.SetSettingsAsync(settingsobject); } else { - this.settings = payload.Settings.ToObject(); + JObject settingsobject = payload.Settings; + this.settings = settingsobject.ToObject(); } } @@ -70,6 +75,13 @@ public override void KeyReleased(KeyPayload payload) public override void OnTick() { + if (Globals.missingx) + { + settings.MissingX = true; + } else + { + settings.MissingX = false; + } } public override void Dispose() @@ -85,7 +97,9 @@ public override void ReceivedSettings(ReceivedSettingsPayload payload) } public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload) - { } + { + + } #endregion @@ -96,22 +110,14 @@ private async void XScreenRecord() { await Task.Run(() => { - if (settings.Type == String.Empty) - { - Connection.ShowAlert(); - MessageBox.Show("A ScreenRecord type is required! Please check the Stream Deck application."); - } - else - { - System.Diagnostics.Process process = new System.Diagnostics.Process(); - System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); - startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; - startInfo.FileName = Globals.xpath; - startInfo.Arguments = "-" + settings.Type; - process.StartInfo = startInfo; - process.Start(); - Connection.ShowOk(); - } + System.Diagnostics.Process process = new System.Diagnostics.Process(); + System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); + startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; + startInfo.FileName = Globals.xpath; + startInfo.Arguments = "-" + settings.Type; + process.StartInfo = startInfo; + process.Start(); + Connection.ShowOk(); }); } #endregion diff --git a/ShareX/Screenshot.cs b/ShareX/Screenshot.cs index d83289a..6b107ff 100644 --- a/ShareX/Screenshot.cs +++ b/ShareX/Screenshot.cs @@ -20,13 +20,16 @@ private class PluginSettings public static PluginSettings CreateDefaultSettings() { PluginSettings instance = new PluginSettings(); - instance.Type = String.Empty; ; + instance.Type = "ActiveWindow"; + instance.MissingX = Globals.missingx; return instance; } [JsonProperty(PropertyName = "type")] public string Type { get; set; } + [JsonProperty(PropertyName = "missingx")] + public bool MissingX { get; set; } } #region Private members @@ -45,11 +48,14 @@ public Screenshot(SDConnection connection, InitialPayload payload) : base(connec if (payload.Settings == null || payload.Settings.Count == 0) { this.settings = PluginSettings.CreateDefaultSettings(); - Connection.SetSettingsAsync(JObject.FromObject(settings)); + JObject settingsobject = JObject.FromObject(settings); + Connection.SetSettingsAsync(settingsobject); } else { - this.settings = payload.Settings.ToObject(); + JObject settingsobject = payload.Settings; + if (Globals.missingx) + this.settings = settingsobject.ToObject(); } } @@ -70,6 +76,14 @@ public override void KeyReleased(KeyPayload payload) public override void OnTick() { + if (Globals.missingx) + { + settings.MissingX = true; + } + else + { + settings.MissingX = false; + } } public override void Dispose() @@ -96,22 +110,14 @@ private async void XScreenshot() { await Task.Run(() => { - if (settings.Type == String.Empty) - { - Connection.ShowAlert(); - MessageBox.Show("A Screenshot type is required! Please check the Stream Deck application."); - } - else - { - System.Diagnostics.Process process = new System.Diagnostics.Process(); - System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); - startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; - startInfo.FileName = Globals.xpath; - startInfo.Arguments = "-" + settings.Type; - process.StartInfo = startInfo; - process.Start(); - Connection.ShowOk(); - } + System.Diagnostics.Process process = new System.Diagnostics.Process(); + System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); + startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; + startInfo.FileName = Globals.xpath; + startInfo.Arguments = "-" + settings.Type; + process.StartInfo = startInfo; + process.Start(); + Connection.ShowOk(); }); } #endregion diff --git a/ShareX/Workflow.cs b/ShareX/Workflow.cs index c8671fb..1ca2769 100644 --- a/ShareX/Workflow.cs +++ b/ShareX/Workflow.cs @@ -20,13 +20,16 @@ private class PluginSettings public static PluginSettings CreateDefaultSettings() { PluginSettings instance = new PluginSettings(); - instance.WorkflowName = String.Empty; ; + instance.WorkflowName = String.Empty; + instance.MissingX = Globals.missingx; return instance; } [JsonProperty(PropertyName = "workflow")] public string WorkflowName { get; set; } + [JsonProperty(PropertyName = "missingx")] + public bool MissingX { get; set; } } #region Private members @@ -45,11 +48,13 @@ public Workflow(SDConnection connection, InitialPayload payload) : base(connecti if (payload.Settings == null || payload.Settings.Count == 0) { this.settings = PluginSettings.CreateDefaultSettings(); - Connection.SetSettingsAsync(JObject.FromObject(settings)); + JObject settingsobject = JObject.FromObject(settings); + Connection.SetSettingsAsync(settingsobject); } else { - this.settings = payload.Settings.ToObject(); + JObject settingsobject = payload.Settings; + this.settings = settingsobject.ToObject(); } } @@ -70,6 +75,14 @@ public override void KeyReleased(KeyPayload payload) public override void OnTick() { + if (Globals.missingx) + { + settings.MissingX = true; + } + else + { + settings.MissingX = false; + } } public override void Dispose() @@ -85,7 +98,8 @@ public override void ReceivedSettings(ReceivedSettingsPayload payload) } public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload) - { } + { + } #endregion @@ -96,22 +110,14 @@ private async void XWorkflow() { await Task.Run(() => { - if (settings.WorkflowName == String.Empty) - { - Connection.ShowAlert(); - MessageBox.Show("You did not name a workflow!"); - } - else - { - System.Diagnostics.Process process = new System.Diagnostics.Process(); - System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); - startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; - startInfo.FileName = Globals.xpath; - startInfo.Arguments = "-workflow \"" + settings.WorkflowName + "\""; - process.StartInfo = startInfo; - process.Start(); - Connection.ShowOk(); - } + System.Diagnostics.Process process = new System.Diagnostics.Process(); + System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); + startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; + startInfo.FileName = Globals.xpath; + startInfo.Arguments = "-workflow \"" + settings.WorkflowName + "\""; + process.StartInfo = startInfo; + process.Start(); + Connection.ShowOk(); }); } #endregion diff --git a/ShareX/manifest.json b/ShareX/manifest.json index 11fe376..e86e8de 100644 --- a/ShareX/manifest.json +++ b/ShareX/manifest.json @@ -51,7 +51,7 @@ "Name": "ShareX", "Icon": "Images/pluginIcon", "URL": "https://reedhaffner.com/", - "Version": "1.0", + "Version": "1.2", "CodePath": "com.reedhaffner.ShareX", "Category": "ShareX", "CategoryIcon": "Images/categoryIcon",