From c67add20d6f2de96fcabf652d6e5ab9a78ab0992 Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Fri, 19 Jul 2024 10:46:29 +0200 Subject: [PATCH] improve logging/error display for lack of penumbra or glamourer --- .../Interop/Ipc/IpcCallerGlamourer.cs | 13 +++++-- .../Interop/Ipc/IpcCallerPenumbra.cs | 2 ++ MareSynchronos/MareSynchronos.csproj | 2 +- MareSynchronos/Plugin.cs | 3 +- .../Services/NotificationService.cs | 14 +++++--- .../ServerConfigurationManager.cs | 2 +- MareSynchronos/UI/CompactUI.cs | 34 ++++++++++++++++++- 7 files changed, 60 insertions(+), 10 deletions(-) diff --git a/MareSynchronos/Interop/Ipc/IpcCallerGlamourer.cs b/MareSynchronos/Interop/Ipc/IpcCallerGlamourer.cs index 50cb8c7..3d8a2ad 100644 --- a/MareSynchronos/Interop/Ipc/IpcCallerGlamourer.cs +++ b/MareSynchronos/Interop/Ipc/IpcCallerGlamourer.cs @@ -10,7 +10,7 @@ using Microsoft.Extensions.Logging; namespace MareSynchronos.Interop.Ipc; -public sealed class IpcCallerGlamourer : IIpcCaller +public sealed class IpcCallerGlamourer : DisposableMediatorSubscriberBase, IIpcCaller { private readonly ILogger _logger; private readonly IDalamudPluginInterface _pi; @@ -31,7 +31,7 @@ public sealed class IpcCallerGlamourer : IIpcCaller private readonly uint LockCode = 0x6D617265; public IpcCallerGlamourer(ILogger logger, IDalamudPluginInterface pi, DalamudUtilService dalamudUtil, MareMediator mareMediator, - RedrawManager redrawManager) + RedrawManager redrawManager) : base(logger, mareMediator) { _glamourerApiVersions = new ApiVersion(pi); _glamourerGetAllCustomization = new GetStateBase64(pi); @@ -50,6 +50,15 @@ public sealed class IpcCallerGlamourer : IIpcCaller _glamourerStateChanged = StateChanged.Subscriber(pi, GlamourerChanged); _glamourerStateChanged.Enable(); + + Mediator.Subscribe(this, s => _shownGlamourerUnavailable = false); + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + + _redrawManager.Cancel(); } public bool APIAvailable { get; private set; } diff --git a/MareSynchronos/Interop/Ipc/IpcCallerPenumbra.cs b/MareSynchronos/Interop/Ipc/IpcCallerPenumbra.cs index 104ebce..e3f6ebb 100644 --- a/MareSynchronos/Interop/Ipc/IpcCallerPenumbra.cs +++ b/MareSynchronos/Interop/Ipc/IpcCallerPenumbra.cs @@ -90,6 +90,8 @@ public sealed class IpcCallerPenumbra : DisposableMediatorSubscriberBase, IIpcCa { _penumbraRedraw.Invoke(msg.Character.ObjectIndex, RedrawType.AfterGPose); }); + + Mediator.Subscribe(this, (msg) => _shownPenumbraUnavailable = false); } public bool APIAvailable { get; private set; } = false; diff --git a/MareSynchronos/MareSynchronos.csproj b/MareSynchronos/MareSynchronos.csproj index a4b729f..d61d229 100644 --- a/MareSynchronos/MareSynchronos.csproj +++ b/MareSynchronos/MareSynchronos.csproj @@ -3,7 +3,7 @@ - 1.9.0 + 1.10.0 https://github.com/Penumbra-Sync/client diff --git a/MareSynchronos/Plugin.cs b/MareSynchronos/Plugin.cs index 82ebf42..5a5fd1d 100644 --- a/MareSynchronos/Plugin.cs +++ b/MareSynchronos/Plugin.cs @@ -107,7 +107,8 @@ public sealed class Plugin : IDalamudPlugin s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService())); collection.AddSingleton((s) => new NotificationService(s.GetRequiredService>(), - s.GetRequiredService(), notificationManager, chatGui, s.GetRequiredService())); + s.GetRequiredService(), s.GetRequiredService(), + notificationManager, chatGui, s.GetRequiredService())); collection.AddSingleton((s) => new MareConfigService(pluginInterface.ConfigDirectory.FullName)); collection.AddSingleton((s) => new ServerConfigService(pluginInterface.ConfigDirectory.FullName)); collection.AddSingleton((s) => new NotesConfigService(pluginInterface.ConfigDirectory.FullName)); diff --git a/MareSynchronos/Services/NotificationService.cs b/MareSynchronos/Services/NotificationService.cs index 34053f2..f76dbfb 100644 --- a/MareSynchronos/Services/NotificationService.cs +++ b/MareSynchronos/Services/NotificationService.cs @@ -12,13 +12,17 @@ namespace MareSynchronos.Services; public class NotificationService : DisposableMediatorSubscriberBase, IHostedService { + private readonly DalamudUtilService _dalamudUtilService; private readonly INotificationManager _notificationManager; private readonly IChatGui _chatGui; private readonly MareConfigService _configurationService; - public NotificationService(ILogger logger, MareMediator mediator, INotificationManager notificationManager, + public NotificationService(ILogger logger, MareMediator mediator, + DalamudUtilService dalamudUtilService, + INotificationManager notificationManager, IChatGui chatGui, MareConfigService configurationService) : base(logger, mediator) { + _dalamudUtilService = dalamudUtilService; _notificationManager = notificationManager; _chatGui = chatGui; _configurationService = configurationService; @@ -75,6 +79,8 @@ public class NotificationService : DisposableMediatorSubscriberBase, IHostedServ { Logger.LogInformation("{msg}", msg.ToString()); + if (!_dalamudUtilService.IsLoggedIn) return; + switch (msg.Type) { case NotificationType.Info: @@ -117,9 +123,9 @@ public class NotificationService : DisposableMediatorSubscriberBase, IHostedServ { Dalamud.Interface.ImGuiNotification.NotificationType dalamudType = msg.Type switch { - MareConfiguration.Models.NotificationType.Error => Dalamud.Interface.ImGuiNotification.NotificationType.Error, - MareConfiguration.Models.NotificationType.Warning => Dalamud.Interface.ImGuiNotification.NotificationType.Warning, - MareConfiguration.Models.NotificationType.Info => Dalamud.Interface.ImGuiNotification.NotificationType.Info, + NotificationType.Error => Dalamud.Interface.ImGuiNotification.NotificationType.Error, + NotificationType.Warning => Dalamud.Interface.ImGuiNotification.NotificationType.Warning, + NotificationType.Info => Dalamud.Interface.ImGuiNotification.NotificationType.Info, _ => Dalamud.Interface.ImGuiNotification.NotificationType.Info }; diff --git a/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs b/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs index 4b52eee..ee73547 100644 --- a/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs +++ b/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs @@ -103,7 +103,7 @@ public class ServerConfigurationManager var auth = currentServer.Authentications.FindAll(f => string.Equals(f.CharacterName, charaName, StringComparison.Ordinal) && f.WorldId == worldId); if (auth.Count >= 2) { - _mareMediator.Publish(new NotificationMessage("Multiple Identical Characters detected", "Your Service configuration has multiple characters with the same name and world set up. Please delete the duplicates in the character configuration.", + _mareMediator.Publish(new NotificationMessage("Multiple Identical Characters detected", "Your Service configuration has multiple characters with the same name and world set up. Please delete the duplicates in the character management.", NotificationType.Error)); _logger.LogTrace("GetSecretKey accessed, returning null because multiple ({count}) identical characters.", auth.Count); return null; diff --git a/MareSynchronos/UI/CompactUI.cs b/MareSynchronos/UI/CompactUI.cs index 9de6dc6..f7b97b1 100644 --- a/MareSynchronos/UI/CompactUI.cs +++ b/MareSynchronos/UI/CompactUI.cs @@ -6,6 +6,7 @@ using Dalamud.Utility; using ImGuiNET; using MareSynchronos.API.Data.Extensions; using MareSynchronos.API.Dto.Group; +using MareSynchronos.Interop.Ipc; using MareSynchronos.MareConfiguration; using MareSynchronos.PlayerData.Handlers; using MareSynchronos.PlayerData.Pairs; @@ -37,6 +38,7 @@ public class CompactUi : WindowMediatorSubscriberBase private readonly PairManager _pairManager; private readonly SelectTagForPairUi _selectGroupForPairUi; private readonly SelectPairForTagUi _selectPairsForGroupUi; + private readonly IpcManager _ipcManager; private readonly ServerConfigurationManager _serverManager; private readonly TopTabMenu _tabMenu; private readonly TagHandler _tagHandler; @@ -55,7 +57,7 @@ public class CompactUi : WindowMediatorSubscriberBase public CompactUi(ILogger logger, UiSharedService uiShared, MareConfigService configService, ApiController apiController, PairManager pairManager, ServerConfigurationManager serverManager, MareMediator mediator, FileUploadManager fileTransferManager, TagHandler tagHandler, DrawEntityFactory drawEntityFactory, SelectTagForPairUi selectTagForPairUi, SelectPairForTagUi selectPairForTagUi, - PerformanceCollectorService performanceCollectorService) + PerformanceCollectorService performanceCollectorService, IpcManager ipcManager) : base(logger, mediator, "###MareSynchronosMainUI", performanceCollectorService) { _uiSharedService = uiShared; @@ -68,6 +70,7 @@ public class CompactUi : WindowMediatorSubscriberBase _drawEntityFactory = drawEntityFactory; _selectGroupForPairUi = selectTagForPairUi; _selectPairsForGroupUi = selectPairForTagUi; + _ipcManager = ipcManager; _tabMenu = new TopTabMenu(Mediator, _apiController, _pairManager, _uiSharedService); AllowPinning = false; @@ -152,6 +155,35 @@ public class CompactUi : WindowMediatorSubscriberBase $"It is highly recommended to keep Mare Synchronos up to date. Open /xlplugins and update the plugin.", ImGuiColors.DalamudRed); } + if (!_ipcManager.Initialized) + { + var unsupported = "MISSING ESSENTIAL PLUGINS"; + + using (_uiSharedService.UidFont.Push()) + { + var uidTextSize = ImGui.CalcTextSize(unsupported); + ImGui.SetCursorPosX((ImGui.GetWindowContentRegionMax().X + ImGui.GetWindowContentRegionMin().X) / 2 - uidTextSize.X / 2); + ImGui.AlignTextToFramePadding(); + ImGui.TextColored(ImGuiColors.DalamudRed, unsupported); + } + var penumAvailable = _ipcManager.Penumbra.APIAvailable; + var glamAvailable = _ipcManager.Glamourer.APIAvailable; + + UiSharedService.ColorTextWrapped($"One or more Plugins essential for Mare operation are unavailable. Enable or update following plugins:", ImGuiColors.DalamudRed); + using var indent = ImRaii.PushIndent(10f); + if (!penumAvailable) + { + UiSharedService.TextWrapped("Penumbra"); + _uiSharedService.BooleanToColoredIcon(penumAvailable, true); + } + if (!glamAvailable) + { + UiSharedService.TextWrapped("Glamourer"); + _uiSharedService.BooleanToColoredIcon(glamAvailable, true); + } + ImGui.Separator(); + } + using (ImRaii.PushId("header")) DrawUIDHeader(); ImGui.Separator(); using (ImRaii.PushId("serverstatus")) DrawServerStatus();