mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-15 05:04:15 +01:00
Move off messager
This commit is contained in:
parent
6da725350a
commit
aa01acd76a
1 changed files with 11 additions and 23 deletions
|
|
@ -1,19 +1,11 @@
|
||||||
using Dalamud.Interface.Internal.Notifications;
|
using OtterGui.Log;
|
||||||
using OtterGui.Classes;
|
|
||||||
|
|
||||||
namespace Penumbra.Import.Models;
|
namespace Penumbra.Import.Models;
|
||||||
|
|
||||||
public record class IoNotifier
|
public record class IoNotifier
|
||||||
{
|
{
|
||||||
/// <summary> Notification subclass so that we have a distinct type to filter by. </summary>
|
private readonly List<string> _messages = [];
|
||||||
private class LegallyDistinctNotification : Notification
|
private string _context = "";
|
||||||
{
|
|
||||||
public LegallyDistinctNotification(string content, NotificationType type): base(content, type)
|
|
||||||
{}
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly DateTime _startTime = DateTime.UtcNow;
|
|
||||||
private string _context = "";
|
|
||||||
|
|
||||||
/// <summary> Create a new notifier with the specified context appended to any other context already present. </summary>
|
/// <summary> Create a new notifier with the specified context appended to any other context already present. </summary>
|
||||||
public IoNotifier WithContext(string context)
|
public IoNotifier WithContext(string context)
|
||||||
|
|
@ -21,12 +13,12 @@ public record class IoNotifier
|
||||||
|
|
||||||
/// <summary> Send a warning with any current context to notification channels. </summary>
|
/// <summary> Send a warning with any current context to notification channels. </summary>
|
||||||
public void Warning(string content)
|
public void Warning(string content)
|
||||||
=> SendNotification(content, NotificationType.Warning);
|
=> SendMessage(content, Logger.LogLevel.Warning);
|
||||||
|
|
||||||
/// <summary> Get the current warnings for this notifier. </summary>
|
/// <summary> Get the current warnings for this notifier. </summary>
|
||||||
/// <remarks> This does not currently filter to notifications with the current notifier's context - it will return all IO notifications from all notifiers. </remarks>
|
/// <remarks> This does not currently filter to notifications with the current notifier's context - it will return all IO notifications from all notifiers. </remarks>
|
||||||
public IEnumerable<string> GetWarnings()
|
public IEnumerable<string> GetWarnings()
|
||||||
=> GetFilteredNotifications(NotificationType.Warning);
|
=> _messages;
|
||||||
|
|
||||||
/// <summary> Create an exception with any current context. </summary>
|
/// <summary> Create an exception with any current context. </summary>
|
||||||
[StackTraceHidden]
|
[StackTraceHidden]
|
||||||
|
|
@ -39,14 +31,10 @@ public record class IoNotifier
|
||||||
where TException : Exception, new()
|
where TException : Exception, new()
|
||||||
=> (TException)Activator.CreateInstance(typeof(TException), $"{_context}{message}")!;
|
=> (TException)Activator.CreateInstance(typeof(TException), $"{_context}{message}")!;
|
||||||
|
|
||||||
private void SendNotification(string message, NotificationType type)
|
private void SendMessage(string message, Logger.LogLevel type)
|
||||||
=> Penumbra.Messager.AddMessage(
|
{
|
||||||
new LegallyDistinctNotification($"{_context}{message}", type),
|
var fullText = $"{_context}{message}";
|
||||||
true, false, true, false
|
Penumbra.Log.Message(type, fullText);
|
||||||
);
|
_messages.Add(fullText);
|
||||||
|
}
|
||||||
private IEnumerable<string> GetFilteredNotifications(NotificationType type)
|
|
||||||
=> Penumbra.Messager
|
|
||||||
.Where(p => p.Key >= _startTime && p.Value is LegallyDistinctNotification && p.Value.NotificationType == type)
|
|
||||||
.Select(p => p.Value.PrintMessage);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue