Skip to content

Commit

Permalink
message buttons timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Razzmatazzz committed Jun 14, 2024
1 parent c4a6fc0 commit bbefa59
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 78 deletions.
17 changes: 9 additions & 8 deletions TarkovMonitor/GameWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,15 @@ internal void GameWatcher_NewLogData(object? sender, NewLogDataEventArgs e)
CurrentProfile.Id = profileIdMatch.Groups["profileId"].Value;
if (!e.InitialRead)
{
ProfileChanged?.Invoke(this, new(CurrentProfile));
if (raidInfo.StartedTime != null && raidInfo.EndedTime == null)
{
raidInfo.EndedTime = eventDate;
RaidEnded?.Invoke(this, new(raidInfo, CurrentProfile));
}
else
{
ProfileChanged?.Invoke(this, new(CurrentProfile));
}
}
continue;
}
Expand Down Expand Up @@ -418,13 +426,6 @@ internal void GameWatcher_NewLogData(object? sender, NewLogDataEventArgs e)
ProfileType = CurrentProfile.Type,
};
}
if (eventLine.Contains("application|SelectProfile ProfileId:"))
{
if (raidInfo.StartedTime != null && raidInfo.EndedTime == null) {
raidInfo.EndedTime = eventDate;
RaidEnded?.Invoke(this, new(raidInfo, CurrentProfile));
}
}
if (eventLine.Contains("application|Init: pstrGameVersion: "))
{
if (raidInfo.EndedTime != null)
Expand Down
72 changes: 9 additions & 63 deletions TarkovMonitor/MainBlazorUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ public MainBlazorUI()
SocketClient.ExceptionThrown += SocketClient_ExceptionThrown;

// Update tarkov.dev Repository data
UpdateItems();
UpdateTasks();
UpdateMaps();
UpdateTraders();
UpdateHideoutStations();
UpdateTarkovDevApiData();
TarkovDev.StartAutoUpdates();

UpdateCheck.CheckForNewVersion();
Expand Down Expand Up @@ -228,14 +224,15 @@ private void Eft_RaidEnded(object? sender, RaidInfoEventArgs e)
File.Delete(Path.Combine(eft.ScreenshotsPath, filename));
}
//e.RaidInfo.Screenshots.Clear();
monMessage.Buttons.Remove(screenshotButton);
messageLog.AddMessage($"Deleted {e.RaidInfo.Screenshots.Count} screenshots");
}
catch (Exception ex)
{
messageLog.AddMessage($"Error deleting screenshot: {ex.Message} {ex.StackTrace}", "exception");
}
monMessage.Buttons.Remove(screenshotButton);
};
screenshotButton.Timeout = TimeSpan.FromMinutes(120).TotalMilliseconds;
monMessage.Buttons.Add(screenshotButton);
}
messageLog.AddMessage(monMessage);
Expand Down Expand Up @@ -398,68 +395,16 @@ private void WebView_CoreWebView2InitializationCompleted(object? sender, CoreWeb
if (Debugger.IsAttached) blazorWebView1.WebView.CoreWebView2.OpenDevToolsWindow();
}

private async Task UpdateItems()
private async Task UpdateTarkovDevApiData()
{
try
{
await TarkovDev.GetItems();
messageLog.AddMessage($"Retrieved {String.Format("{0:n0}", TarkovDev.Items.Count)} items from tarkov.dev", "update");
await TarkovDev.UpdateApiData();
messageLog.AddMessage($"Retrieved {String.Format("{0:n0}", TarkovDev.Items.Count)} items, {TarkovDev.Maps.Count} maps, {TarkovDev.Traders.Count} traders, {TarkovDev.Tasks.Count} tasks, and {TarkovDev.Stations.Count} hideout stations from tarkov.dev", "update");
}
catch (Exception ex)
{
messageLog.AddMessage($"Error updating items: {ex.Message}");
}
}

private async Task UpdateTasks()
{
try
{
await TarkovDev.GetTasks();
messageLog.AddMessage($"Retrieved {TarkovDev.Tasks.Count} tasks from tarkov.dev", "update");
}
catch (Exception ex)
{
messageLog.AddMessage($"Error updating tasks: {ex.Message}");
}
}

private async Task UpdateMaps()
{
try
{
await TarkovDev.GetMaps();
messageLog.AddMessage($"Retrieved {TarkovDev.Maps.Count} maps from tarkov.dev", "update");
}
catch (Exception ex)
{
messageLog.AddMessage($"Error updating maps: {ex.Message}");
}
}

private async Task UpdateTraders()
{
try
{
await TarkovDev.GetTraders();
messageLog.AddMessage($"Retrieved {TarkovDev.Traders.Count} traders from tarkov.dev", "update");
}
catch (Exception ex)
{
messageLog.AddMessage($"Error updating traders: {ex.Message}");
}
}

private async Task UpdateHideoutStations()
{
try
{
await TarkovDev.GetHideout();
messageLog.AddMessage($"Retrieved {TarkovDev.Stations.Count} hideout stations from tarkov.dev", "update");
}
catch (Exception ex)
{
messageLog.AddMessage($"Error updating hideout stations: {ex.Message}");
messageLog.AddMessage($"Error updating tarkov.dev API data: {ex.Message}");
}
}

Expand Down Expand Up @@ -690,18 +635,19 @@ private async void Eft_RaidStart(object? sender, RaidInfoEventArgs e)
try
{
await TarkovDev.PostGoonsSighting(e.RaidInfo.Map, (DateTime)e.RaidInfo.StartedTime, eft.AccountId);
monMessage.Buttons.Remove(goonsButton);
messageLog.AddMessage($"Goons reported on {mapName}", "info");
}
catch (Exception ex) {
messageLog.AddMessage($"Error reporting goons: {ex.Message} {ex.StackTrace}", "exception");
}
monMessage.Buttons.Remove(goonsButton);
};
goonsButton.Confirm = new(
$"Report Goons on {mapName}",
"<p>Please only submit a report if you saw the goons in this raid.</p><p><strong>Notice:</strong> By submitting a goons report, you consent to collection of your IP address and EFT account id for report verification purposes.</p>",
"Submit report", "Cancel"
);
goonsButton.Timeout = TimeSpan.FromMinutes(120).TotalMilliseconds;
monMessage.Buttons.Add(goonsButton);
}
messageLog.AddMessage(monMessage);
Expand Down
77 changes: 76 additions & 1 deletion TarkovMonitor/MonitorMessage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using MudBlazor;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Timers;

namespace TarkovMonitor
{
Expand All @@ -10,10 +13,34 @@ public class MonitorMessage
public string Type { get; set; } = "";
public string Url { get; set; } = "";
public Action? OnClick { get; set; } = null;
public List<MonitorMessageButton> Buttons { get; set; } = new();
public ObservableCollection<MonitorMessageButton> Buttons { get; set; } = new();
public MonitorMessage(string message)
{
Message = message;
Buttons.CollectionChanged += (object? sender, NotifyCollectionChangedEventArgs e) => {
if (e.Action == NotifyCollectionChangedAction.Add)
{
if (e.NewItems == null)
{
return;
}
foreach (MonitorMessageButton button in e.NewItems.Cast<MonitorMessageButton>().ToList())
{
button.Expired += ButtonExpired;
}
}
if (e.Action == NotifyCollectionChangedAction.Remove)
{
if (e.OldItems == null)
{
return;
}
foreach (MonitorMessageButton button in e.OldItems.Cast<MonitorMessageButton>().ToList())
{
button.Expired -= ButtonExpired;
}
}
};
}
public MonitorMessage(string message, string? type = "", string? url = "") : this(message)
{
Expand All @@ -34,6 +61,15 @@ public MonitorMessage(string message, string? type = "", string? url = "") : thi
}, Icons.Material.Filled.BugReport));
}
}

private void ButtonExpired(object? sender, EventArgs e)
{
if (sender == null)
{
return;
}
Buttons.Remove((MonitorMessageButton)sender);
}
}

public class MonitorMessageButton
Expand All @@ -44,13 +80,52 @@ public class MonitorMessageButton
public Action? OnClick { get; set; }
public bool Disabled { get; set; } = false;
public MonitorMessageButtonConfirm? Confirm { get; set; }
private System.Timers.Timer? buttonTimer;
private double? timeout = null;
public double? Timeout {
get
{
return timeout;
}
set
{
timeout = value;
if (buttonTimer != null)
{
buttonTimer.Stop();
buttonTimer.Dispose();
}
if (value == null || value == 0)
{
buttonTimer = null;
}
else
{
buttonTimer = new(timeout ?? 0) {
AutoReset = true,
Enabled = true,
};
buttonTimer.Elapsed += (object? sender, ElapsedEventArgs e) =>
{
Expired?.Invoke(this, e);
};

}
}
}
public event EventHandler? Expired;
public MonitorMessageButton(string text, Action? onClick = null, string icon = "")
{
Text = text;
Icon = icon;
OnClick = onClick;
}
public MonitorMessageButton(string text, string icon = "") : this(text, null, icon) { }
public void Expire()
{
buttonTimer?.Stop();
Expired?.Invoke(this, new());
}
}

public class MonitorMessageButtonConfirm
Expand Down
18 changes: 12 additions & 6 deletions TarkovMonitor/TarkovDev.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using GraphQL.Client.Http;
using GraphQL.Client.Serializer.SystemTextJson;
using Refit;
using System.Security.Policy;
using static TarkovMonitor.TarkovTracker;

namespace TarkovMonitor
{
Expand Down Expand Up @@ -199,6 +197,17 @@ ...on HideoutStationBonus {
Stations = response.Data.hideoutStations;
return Stations;
}
public async static System.Threading.Tasks.Task UpdateApiData()
{
List<System.Threading.Tasks.Task> tasks = new() {
GetTasks(),
GetMaps(),
GetItems(),
GetTraders(),
GetHideout(),
};
await System.Threading.Tasks.Task.WhenAll(tasks);
}
public async static Task<List<PlayerLevel>> GetPlayerLevels()
{
var request = new GraphQL.GraphQLRequest()
Expand Down Expand Up @@ -317,10 +326,7 @@ public static void StartAutoUpdates()

private static void UpdateTimer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{
GetTasks();
GetMaps();
GetItems();
GetTraders();
UpdateApiData();
}

public class TasksResponse
Expand Down

0 comments on commit bbefa59

Please sign in to comment.