Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/SiteMonitor/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
using System.Reflection;
using System;
using System.Reflection;

namespace SiteMonitor;

/// <summary>
/// Constants used throughout the file.
/// </summary>
public class Constants {
/// <summary>
/// The maximum amount of time before alerting the user that we aren't getting chat messages.
/// </summary>
public static readonly TimeSpan MAX_TIME_WITHOUT_CHATS = TimeSpan.FromMinutes(30);

/// <summary>
/// The maximum amount of time before alerting the user that the APIs are down and not automatically coming back up.
/// </summary>
public static readonly TimeSpan MAX_TIME_SERVICE_IS_DOWN = TimeSpan.FromMinutes(5);

/// <summary>
/// The version of the application being run right now.
/// </summary>
Expand Down
7 changes: 5 additions & 2 deletions src/SiteMonitor/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace SiteMonitor.ViewModels;
/// The view model for the main UI.
/// </summary>
public partial class MainWindowViewModel : ViewModelBase {
private DateTime? _apiDownSince;
[ObservableProperty] private bool _apiUp = true;

[ObservableProperty] private string? _chatTimestamp;
Expand Down Expand Up @@ -168,15 +169,17 @@ private async Task PingSite() {
TimeSpan diff = DateTime.Now - time.ToLocalTime();
timestamp = $"{timestamp} ({diff.Hours}h {diff.Minutes}m {diff.Seconds}s ago)";
ChatTimestamp = timestamp;
chatNotUpdating = diff > TimeSpan.FromMinutes(5);
chatNotUpdating = diff > Constants.MAX_TIME_WITHOUT_CHATS;
}
}
else {
ChatTimestamp = null;
chatNotUpdating = true;
}

if ((!WebsiteUp || !ApiUp || !NullUp || chatNotUpdating) && IsMinimized) {
_apiDownSince = !WebsiteUp || !ApiUp || !NullUp ? _apiDownSince ?? DateTime.Now : null;
bool apiNotComingUp = DateTime.Now - _apiDownSince > Constants.MAX_TIME_SERVICE_IS_DOWN;
if ((apiNotComingUp || chatNotUpdating) && IsMinimized) {
WindowState = WindowState.Normal;
}

Expand Down
Loading