Fix freezing popouts on saving the settings

This commit is contained in:
Infi
2024-04-23 07:48:57 +02:00
parent fc8199b3e5
commit c892577f54
6 changed files with 172 additions and 33 deletions
+24 -10
View File
@@ -56,8 +56,12 @@ internal class Configuration : IPluginConfiguration
public bool OverrideStyle;
public string? ChosenStyle;
internal void UpdateFrom(Configuration other)
internal void UpdateFrom(Configuration other, bool backToOriginal)
{
if (backToOriginal)
foreach (var tab in Tabs.Where(t => t.PopOut))
tab.PopOut = false;
HideChat = other.HideChat;
HideDuringCutscenes = other.HideDuringCutscenes;
HideWhenNotLoggedIn = other.HideWhenNotLoggedIn;
@@ -175,7 +179,7 @@ internal class Tab
public string Name = Language.Tab_DefaultName;
public Dictionary<ChatType, ChatSource> ChatCodes = new();
public bool ExtraChatAll;
public HashSet<Guid> ExtraChatChannels = new();
public HashSet<Guid> ExtraChatChannels = [];
[Obsolete("Use UnreadMode instead")]
public bool DisplayUnread = true;
@@ -194,9 +198,9 @@ internal class Tab
public SemaphoreSlim MessagesMutex = new(1, 1);
[NonSerialized]
public List<Message> Messages = new();
public List<Message> Messages = [];
[NonSerialized]
public HashSet<Guid> TrackedMessageIds = new();
public HashSet<Guid> TrackedMessageIds = [];
[NonSerialized]
public InputChannel? PreviousChannel;
@@ -204,13 +208,18 @@ internal class Tab
[NonSerialized]
public Guid Identifier = Guid.NewGuid();
~Tab() { MessagesMutex.Dispose(); }
~Tab()
{
MessagesMutex.Dispose();
}
internal bool Contains(Message message) {
internal bool Contains(Message message)
{
return TrackedMessageIds.Contains(message.Id);
}
internal bool Matches(Message message) {
internal bool Matches(Message message)
{
if (message.ExtraChatChannel != Guid.Empty)
return ExtraChatAll || ExtraChatChannels.Contains(message.ExtraChatChannel);
@@ -221,11 +230,14 @@ internal class Tab
}
internal void AddMessage(Message message, bool unread = true) {
if (Contains(message)) return;
if (Contains(message))
return;
MessagesMutex.Wait();
TrackedMessageIds.Add(message.Id);
Messages.Add(message);
while (Messages.Count > MessageManager.MessageDisplayLimit) {
while (Messages.Count > MessageManager.MessageDisplayLimit)
{
TrackedMessageIds.Remove(Messages[0].Id);
Messages.RemoveAt(0);
}
@@ -235,7 +247,8 @@ internal class Tab
Unread += 1;
}
internal void Clear() {
internal void Clear()
{
MessagesMutex.Wait();
Messages.Clear();
TrackedMessageIds.Clear();
@@ -259,6 +272,7 @@ internal class Tab
PopOut = PopOut,
IndependentOpacity = IndependentOpacity,
Opacity = Opacity,
Identifier = Identifier,
};
}
}
+4 -6
View File
@@ -12,6 +12,7 @@ using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Internal.Notifications;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Utility;
using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Component.GUI;
@@ -73,14 +74,14 @@ public sealed class PayloadHandler {
var (chunk, payload) = Popup.Value;
if (!ImGui.BeginPopup(PopupId))
using var popup = ImRaii.Popup(PopupId);
if (!popup.Success)
{
Popup = null;
return;
}
ImGui.PushID(PopupId);
using var id = ImRaii.PushId(PopupId);
var drawn = false;
switch (payload)
{
@@ -100,9 +101,6 @@ public sealed class PayloadHandler {
ContextFooter(drawn, chunk);
Integrations(chunk, payload);
ImGui.PopID();
ImGui.EndPopup();
}
private void Integrations(Chunk chunk, Payload? payload)
+3 -3
View File
@@ -1157,7 +1157,7 @@ public sealed class ChatLogWindow : Window
}
internal readonly List<bool> PopOutDocked = [];
internal readonly Dictionary<string, Window> PopOutWindows = new();
internal readonly HashSet<Guid> PopOutWindows = [];
private void AddPopOutsToDraw()
{
HandlerLender.ResetCounter();
@@ -1174,13 +1174,13 @@ public sealed class ChatLogWindow : Window
if (!tab.PopOut)
continue;
if (PopOutWindows.ContainsKey($"{tab.Name}{i}"))
if (PopOutWindows.Contains(tab.Identifier))
continue;
var window = new Popout(this, tab, i);
Plugin.WindowSystem.AddWindow(window);
PopOutWindows.Add($"{tab.Name}{i}", window);
PopOutWindows.Add(tab.Identifier);
}
}
+10 -3
View File
@@ -26,6 +26,12 @@ internal class Popout : Window
DisableWindowSounds = true;
}
public override void PreOpenCheck()
{
if (!Tab.PopOut)
IsOpen = false;
}
public override bool DrawConditions()
{
return !ChatLogWindow.IsHidden;
@@ -48,9 +54,10 @@ internal class Popout : Window
public override void Draw()
{
using var id = ImRaii.PushId($"popout-{Tab.Name}");
using var id = ImRaii.PushId($"popout-{Tab.Identifier}");
if (!ChatLogWindow.Plugin.Config.ShowPopOutTitleBar) {
if (!ChatLogWindow.Plugin.Config.ShowPopOutTitleBar)
{
ImGui.TextUnformatted(Tab.Name);
ImGui.Separator();
}
@@ -69,7 +76,7 @@ internal class Popout : Window
public override void OnClose()
{
ChatLogWindow.PopOutWindows.Remove($"{Tab.Name}{Idx}");
ChatLogWindow.PopOutWindows.Remove(Tab.Identifier);
ChatLogWindow.Plugin.WindowSystem.RemoveWindow(this);
Tab.PopOut = false;
+2 -2
View File
@@ -65,7 +65,7 @@ public sealed class SettingsWindow : Window
private void Initialise()
{
Mutable.UpdateFrom(Plugin.Config);
Mutable.UpdateFrom(Plugin.Config, false);
}
public override void Draw()
@@ -153,7 +153,7 @@ public sealed class SettingsWindow : Window
|| Math.Abs(Mutable.JapaneseFontSize - Plugin.Config.JapaneseFontSize) > 0.001
|| Math.Abs(Mutable.SymbolsFontSize - Plugin.Config.SymbolsFontSize) > 0.001;
Plugin.Config.UpdateFrom(Mutable);
Plugin.Config.UpdateFrom(Mutable, true);
// save after 60 frames have passed, which should hopefully not
// commit any changes that cause a crash