Add auto-close when notification becomes inactive
- Fleet alert forms now check every 30 seconds if notification is still active - Automatically close if notification has ended or been deactivated - Bump tray to 1.6.3, agent to 1.13.2
This commit is contained in:
@@ -12,15 +12,20 @@ namespace ShopDbEndpointAgent.Tray;
|
||||
internal sealed class FleetAlertForm : Form
|
||||
{
|
||||
private readonly FleetAlert alert;
|
||||
private readonly FleetAlertClient? client;
|
||||
private readonly string? hostname;
|
||||
private System.Windows.Forms.Timer? countdownTimer;
|
||||
private System.Windows.Forms.Timer? statusCheckTimer;
|
||||
private int remainingSeconds;
|
||||
private Label? countdownLabel;
|
||||
|
||||
public event EventHandler? OnAcknowledgeClicked;
|
||||
|
||||
public FleetAlertForm(FleetAlert alert)
|
||||
public FleetAlertForm(FleetAlert alert, FleetAlertClient? client = null, string? hostname = null)
|
||||
{
|
||||
this.alert = alert ?? throw new ArgumentNullException(nameof(alert));
|
||||
this.client = client;
|
||||
this.hostname = hostname;
|
||||
|
||||
Text = string.Empty;
|
||||
FormBorderStyle = FormBorderStyle.None;
|
||||
@@ -43,11 +48,46 @@ internal sealed class FleetAlertForm : Form
|
||||
private void FleetAlertForm_FormClosing(object? sender, FormClosingEventArgs e)
|
||||
{
|
||||
countdownTimer?.Stop();
|
||||
statusCheckTimer?.Stop();
|
||||
}
|
||||
|
||||
private void FleetAlertForm_Load(object? sender, EventArgs e)
|
||||
{
|
||||
System.Media.SystemSounds.Beep.Play();
|
||||
|
||||
if (client != null && hostname != null)
|
||||
{
|
||||
StartStatusCheck();
|
||||
}
|
||||
}
|
||||
|
||||
private void StartStatusCheck()
|
||||
{
|
||||
statusCheckTimer = new System.Windows.Forms.Timer { Interval = 30000 };
|
||||
statusCheckTimer.Tick += StatusCheckTimer_Tick;
|
||||
statusCheckTimer.Start();
|
||||
}
|
||||
|
||||
private async void StatusCheckTimer_Tick(object? sender, EventArgs e)
|
||||
{
|
||||
if (client == null || hostname == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var alerts = await client.FetchAlertsAsync(hostname, CancellationToken.None);
|
||||
var stillActive = alerts?.Any(a => a.NotificationId == alert.NotificationId) ?? false;
|
||||
|
||||
if (!stillActive)
|
||||
{
|
||||
statusCheckTimer?.Stop();
|
||||
Close();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore errors - keep the form open if we can't check status
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyRoundedCorners()
|
||||
@@ -280,6 +320,8 @@ internal sealed class FleetAlertForm : Form
|
||||
{
|
||||
countdownTimer?.Stop();
|
||||
countdownTimer?.Dispose();
|
||||
statusCheckTimer?.Stop();
|
||||
statusCheckTimer?.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ internal sealed class FleetAlertWorker : IDisposable
|
||||
{
|
||||
try
|
||||
{
|
||||
using var form = new FleetAlertForm(alert);
|
||||
using var form = new FleetAlertForm(alert, client, hostname);
|
||||
form.OnAcknowledgeClicked += (s, e) => OnAlertAcknowledged(alert, token);
|
||||
var result = form.ShowDialog();
|
||||
}
|
||||
|
||||
@@ -76,7 +76,10 @@
|
||||
<!-- 1.6.2: disable auto-dismiss timer. Fleet alerts now require manual
|
||||
acknowledgment only. Footer shows "Manual acknowledgment required" instead
|
||||
of countdown timer. -->
|
||||
<Version>1.6.2</Version>
|
||||
<!-- 1.6.3: auto-close when notification becomes inactive. Fleet alert forms now
|
||||
check every 30 seconds if the notification is still active on the server and
|
||||
automatically close if it has ended or been deactivated. -->
|
||||
<Version>1.6.3</Version>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<SelfContained>true</SelfContained>
|
||||
|
||||
@@ -173,7 +173,9 @@
|
||||
is the side that listens, so an older tray simply never answers. -->
|
||||
<!-- 1.13.1: coordinated release with tray 1.6.0 (fleet alert styling update).
|
||||
No agent code changes, but deployed together for version consistency. -->
|
||||
<Version>1.13.1</Version>
|
||||
<!-- 1.13.2: coordinated release with tray 1.6.3 (auto-close when inactive, crash fix).
|
||||
No agent code changes, but deployed together for version consistency. -->
|
||||
<Version>1.13.2</Version>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<SelfContained>true</SelfContained>
|
||||
|
||||
Reference in New Issue
Block a user