Skip to content

Commit

Permalink
Fix Stream Deck plugin shutdown to be more graceful
Browse files Browse the repository at this point in the history
Fix build break due to logger.
  • Loading branch information
TyrenDe committed Mar 8, 2019
1 parent 22d72cf commit 00540b4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
53 changes: 30 additions & 23 deletions MixItUp.StreamDeckPlugin/MixItUpPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,40 @@ static MixItUpPlugin()

public async Task RunAsync(int port, string uuid, string registerEvent)
{
this.connection = new StreamDeckConnection(port, uuid, registerEvent);

this.connection.OnConnected += Connection_OnConnected;
this.connection.OnDisconnected += Connection_OnDisconnected;
this.connection.OnApplicationDidLaunch += Connection_OnApplicationDidLaunch;
this.connection.OnApplicationDidTerminate += Connection_OnApplicationDidTerminate;
this.connection.OnKeyDown += Connection_OnKeyDown;
this.connection.OnWillAppear += Connection_OnWillAppear;
this.connection.OnWillDisappear += Connection_OnWillDisappear;
this.connection.OnSendToPlugin += Connection_OnSendToPlugin;
this.connection.OnTitleParametersDidChange += Connection_OnTitleParametersDidChange;

// Start the connection
connection.Run();

// Wait for up to 10 seconds to connect, if it fails, the app will exit
if (this.connectEvent.WaitOne(TimeSpan.FromSeconds(10)))
{
// We connected, loop every second until we disconnect
while (!this.disconnectEvent.WaitOne(TimeSpan.FromMilliseconds(1000)))
try
{
this.connection = new StreamDeckConnection(port, uuid, registerEvent);

this.connection.OnConnected += Connection_OnConnected;
this.connection.OnDisconnected += Connection_OnDisconnected;
this.connection.OnApplicationDidLaunch += Connection_OnApplicationDidLaunch;
this.connection.OnApplicationDidTerminate += Connection_OnApplicationDidTerminate;
this.connection.OnKeyDown += Connection_OnKeyDown;
this.connection.OnWillAppear += Connection_OnWillAppear;
this.connection.OnWillDisappear += Connection_OnWillDisappear;
this.connection.OnSendToPlugin += Connection_OnSendToPlugin;
this.connection.OnTitleParametersDidChange += Connection_OnTitleParametersDidChange;

// Start the connection
connection.Run();

// Wait for up to 10 seconds to connect, if it fails, the app will exit
if (this.connectEvent.WaitOne(TimeSpan.FromSeconds(10)))
{
// We connected, loop every second until we disconnect
while (!this.disconnectEvent.WaitOne(TimeSpan.FromMilliseconds(1000)))
{
await RunTickAsync();
}
}
else
{
await RunTickAsync();
Console.WriteLine("Mix It Up Plugin failed to connect to Stream Deck");
}
}
else
catch (Exception ex)
{
Console.WriteLine("Mix It Up Plugin failed to connect to Stream Deck");
Console.WriteLine($"Mix It Up Plugin crashed: {ex.ToString()}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion MixItUp.StreamDeckPlugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"Name": "Mix It Up",
"Icon": "Images/categoryIcon",
"URL": "https://mixitupapp.com/",
"Version": "4.1.0",
"Version": "4.1.1",
"CodePath": "MixItUp.StreamDeckPlugin.exe",
"Category": "Mix It Up",
"CategoryIcon": "Images/categoryIcon",
Expand Down
2 changes: 1 addition & 1 deletion MixItUp.WPF/Controls/MainControls/GiveawayControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ private async void GlobalEvents_OnChatCommandMessageReceived(object sender, Chat
}
catch (Exception ex)
{
Logger.Log(ex);
MixItUp.Base.Util.Logger.Log(ex);
}
}

Expand Down

0 comments on commit 00540b4

Please sign in to comment.