refactor(di): migrate UI Window-Layer to ILogger<T> (DI-4 Slice C)
Six UI files shift from Plugin.LogProxy to ILogger<T> via constructor injection. Container singletons (each takes a typed ILogger plus, where it owns nested allocations, an ILoggerFactory to spawn child loggers): - Ui/ChatLogWindow (15 sites, plus an ILoggerFactory for the Popout new-call at Ui/ChatLogWindow.cs:2417) - Ui/Settings (SettingsWindow): no own sites, but takes an ILoggerFactory so it can hand typed loggers to its three migrated settings tabs (General, the other six tabs stay unchanged) - Ui/DbViewer (3 sites) Nested instances allocated by parent containers: - Ui/Popout (7 sites, ILogger<Popout> as the new 4th ctor arg passed from ChatLogWindow) - Ui/SettingsTabs/ThemeAndLayout (1 site) - Ui/SettingsTabs/FontsAndColours (1 site) - Ui/SettingsTabs/DataManagement (15 sites) PluginHostFactory factory lambdas updated for ChatLogWindow, SettingsWindow and DbViewer to resolve the new logger args.
This commit is contained in:
@@ -22,6 +22,7 @@ using HellionChat.Resources;
|
||||
using HellionChat.Util;
|
||||
using Lumina.Excel.Sheets;
|
||||
using Lumina.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace HellionChat.Ui;
|
||||
|
||||
@@ -98,10 +99,19 @@ public sealed class ChatLogWindow : Window
|
||||
private long FrameTime; // set every frame
|
||||
internal long LastActivityTime = Environment.TickCount64;
|
||||
|
||||
internal ChatLogWindow(Plugin plugin)
|
||||
private readonly ILogger<ChatLogWindow> _logger;
|
||||
private readonly ILoggerFactory _loggerFactory;
|
||||
|
||||
internal ChatLogWindow(
|
||||
Plugin plugin,
|
||||
ILogger<ChatLogWindow> logger,
|
||||
ILoggerFactory loggerFactory
|
||||
)
|
||||
: base($"{Plugin.PluginName}###chat2")
|
||||
{
|
||||
Plugin = plugin;
|
||||
_logger = logger;
|
||||
_loggerFactory = loggerFactory;
|
||||
Salt = new Random().Next().ToString();
|
||||
|
||||
Size = new Vector2(500, 250);
|
||||
@@ -297,7 +307,7 @@ public sealed class ChatLogWindow : Window
|
||||
|| !GameFunctions.Chat.IsChannelOrExistingLinkshell(targetChannel.Value)
|
||||
)
|
||||
{
|
||||
Plugin.LogProxy.Warning(
|
||||
_logger.LogWarning(
|
||||
$"Channel was set to an invalid value '{targetChannel}', ignoring"
|
||||
);
|
||||
return;
|
||||
@@ -351,11 +361,11 @@ public sealed class ChatLogWindow : Window
|
||||
{
|
||||
case "hide":
|
||||
CurrentHideState = HideState.User;
|
||||
Plugin.LogProxy.Verbose("HideState: → User (chat hide command)");
|
||||
_logger.LogTrace("HideState: → User (chat hide command)");
|
||||
break;
|
||||
case "show":
|
||||
CurrentHideState = HideState.None;
|
||||
Plugin.LogProxy.Verbose("HideState: → None (chat show command)");
|
||||
_logger.LogTrace("HideState: → None (chat show command)");
|
||||
break;
|
||||
case "toggle":
|
||||
CurrentHideState = CurrentHideState switch
|
||||
@@ -365,7 +375,7 @@ public sealed class ChatLogWindow : Window
|
||||
HideState.None => HideState.User,
|
||||
_ => CurrentHideState,
|
||||
};
|
||||
Plugin.LogProxy.Verbose($"HideState: → {CurrentHideState} (chat toggle command)");
|
||||
_logger.LogTrace($"HideState: → {CurrentHideState} (chat toggle command)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -475,7 +485,7 @@ public sealed class ChatLogWindow : Window
|
||||
else if (newTab.CurrentChannel.Channel is InputChannel.Invalid)
|
||||
{
|
||||
newTab.CurrentChannel = previousTab.CurrentChannel.Clone();
|
||||
Plugin.LogProxy.Debug(
|
||||
_logger.LogDebug(
|
||||
$"[Tab] '{newTab.Name}' seeded channel from '{previousTab.Name}' "
|
||||
+ $"(Channel={newTab.CurrentChannel.Channel}, TellTarget={newTab.CurrentChannel.TellTarget?.ToTargetString() ?? "null"})"
|
||||
);
|
||||
@@ -503,14 +513,14 @@ public sealed class ChatLogWindow : Window
|
||||
if (Plugin.Config.HideInBattle && CurrentHideState == HideState.None && Plugin.InBattle)
|
||||
{
|
||||
CurrentHideState = HideState.Battle;
|
||||
Plugin.LogProxy.Verbose("HideState: None → Battle");
|
||||
_logger.LogTrace("HideState: None → Battle");
|
||||
}
|
||||
|
||||
// If the chat is hidden because of battle, we reset it here
|
||||
if (CurrentHideState is HideState.Battle && !Plugin.InBattle)
|
||||
{
|
||||
CurrentHideState = HideState.None;
|
||||
Plugin.LogProxy.Verbose("HideState: Battle → None");
|
||||
_logger.LogTrace("HideState: Battle → None");
|
||||
}
|
||||
|
||||
// if the chat has no hide state and in a cutscene, set the hide state to cutscene
|
||||
@@ -523,7 +533,7 @@ public sealed class ChatLogWindow : Window
|
||||
if (Plugin.Functions.Chat.CheckHideFlags())
|
||||
{
|
||||
CurrentHideState = HideState.Cutscene;
|
||||
Plugin.LogProxy.Verbose("HideState: None → Cutscene");
|
||||
_logger.LogTrace("HideState: None → Cutscene");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,7 +544,7 @@ public sealed class ChatLogWindow : Window
|
||||
&& !Plugin.GposeActive
|
||||
)
|
||||
{
|
||||
Plugin.LogProxy.Verbose($"HideState: {CurrentHideState} → None (cutscene/gpose ended)");
|
||||
_logger.LogTrace($"HideState: {CurrentHideState} → None (cutscene/gpose ended)");
|
||||
CurrentHideState = HideState.None;
|
||||
}
|
||||
|
||||
@@ -542,14 +552,14 @@ public sealed class ChatLogWindow : Window
|
||||
if (CurrentHideState == HideState.Cutscene && Activate)
|
||||
{
|
||||
CurrentHideState = HideState.CutsceneOverride;
|
||||
Plugin.LogProxy.Verbose("HideState: Cutscene → CutsceneOverride (user activate)");
|
||||
_logger.LogTrace("HideState: Cutscene → CutsceneOverride (user activate)");
|
||||
}
|
||||
|
||||
// if the user hid the chat and is now activating chat, reset the hide state
|
||||
if (CurrentHideState == HideState.User && Activate)
|
||||
{
|
||||
CurrentHideState = HideState.None;
|
||||
Plugin.LogProxy.Verbose("HideState: User → None (activate)");
|
||||
_logger.LogTrace("HideState: User → None (activate)");
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -680,7 +690,7 @@ public sealed class ChatLogWindow : Window
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Plugin.LogProxy.Error(ex, "Error drawing Chat Log window");
|
||||
_logger.LogError(ex, "Error drawing Chat Log window");
|
||||
if (!NotifiedDrawFailure)
|
||||
{
|
||||
Plugin.Notification.AddNotification(
|
||||
@@ -1722,7 +1732,7 @@ public sealed class ChatLogWindow : Window
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Plugin.LogProxy.Warning(ex, "Error drawing chat log");
|
||||
_logger.LogWarning(ex, "Error drawing chat log");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2270,7 +2280,7 @@ public sealed class ChatLogWindow : Window
|
||||
{
|
||||
Plugin.Config.SeenPopOutHeaderHint = true;
|
||||
Plugin.SaveConfig();
|
||||
Plugin.LogProxy.Debug("v0.6.1 pop-out header hint dismissed");
|
||||
_logger.LogDebug("v0.6.1 pop-out header hint dismissed");
|
||||
if (openSettings)
|
||||
Plugin.SettingsWindow.Toggle();
|
||||
}
|
||||
@@ -2408,7 +2418,7 @@ public sealed class ChatLogWindow : Window
|
||||
if (PopOutWindows.Contains(tab.Identifier))
|
||||
continue;
|
||||
|
||||
var window = new Popout(this, tab, i);
|
||||
var window = new Popout(this, tab, i, _loggerFactory.CreateLogger<Popout>());
|
||||
|
||||
Plugin.WindowSystem.AddWindow(window);
|
||||
PopOutWindows.Add(tab.Identifier);
|
||||
@@ -2925,7 +2935,7 @@ public sealed class ChatLogWindow : Window
|
||||
var viewport = ImGui.GetMainViewport();
|
||||
var safePos = viewport.WorkPos + SafeDefaultOffset;
|
||||
Position = safePos;
|
||||
Plugin.LogProxy.Info(
|
||||
_logger.LogInformation(
|
||||
$"[Window-Recovery] {source}: snapping main window from {LastWindowPos} (size {LastWindowSize}) to {safePos}."
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user