Skip to content

Commit

Permalink
Added remaining Events Sent to ConfigurationManager (#64)
Browse files Browse the repository at this point in the history
* Refactored to an Proxy interface to address #47

* Added remaining EventsSent to ConfigurationManager
  • Loading branch information
csharpfritz authored Jan 28, 2019
1 parent e12bc80 commit 1797978
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 43 deletions.
Binary file added src/SamplePlugin/Fritz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 38 additions & 31 deletions src/SamplePlugin/MySamplePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,41 @@ public override async Task OnKeyUp(StreamDeckEventPayload args)
_Counter++;
await Manager.SetTitleAsync(args.context, _Counter.ToString());

if (_Counter % 10 == 0)
{
await Manager.ShowAlertAsync(args.context);
}
else if (_Counter % 15 == 0)
{
await Manager.OpenUrlAsync(args.context, "https://www.bing.com");
}
else if (_Counter % 3 == 0)
{
await Manager.ShowOkAsync(args.context);
}
}

public override async Task OnWillAppear(StreamDeckEventPayload args)
{
if(args.payload!= null && args.payload.settings != null && args.payload.settings.counter != null)
{
_Counter = args.payload.settings.counter;
}
await Manager.SetTitleAsync(args.context, _Counter.ToString());
}

public override async Task OnWillDisappear(StreamDeckEventPayload args)
{
dynamic settings = new ExpandoObject();
settings.counter = _Counter;
await Manager.SetSettingsAsync(args.context, settings);
}
}
}
if (_Counter % 10 == 0)
{
await Manager.ShowAlertAsync(args.context);
}
else if (_Counter % 15 == 0)
{
await Manager.OpenUrlAsync(args.context, "https://www.bing.com");
}
else if (_Counter % 3 == 0)
{
await Manager.ShowOkAsync(args.context);
}
else if (_Counter % 7 == 0)
{
await Manager.SetImageAsync(args.context, "Fritz.png");
}
}

public override async Task OnWillAppear(StreamDeckEventPayload args)
{
if (args.payload != null && args.payload.settings != null && args.payload.settings.counter != null)
{
_Counter = args.payload.settings.counter;
}
await Manager.SetTitleAsync(args.context, _Counter.ToString());
}

public override async Task OnWillDisappear(StreamDeckEventPayload args)
{
//dynamic settings = new ExpandoObject();
//settings.counter = _Counter;

var settings = new { counter = _Counter };

await Manager.SetSettingsAsync(args.context, settings);
}
}
}
6 changes: 6 additions & 0 deletions src/SamplePlugin/SamplePlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<RuntimeIdentifiers Condition="'$(Configuration)'=='Release' ">win-x64;osx-x64</RuntimeIdentifiers> <!-- At this time, the only platforms we are really targetting, and supported by the Stream Deck SDK are Windows and macOS -->
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<None Remove="Fritz.png" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\StreamDeckLib\StreamDeckLib.csproj" />
Expand Down Expand Up @@ -36,6 +39,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="[email protected]" />
<Content Include="Fritz.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="manifest.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
73 changes: 69 additions & 4 deletions src/StreamDeckLib/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using StreamDeckLib.Messages;
using System;
using System.Diagnostics;
using System.IO;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -159,14 +160,22 @@ public async Task SetTitleAsync(string context, string newTitle)
await _Proxy.SendStreamDeckEvent(args);
}

public async Task SetSettingsAsync(string context, dynamic value)
{
var args = new SetSettingsArgs()
public async Task SetImageAsync(string context, string imageLocation) {

var imgString = Convert.ToBase64String(File.ReadAllBytes(imageLocation), Base64FormattingOptions.None);

var args = new SetImageArgs
{
context = context,
payload = value
payload = new SetImageArgs.Payload
{
TargetType = SetTitleArgs.TargetType.HardwareAndSoftware,
image = $"data:image/{new FileInfo(imageLocation).Extension.ToLowerInvariant().Substring(1)};base64, {imgString}"
}
};

await _Proxy.SendStreamDeckEvent(args);

}

public async Task ShowAlertAsync(string context)
Expand All @@ -187,6 +196,62 @@ public async Task ShowOkAsync(string context)
await _Proxy.SendStreamDeckEvent(args);
}

public async Task SetSettingsAsync(string context, dynamic value)
{
var args = new SetSettingsArgs()
{
context = context,
payload = value
};
await _Proxy.SendStreamDeckEvent(args);
}

public async Task SetStateAsync(string context, int state)
{

var args = new SetStateArgs
{
context = context,
payload = new SetStateArgs.Payload
{
state = state
}
};

await _Proxy.SendStreamDeckEvent(args);


}

public async Task SendToPropertyInspectorAsync(string context, dynamic payload) {

var args = new SendToPropertyInspectorArgs
{
action = _Uuid,
context = context,
payload = payload
};

await _Proxy.SendStreamDeckEvent(args);

}

public async Task SwitchToProfileAsync(string context, string device, string profileName) {

var args = new SwitchToProfileArgs
{
context = context,
device = device,
payload = new SwitchToProfileArgs.Payload
{
profile = profileName
}
};

await _Proxy.SendStreamDeckEvent(args);

}

public async Task OpenUrlAsync(string context, string url)
{
var args = new OpenUrlArgs()
Expand Down
14 changes: 14 additions & 0 deletions src/StreamDeckLib/Messages/SendToPropertyInspectorArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace StreamDeckLib.Messages
{
public class SendToPropertyInspectorArgs : BaseStreamDeckArgs
{

public override string Event => "sendToPropertyInspector";

public string action { get; set; }

public dynamic payload { get; set; }

}

}
24 changes: 24 additions & 0 deletions src/StreamDeckLib/Messages/SetImageArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Newtonsoft.Json;
using static StreamDeckLib.Messages.SetTitleArgs;

namespace StreamDeckLib.Messages
{
public class SetImageArgs : BaseStreamDeckArgs
{
public override string Event { get => "setImage"; }

public Payload payload { get; set; }
public class Payload
{

public string image { get; set; }

public int target { get { return (int)TargetType; } }

[JsonIgnore]
public TargetType TargetType { get; set; }

}

}
}
11 changes: 6 additions & 5 deletions src/StreamDeckLib/Messages/SetSettingsArgs.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace StreamDeckLib.Messages
{
public class SetSettingsArgs : BaseStreamDeckArgs
{
public override string Event => "setSettings";
public dynamic payload { get; set; }
}
public class SetSettingsArgs : BaseStreamDeckArgs
{
public override string Event => "setSettings";
public dynamic payload { get; set; }
}

}
14 changes: 14 additions & 0 deletions src/StreamDeckLib/Messages/SetStateArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace StreamDeckLib.Messages
{
public class SetStateArgs : BaseStreamDeckArgs
{
public override string Event => "setState";
public Payload payload { get; set; }
public class Payload
{
public int state{ get; set; }
}

}

}
6 changes: 3 additions & 3 deletions src/StreamDeckLib/Messages/SetTitleArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ namespace StreamDeckLib.Messages
{
public class SetTitleArgs : BaseStreamDeckArgs
{
public override string Event => "setTitle";
public override string Event => "setTitle";
public Payload payload { get; set; }
public class Payload
public class Payload
{
public string title { get; set; }
public int target { get { return (int)TargetType; } }
[JsonIgnore]
public TargetType TargetType { get; set; }
}

public enum TargetType
public enum TargetType
{
HardwareAndSoftware = 0,
Hardware = 1,
Expand Down
19 changes: 19 additions & 0 deletions src/StreamDeckLib/Messages/SwitchToProfileArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;

namespace StreamDeckLib.Messages
{
public class SwitchToProfileArgs : BaseStreamDeckArgs
{
public override string Event => "switchToProfile";

public string device { get; set; }

public Payload payload { get; set; }

public class Payload
{
public string profile { get; set; }
}

}
}

0 comments on commit 1797978

Please sign in to comment.