Skip to content

Commit

Permalink
Better status system
Browse files Browse the repository at this point in the history
It should be more obvious now when an error is spammed multiple times in the status bar.

Non-error status messages also disappear after a few seconds now.
  • Loading branch information
Sparronator9999 committed Oct 27, 2024
1 parent 4ee0764 commit cb0e13b
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 59 deletions.
31 changes: 19 additions & 12 deletions YAMDCC.GUI/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 75 additions & 17 deletions YAMDCC.GUI/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace YAMDCC.GUI
internal sealed partial class MainWindow : Form
{
#region Fields
private readonly Status AppStatus = new();

/// <summary>
/// The path where program data is stored.
/// </summary>
Expand Down Expand Up @@ -224,10 +226,7 @@ private void IPC_MessageReceived(object sender, PipeMessageEventArgs<ServiceResp
{
case Response.Nothing:
{
lblStatus.Invoke(new Action(delegate
{
lblStatus.Text = $"WARN: Received an empty response from service";
}));
UpdateStatus(StatusCode.ServiceResponseEmpty);
break;
}
case Response.Success:
Expand All @@ -239,10 +238,7 @@ private void IPC_MessageReceived(object sender, PipeMessageEventArgs<ServiceResp
{
if (int.TryParse(args[0], out int value))
{
lblStatus.Invoke(new Action(delegate
{
lblStatus.Text = $"ERROR: a {(Command)value} service command failed to run.";
}));
UpdateStatus(StatusCode.ServiceCommandFail, value);
}
break;
}
Expand Down Expand Up @@ -303,18 +299,15 @@ private void HandleSuccessResponse(string[] args)
{
case Command.ApplyConfig:
btnApply.Enabled = true;
lblStatus.Text = "Config applied successfully!";
UpdateStatus(StatusCode.ConfApplySuccess);
if (Config.KeyLightConf is not null)
{
ServiceCommand command = new(Command.GetKeyLightBright, "");
IPCClient.PushMessage(command);
}
break;
case Command.FullBlast:
lblStatus.Invoke(new Action(delegate
{
lblStatus.Text = "Full blast toggled successfully!";
}));
UpdateStatus(StatusCode.FullBlastToggleSuccess);
break;
}
}
Expand Down Expand Up @@ -717,7 +710,7 @@ private void UpdateFanMon(int value, int i)

private void LoadConf(string confPath)
{
lblStatus.Text = "Loading config, please wait...";
UpdateStatus(StatusCode.ConfLoading);

try
{
Expand All @@ -728,7 +721,7 @@ private void LoadConf(string confPath)
{
if (ex is InvalidConfigException or InvalidOperationException or FileNotFoundException)
{
lblStatus.Text = "Please load a config to start";
UpdateStatus(StatusCode.NoConfig);
return;
}
else
Expand All @@ -741,7 +734,6 @@ private void LoadConf(string confPath)

private void LoadConf(YAMDCC_Config config)
{
lblStatus.Text = "Loading config, please wait...";
if (config.Template)
{
MessageBox.Show(
Expand Down Expand Up @@ -840,7 +832,7 @@ private void LoadConf(YAMDCC_Config config)
cboFanSel.SelectedIndex = 0;
tsiECMon.Enabled = true;

lblStatus.Text = "Ready";
UpdateStatus(StatusCode.None);
}

private void ApplyConf()
Expand Down Expand Up @@ -1005,5 +997,71 @@ private void UpdateFanCurveDisplay()
}
}
#endregion

private void UpdateStatus(StatusCode status, int data = 0)
{
if (AppStatus.Code == status)
{
AppStatus.RepeatCount++;
}
else
{
AppStatus.Code = status;
AppStatus.RepeatCount = 0;
}

// set status text
if (AppStatus is not null)
{
bool persist = false;

switch (AppStatus.Code)
{
case StatusCode.ServiceCommandFail:
persist = true;
lblStatus.Text = $"ERROR: A {(Command)data} service command failed to run.";
break;
case StatusCode.ServiceResponseEmpty:
lblStatus.Text = $"WARN: Received an empty response from service.";
break;
case StatusCode.NoConfig:
persist = true;
lblStatus.Text = "Please load a config to start";
break;
case StatusCode.ConfLoading:
lblStatus.Text = "Loading config, please wait...";
break;
case StatusCode.ConfApplySuccess:
lblStatus.Text = $"Config applied successfully!";
break;
case StatusCode.FullBlastToggleSuccess:
lblStatus.Text = $"Full Blast toggled successfully!";
break;
default:
persist = true;
lblStatus.Text = "Ready";
break;
}

if (AppStatus.RepeatCount > 0)
{
lblStatus.Text += $" (x{AppStatus.RepeatCount + 1})";
}

if (!persist)
{
tmrStatusReset.Stop();
tmrStatusReset.Start();
}
}
}

private void tmrStatusReset_Tick(object sender, EventArgs e)
{
AppStatus.Code = StatusCode.None;
AppStatus.RepeatCount = 0;
lblStatus.Text = "Ready";
tmrStatusReset.Stop();
}
}
}
33 changes: 3 additions & 30 deletions YAMDCC.GUI/MainWindow.resx
Original file line number Diff line number Diff line change
Expand Up @@ -138,30 +138,12 @@
<metadata name="sep5.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="sep1.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="sep2.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="tcMain.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="tabFanControl.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="tabOptions.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="tabFanControl.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="flwFanSelect.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="tblFCBottom.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="flwFanSelect.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
Expand All @@ -174,12 +156,6 @@
<metadata name="tblExtra.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="tblExtra.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="flwKeyLight.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="flwKeyLight.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
Expand All @@ -189,16 +165,13 @@
<metadata name="lblKeyLightHigh.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="lblKeyLightLow.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="lblKeyLightHigh.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="flwStats.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="tmrPoll.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>126, 17</value>
</metadata>
<metadata name="tmrStatusReset.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>219, 17</value>
</metadata>
</root>
31 changes: 31 additions & 0 deletions YAMDCC.GUI/Status.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace YAMDCC.GUI
{
internal class Status
{
internal StatusCode Code;
internal int RepeatCount;

internal Status()
{
Code = StatusCode.None;
RepeatCount = 0;
}

internal Status(StatusCode code, int repeatCount)
{
Code = code;
RepeatCount = repeatCount;
}
}

internal enum StatusCode
{
None = 0,
ServiceCommandFail,
ServiceResponseEmpty,
ConfLoading,
NoConfig,
ConfApplySuccess,
FullBlastToggleSuccess,
}
}

0 comments on commit cb0e13b

Please sign in to comment.