mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +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.Classes;
|
||||
using OtterGui.Log;
|
||||
|
||||
namespace Penumbra.Import.Models;
|
||||
|
||||
public record class IoNotifier
|
||||
{
|
||||
/// <summary> Notification subclass so that we have a distinct type to filter by. </summary>
|
||||
private class LegallyDistinctNotification : Notification
|
||||
{
|
||||
public LegallyDistinctNotification(string content, NotificationType type): base(content, type)
|
||||
{}
|
||||
}
|
||||
|
||||
private readonly DateTime _startTime = DateTime.UtcNow;
|
||||
private string _context = "";
|
||||
private readonly List<string> _messages = [];
|
||||
private string _context = "";
|
||||
|
||||
/// <summary> Create a new notifier with the specified context appended to any other context already present. </summary>
|
||||
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>
|
||||
public void Warning(string content)
|
||||
=> SendNotification(content, NotificationType.Warning);
|
||||
=> SendMessage(content, Logger.LogLevel.Warning);
|
||||
|
||||
/// <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>
|
||||
public IEnumerable<string> GetWarnings()
|
||||
=> GetFilteredNotifications(NotificationType.Warning);
|
||||
=> _messages;
|
||||
|
||||
/// <summary> Create an exception with any current context. </summary>
|
||||
[StackTraceHidden]
|
||||
|
|
@ -39,14 +31,10 @@ public record class IoNotifier
|
|||
where TException : Exception, new()
|
||||
=> (TException)Activator.CreateInstance(typeof(TException), $"{_context}{message}")!;
|
||||
|
||||
private void SendNotification(string message, NotificationType type)
|
||||
=> Penumbra.Messager.AddMessage(
|
||||
new LegallyDistinctNotification($"{_context}{message}", type),
|
||||
true, false, true, false
|
||||
);
|
||||
|
||||
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);
|
||||
private void SendMessage(string message, Logger.LogLevel type)
|
||||
{
|
||||
var fullText = $"{_context}{message}";
|
||||
Penumbra.Log.Message(type, fullText);
|
||||
_messages.Add(fullText);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue