Skip to content

Commit

Permalink
Create a cleaner "no sharex" message.
Browse files Browse the repository at this point in the history
  • Loading branch information
reedhaffner committed Sep 26, 2019
1 parent a8293b1 commit db9fd07
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 86 deletions.
10 changes: 8 additions & 2 deletions ShareX/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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);
}
}
Expand Down
50 changes: 36 additions & 14 deletions ShareX/PropertyInspector/ShareX/ScreenRecord.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,44 @@
<meta name=apple-mobile-web-app-status-bar-style content=black>
<title>ShareX Screen Record</title>
<link rel="stylesheet" href="../sdpi.css">
<style>

.hidden {
display: none;
}

</style>
</head>
<body>
<div class="sdpi-wrapper">
<div class="sdpi-wrapper missingx hidden">
<details class="message info">
<summary>ShareX could not be found. Please, close StreamDeck, launch ShareX, reopen StreamDeck, then recreate this action. If you have any problems, please create an issue on <span class="linkspan" onclick="openWebsite()">Github</span>.</summary>
</details>
</div>
<div class="sdpi-wrapper foundx">
<div class="sdpi-item" id="select_single">
<div class="sdpi-item-label">Screen Record</div>
<select class="sdpi-item-value select sdProperty" id="type" oninput="setSettings()">
<optgroup label="Video">
<option value="ScreenRecorder">Selection</option>
<option value="ScreenRecorderActiveWindow">Current Window</option>
</optgroup>
<optgroup label="GIF">
<option value="ScreenRecorderGIF">Selection</option>
<option value="ScreenRecorderGIFActiveWindow">Current Window</option>
</optgroup>
</select>
</div>
<script src="../sdtools.common.js"></script>
<div class="sdpi-item-label">Screen Record</div>
<select class="sdpi-item-value select sdProperty" id="type" oninput="setSettings()">
<optgroup label="Video">
<option value="ScreenRecorder">Selection</option>
<option value="ScreenRecorderActiveWindow">Current Window</option>
</optgroup>
<optgroup label="GIF">
<option value="ScreenRecorderGIF">Selection</option>
<option value="ScreenRecorderGIFActiveWindow">Current Window</option>
</optgroup>
</select>
</div>
<script src="../sdtools.common.js"></script>
<script>

document.addEventListener("websocketCreate", function(event) {
if (actionInfo.payload.settings["missingx"]) {
document.getElementsByClassName("missingx")[0].classList.remove("hidden");
document.getElementsByClassName("foundx")[0].classList.add("hidden");
}
});

</script>
</body>
</html>
17 changes: 16 additions & 1 deletion ShareX/PropertyInspector/ShareX/Screenshot.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
<link rel="stylesheet" href="../sdpi.css">
</head>
<body>
<div class="sdpi-wrapper">
<div class="sdpi-wrapper missingx hidden">
<details class="message info">
<summary>ShareX could not be found. Please, close StreamDeck, launch ShareX, reopen StreamDeck, then recreate this action. If you have any problems, please create an issue on <span class="linkspan" onclick="openWebsite()">Github</span>.</summary>
</details>
</div>
<div class="sdpi-wrapper foundx">
<div class="sdpi-item" id="select_single">
<div class="sdpi-item-label">Screenshot</div>
<select class="sdpi-item-value select sdProperty" id="type" oninput="setSettings()">
Expand All @@ -30,5 +35,15 @@
</select>
</div>
<script src="../sdtools.common.js"></script>
<script>

document.addEventListener("websocketCreate", function(event) {
if (actionInfo.payload.settings["missingx"]) {
document.getElementsByClassName("missingx")[0].classList.remove("hidden");
document.getElementsByClassName("foundx")[0].classList.add("hidden");
}
});

</script>
</body>
</html>
20 changes: 19 additions & 1 deletion ShareX/PropertyInspector/ShareX/Workflow.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,30 @@
<link rel="stylesheet" href="../sdpi.css">
</head>
<body>
<div class="sdpi-wrapper">
<div class="sdpi-wrapper missingx hidden">
<details class="message info">
<summary>ShareX could not be found. Please, close StreamDeck, launch ShareX, reopen StreamDeck, then recreate this action. If you have any problems, please create an issue on <span class="linkspan" onclick="openWebsite()">Github</span>.</summary>
</details>
</div>
<div class="sdpi-wrapper foundx">
<details class="message info">
<summary>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 <span class="linkspan" onclick="openWebsite()">Github</span>.</summary>
</details>
<div type="textarea" class="sdpi-item" id="required_text">
<div class="sdpi-item-label">Workflow Name</div>
<input class="sdpi-item-value sdProperty" value="" id="workflow" oninput="setSettings()">
</div>
</div>
<script src="../sdtools.common.js"></script>
<script>

document.addEventListener("websocketCreate", function(event) {
if (actionInfo.payload.settings["missingx"]) {
document.getElementsByClassName("missingx")[0].classList.remove("hidden");
document.getElementsByClassName("foundx")[0].classList.add("hidden");
}
});

</script>
</body>
</html>
70 changes: 62 additions & 8 deletions ShareX/PropertyInspector/sdtools.common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var websocket = null,
// sdtools.common.js v1.0
var websocket = null,
uuid = null,
registerEventName = null,
actionInfo = {},
Expand All @@ -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);
}

Expand Down Expand Up @@ -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];
Expand All @@ -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;
Expand All @@ -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 = {
Expand All @@ -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));
Expand Down Expand Up @@ -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);
}
}
46 changes: 26 additions & 20 deletions ShareX/ScreenRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<PluginSettings>();
JObject settingsobject = payload.Settings;
this.settings = settingsobject.ToObject<PluginSettings>();
}
}

Expand All @@ -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()
Expand All @@ -85,7 +97,9 @@ public override void ReceivedSettings(ReceivedSettingsPayload payload)
}

public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload)
{ }
{

}


#endregion
Expand All @@ -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
Expand Down
Loading

0 comments on commit db9fd07

Please sign in to comment.