Skip to content

Commit

Permalink
Addressed logger and memory leak issues FritzAndFriends#73 FritzAndFr…
Browse files Browse the repository at this point in the history
  • Loading branch information
csharpfritz committed Feb 15, 2019
1 parent 1c9c730 commit d4b2f26
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/SamplePlugin/MySampleAction.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.Extensions.Logging;
using Serilog.Core;
using StreamDeckLib;
using StreamDeckLib.Messages;
using System.Threading.Tasks;
Expand Down Expand Up @@ -27,6 +29,12 @@ internal class MySampleAction : BaseStreamDeckAction

public override async Task OnKeyUp(StreamDeckEventPayload args)
{

// Cheer 342 cpayette 15/2/19
// Cheer 100 devlead 15/2/19

Logger.LogTrace($"Button pressed: {args}");

_Counter++;
await Manager.SetTitleAsync(args.context, _Counter.ToString());

Expand Down
8 changes: 6 additions & 2 deletions src/SamplePlugin/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ namespace SamplePlugin

class Program
{

// Cheer 200 careypayette February 14, 2019
// Cheer 100 roberttables February 14, 2019
// Cheer 100 careypayette February 15, 2019
// Cheer 100 devlead 15/2/2019

static ILoggerFactory GetLoggerFactory()
{
var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Expand Down Expand Up @@ -88,8 +94,6 @@ await ConnectionManager.Initialize(args, loggerFactory)
}
#endif

Console.WriteLine("I did a thing...");

}
}

Expand Down
1 change: 1 addition & 0 deletions src/SamplePlugin/SamplePlugin.cmd
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
cd %appdata%\Elgato\StreamDeck\Plugins\com.csharpfritz.samplePlugin.sdPlugin
SamplePlugin.exe -break %*
3 changes: 3 additions & 0 deletions src/StreamDeckLib/BaseStreamDeckAction.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.Extensions.Logging;
using StreamDeckLib.Messages;
using System;
using System.Threading.Tasks;
Expand Down Expand Up @@ -32,6 +33,8 @@ public abstract class BaseStreamDeckAction
/// <value>The registration key.</value>
protected internal string RegistrationKey => UUID;

public ILogger Logger { get; internal set; }

public virtual Task OnKeyDown(StreamDeckEventPayload args) => Task.CompletedTask;

public virtual Task OnKeyUp(StreamDeckEventPayload args) => Task.CompletedTask;
Expand Down
3 changes: 3 additions & 0 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.IO;
using System.Linq;
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -151,6 +152,8 @@ private async Task Run()
continue;
}

if (_ActionEventsIgnore.Contains(msg.Event)) { continue; }

// Make sure we have a registered BaseStreamDeckAction instance registered for the received action (UUID)
if (!_ActionsDictionary.ContainsKey(msg.action))
{
Expand Down
4 changes: 4 additions & 0 deletions src/StreamDeckLib/ConnectionManager_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ partial class ConnectionManager

private static ConnectionManager RegisterActionInternal(ConnectionManager manager, BaseStreamDeckAction action)
{

// Cheer 100 svavablount 15/2/19

ValidateActionForRegistration(action);

action.Manager = manager;
action.Logger = _LoggerFactory.CreateLogger(action.UUID);

_ActionsDictionary.Add(action.RegistrationKey, action);

Expand Down
4 changes: 4 additions & 0 deletions src/StreamDeckLib/ConnectionManager_Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ private static readonly Dictionary<string, Func<BaseStreamDeckAction, StreamDeck
["applicationDidTerminate"] = (action, args) => action.OnApplicationDidTerminate(args),
};

private static readonly string[] _ActionEventsIgnore = new[] {
"deviceDidConnect", "deviceDidDisconnect", "applicationDidLaunch", "applicationDidTerminate"
};

private static readonly Dictionary<string, Func<BaseStreamDeckAction, PropertyInspectorEventPayload, Task>> _PropertyInspectorActionDictionary
= new Dictionary<string, Func<BaseStreamDeckAction, PropertyInspectorEventPayload, Task>>()
{
Expand Down
25 changes: 21 additions & 4 deletions src/StreamDeckToolkit.sln
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.168
# Visual Studio Version 16
VisualStudioVersion = 16.0.28606.126
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StreamDeckLib", "StreamDeckLib\StreamDeckLib.csproj", "{19F24D43-79DB-47B6-AEDA-BAEA3B2F1962}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplePlugin", "SamplePlugin\SamplePlugin.csproj", "{7FCB0FEF-FC38-4187-858C-425FB0664F4E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SamplePlugin", "SamplePlugin\SamplePlugin.csproj", "{7FCB0FEF-FC38-4187-858C-425FB0664F4E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{87F0DB03-6058-40D9-9510-D516FDA578AE}"
ProjectSection(SolutionItems) = preProject
..\.editorconfig = ..\.editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StreamDeckLib.Test", "StreamDeckLib.Test\StreamDeckLib.Test.csproj", "{CAD3C79B-E603-4356-B5BD-5B2E57DFD8BE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StreamDeckLib.Test", "StreamDeckLib.Test\StreamDeckLib.Test.csproj", "{CAD3C79B-E603-4356-B5BD-5B2E57DFD8BE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{A337DDA4-B15C-43B9-AB51-04267D151BB0}"
ProjectSection(SolutionItems) = preProject
..\scripts\install.ps1 = ..\scripts\install.ps1
..\scripts\install.sh = ..\scripts\install.sh
..\scripts\uninstall.ps1 = ..\scripts\uninstall.ps1
..\scripts\uninstall.sh = ..\scripts\uninstall.sh
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Registration", "Registration", "{403D021A-9770-41ED-8554-34FEE375BADA}"
ProjectSection(SolutionItems) = preProject
..\scripts\registration\RegisterPluginAndStartStreamDeck.ps1 = ..\scripts\registration\RegisterPluginAndStartStreamDeck.ps1
..\scripts\registration\RegisterPluginAndStartStreamDeck.sh = ..\scripts\registration\RegisterPluginAndStartStreamDeck.sh
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -36,6 +50,9 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{403D021A-9770-41ED-8554-34FEE375BADA} = {A337DDA4-B15C-43B9-AB51-04267D151BB0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C5036C4A-EAB6-4A37-9D02-1E6D5E77D257}
EndGlobalSection
Expand Down

0 comments on commit d4b2f26

Please sign in to comment.