feat: add LogoutEventAgingStep.cs

This commit is contained in:
goat 2021-08-11 00:56:16 +02:00
parent a8e00f91e7
commit 075a524c7d
No known key found for this signature in database
GPG key ID: F18F057873895461
2 changed files with 60 additions and 6 deletions

View file

@ -9,7 +9,7 @@ namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
/// </summary> /// </summary>
internal class LoginEventAgingStep : IAgingStep internal class LoginEventAgingStep : IAgingStep
{ {
private bool isSubscribed = false; private bool subscribed = false;
private bool hasPassed = false; private bool hasPassed = false;
/// <inheritdoc/> /// <inheritdoc/>
@ -20,16 +20,16 @@ namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{ {
ImGui.Text("Log in now..."); ImGui.Text("Log in now...");
if (!this.isSubscribed) if (!this.subscribed)
{ {
dalamud.ClientState.OnLogin += this.ClientStateOnOnLogin; dalamud.ClientState.OnLogin += this.ClientStateOnOnLogin;
this.isSubscribed = true; this.subscribed = true;
} }
if (this.hasPassed) if (this.hasPassed)
{ {
dalamud.ClientState.OnLogin -= this.ClientStateOnOnLogin; dalamud.ClientState.OnLogin -= this.ClientStateOnOnLogin;
this.isSubscribed = false; this.subscribed = false;
return SelfTestStepResult.Pass; return SelfTestStepResult.Pass;
} }
@ -39,10 +39,10 @@ namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
/// <inheritdoc/> /// <inheritdoc/>
public void CleanUp(Dalamud dalamud) public void CleanUp(Dalamud dalamud)
{ {
if (this.isSubscribed) if (this.subscribed)
{ {
dalamud.ClientState.OnLogin -= this.ClientStateOnOnLogin; dalamud.ClientState.OnLogin -= this.ClientStateOnOnLogin;
this.isSubscribed = false; this.subscribed = false;
} }
} }

View file

@ -0,0 +1,54 @@
using System;
using ImGuiNET;
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Test setup for the login events.
/// </summary>
internal class LogoutEventAgingStep : IAgingStep
{
private bool subscribed = false;
private bool hasPassed = false;
/// <inheritdoc/>
public string Name => "Test Log-In";
/// <inheritdoc/>
public SelfTestStepResult RunStep(Dalamud dalamud)
{
ImGui.Text("Log out now...");
if (!this.subscribed)
{
dalamud.ClientState.OnLogout += this.ClientStateOnOnLogout;
this.subscribed = true;
}
if (this.hasPassed)
{
dalamud.ClientState.OnLogout -= this.ClientStateOnOnLogout;
this.subscribed = false;
return SelfTestStepResult.Pass;
}
return SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp(Dalamud dalamud)
{
if (this.subscribed)
{
dalamud.ClientState.OnLogout -= this.ClientStateOnOnLogout;
this.subscribed = false;
}
}
private void ClientStateOnOnLogout(object sender, EventArgs e)
{
this.hasPassed = true;
}
}
}