From 725fe449f89c7881286537d429eb842a15422652 Mon Sep 17 00:00:00 2001 From: Infi Date: Mon, 2 Sep 2024 12:46:09 +0200 Subject: [PATCH] - Support locked channels - Implement render limit for webinterface [default 1000] --- ChatTwo/ChatTwo.csproj | 2 +- ChatTwo/Configuration.cs | 6 ++++-- ChatTwo/Http/MessageProtocol/DataStructure.cs | 5 +++-- ChatTwo/Http/Processing.cs | 11 ++++++----- ChatTwo/Http/static/start.js | 19 ++++++++++++++++--- ChatTwo/Resources/Language.Designer.cs | 18 ++++++++++++++++++ ChatTwo/Resources/Language.resx | 6 ++++++ ChatTwo/Ui/SettingsTabs/ChatLog.cs | 3 ++- ChatTwo/Ui/SettingsTabs/Webinterface.cs | 4 ++++ 9 files changed, 60 insertions(+), 14 deletions(-) diff --git a/ChatTwo/ChatTwo.csproj b/ChatTwo/ChatTwo.csproj index d1bccab..3959c63 100755 --- a/ChatTwo/ChatTwo.csproj +++ b/ChatTwo/ChatTwo.csproj @@ -1,6 +1,6 @@ - 1.29.0 + 1.29.1 net8.0-windows enable enable diff --git a/ChatTwo/Configuration.cs b/ChatTwo/Configuration.cs index 4207302..da72e85 100755 --- a/ChatTwo/Configuration.cs +++ b/ChatTwo/Configuration.cs @@ -75,7 +75,7 @@ internal class Configuration : IPluginConfiguration public bool CollapseDuplicateMessages; public bool PlaySounds = true; public bool KeepInputFocus = true; - public int MaxLinesToRender = 10_000; + public int MaxLinesToRender = 10_000; // 1-10000 public bool Use24HourClock; public bool ShowEmotes = true; @@ -96,7 +96,7 @@ internal class Configuration : IPluginConfiguration FontId = new DalamudAssetFontAndFamilyId(DalamudAsset.NotoSansJpMedium), SizePt = 12.75f, }; - public bool ItalicEnabled = false; + public bool ItalicEnabled; public SingleFontSpec ItalicFontV2 = new() { FontId = new DalamudAssetFontAndFamilyId(DalamudAsset.NotoSansKrRegular), @@ -120,6 +120,7 @@ internal class Configuration : IPluginConfiguration public string WebinterfacePassword = WebinterfaceUtil.GenerateSimpleAuthCode(); public int WebinterfacePort = 9000; public ConcurrentDictionary SessionTokens = []; + public int WebinterfaceMaxLinesToSend = 1000; // 1-10000 internal void UpdateFrom(Configuration other, bool backToOriginal) { @@ -188,6 +189,7 @@ internal class Configuration : IPluginConfiguration WebinterfaceAutoStart = other.WebinterfaceAutoStart; WebinterfacePassword = other.WebinterfacePassword; WebinterfacePort = other.WebinterfacePort; + WebinterfaceMaxLinesToSend = other.WebinterfaceMaxLinesToSend; } } diff --git a/ChatTwo/Http/MessageProtocol/DataStructure.cs b/ChatTwo/Http/MessageProtocol/DataStructure.cs index e2abf77..5b3a8d1 100644 --- a/ChatTwo/Http/MessageProtocol/DataStructure.cs +++ b/ChatTwo/Http/MessageProtocol/DataStructure.cs @@ -6,9 +6,10 @@ namespace ChatTwo.Http.MessageProtocol; /// /// Contains the current channel name /// -public struct SwitchChannel(MessageTemplate[] channelName) +public struct SwitchChannel((MessageTemplate[] ChannelName, bool Locked) channel) { - [JsonProperty("channelName")] public MessageTemplate[] ChannelName = channelName; + [JsonProperty("channelName")] public MessageTemplate[] ChannelName = channel.ChannelName; + [JsonProperty("channelLocked")] public bool Locked = channel.Locked; } /// diff --git a/ChatTwo/Http/Processing.cs b/ChatTwo/Http/Processing.cs index 96ec3be..6040d76 100644 --- a/ChatTwo/Http/Processing.cs +++ b/ChatTwo/Http/Processing.cs @@ -15,15 +15,16 @@ public class Processing Plugin = plugin; } - internal MessageTemplate[] ReadChannelName(Chunk[] channelName) + internal (MessageTemplate[] ChannelName, bool Locked) ReadChannelName(Chunk[] channelName) { - return channelName.Select(ProcessChunk).ToArray(); + var locked = Plugin.ChatLogWindow.CurrentTab is not { Channel: null }; + return (channelName.Select(ProcessChunk).ToArray(), locked); } internal async Task ReadMessageList() { var tabMessages = await Plugin.ChatLogWindow.CurrentTab!.Messages.GetCopy(); - return tabMessages.Select(ReadMessageContent).ToArray(); + return tabMessages.TakeLast(Plugin.Config.WebinterfaceMaxLinesToSend).Select(ReadMessageContent).ToArray(); } internal MessageResponse ReadMessageContent(Message message) @@ -44,11 +45,11 @@ public class Processing { var messages = await WebserverUtil.FrameworkWrapper(ReadMessageList); var channels = await Plugin.Framework.RunOnTick(Plugin.ChatLogWindow.GetAvailableChannels); - var channelName = await Plugin.Framework.RunOnTick(() => ReadChannelName(Plugin.ChatLogWindow.PreviousChannel)); + var channel = await Plugin.Framework.RunOnTick(() => ReadChannelName(Plugin.ChatLogWindow.PreviousChannel)); // Using the bulk message event to clear everything on the client side that may still exist sse.OutboundQueue.Enqueue(new BulkMessagesEvent(new Messages(messages))); - sse.OutboundQueue.Enqueue(new SwitchChannelEvent(new SwitchChannel(channelName))); + sse.OutboundQueue.Enqueue(new SwitchChannelEvent(new SwitchChannel(channel))); sse.OutboundQueue.Enqueue(new ChannelListEvent(new ChannelList(channels.ToDictionary(pair => pair.Key, pair => (uint)pair.Value)))); } diff --git a/ChatTwo/Http/static/start.js b/ChatTwo/Http/static/start.js index 75be4d9..c8e1db6 100644 --- a/ChatTwo/Http/static/start.js +++ b/ChatTwo/Http/static/start.js @@ -20,6 +20,7 @@ }; this.maxTimestampWidth = 0; this.scrolledToBottom = true; + this.channelLocked = false; // channel selector @@ -72,9 +73,21 @@ }); } - updateChannelHint(templates) { + updateChannelHint(channel) { this.elements.channelHint.innerHTML = ''; - this.elements.channelHint.appendChild(this.processTemplate(templates)); + + const channelElement = this.processTemplate(channel.channelName); + + // Makes the channel selector unclickable if the channel is fixed + this.channelLocked = channel.channelLocked; + if (this.channelLocked) { + channelElement.firstChild.innerText = `(Locked) ${channelElement.firstChild.innerText}`; + this.elements.channelSelect.style.pointerEvents = 'none'; + } else { + this.elements.channelSelect.style.pointerEvents = 'auto'; + } + + this.elements.channelHint.appendChild(channelElement); } updateChannels(channels) { @@ -228,7 +241,7 @@ this.sse.addEventListener('switch-channel', (event) => { try { - this.updateChannelHint(JSON.parse(event.data).channelName); + this.updateChannelHint(JSON.parse(event.data)); } catch (error) { console.error(error); } diff --git a/ChatTwo/Resources/Language.Designer.cs b/ChatTwo/Resources/Language.Designer.cs index cfa6d22..0add0af 100755 --- a/ChatTwo/Resources/Language.Designer.cs +++ b/ChatTwo/Resources/Language.Designer.cs @@ -3533,6 +3533,24 @@ namespace ChatTwo.Resources { } } + /// + /// Looks up a localized string similar to Limits the amount of log lines to show in the webinterface. This will improve loading performance.. + /// + internal static string Options_WebinterfaceMaxLinesToSend_Description { + get { + return ResourceManager.GetString("Options_WebinterfaceMaxLinesToSend_Description", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Log line limit for the webinterface. + /// + internal static string Options_WebinterfaceMaxLinesToSend_Name { + get { + return ResourceManager.GetString("Options_WebinterfaceMaxLinesToSend_Name", resourceCulture); + } + } + /// /// Looks up a localized string similar to Window opacity. /// diff --git a/ChatTwo/Resources/Language.resx b/ChatTwo/Resources/Language.resx index ea818e8..c52cb97 100644 --- a/ChatTwo/Resources/Language.resx +++ b/ChatTwo/Resources/Language.resx @@ -1087,6 +1087,12 @@ Limits the amount of log lines to show in the chat window. This may slightly improve performance. + + Log line limit for the webinterface + + + Limits the amount of log lines to show in the webinterface. This will improve loading performance. + An error occurred while loading chat history. Please see plugin logs for more information to report this issue. diff --git a/ChatTwo/Ui/SettingsTabs/ChatLog.cs b/ChatTwo/Ui/SettingsTabs/ChatLog.cs index a1d834e..46455c8 100644 --- a/ChatTwo/Ui/SettingsTabs/ChatLog.cs +++ b/ChatTwo/Ui/SettingsTabs/ChatLog.cs @@ -50,7 +50,8 @@ internal sealed class ChatLog : ISettingsTab ImGuiUtil.DragFloatVertical(Language.Options_WindowOpacity_Name, ref Mutable.WindowAlpha, .25f, 0f, 100f, $"{Mutable.WindowAlpha:N2}%%", ImGuiSliderFlags.AlwaysClamp); ImGui.Spacing(); - if (ImGuiUtil.InputIntVertical(Language.Options_MaxLinesToShow_Name, Language.Options_MaxLinesToShow_Description, ref Mutable.MaxLinesToRender)) Mutable.MaxLinesToRender = Math.Clamp(Mutable.MaxLinesToRender, 1, 10_000); + if (ImGuiUtil.InputIntVertical(Language.Options_MaxLinesToShow_Name, Language.Options_MaxLinesToShow_Description, ref Mutable.MaxLinesToRender)) + Mutable.MaxLinesToRender = Math.Clamp(Mutable.MaxLinesToRender, 1, 10_000); ImGui.Spacing(); ImGuiUtil.OptionCheckbox(ref Mutable.CanMove, Language.Options_CanMove_Name); diff --git a/ChatTwo/Ui/SettingsTabs/Webinterface.cs b/ChatTwo/Ui/SettingsTabs/Webinterface.cs index 69479e0..854837d 100644 --- a/ChatTwo/Ui/SettingsTabs/Webinterface.cs +++ b/ChatTwo/Ui/SettingsTabs/Webinterface.cs @@ -54,6 +54,10 @@ internal sealed class Webinterface(Plugin plugin, Configuration mutable) : ISett Mutable.WebinterfacePort = Math.Clamp(Mutable.WebinterfacePort, 1024, 49151); ImGui.Spacing(); + if (ImGuiUtil.InputIntVertical(Language.Options_WebinterfaceMaxLinesToSend_Name, Language.Options_WebinterfaceMaxLinesToSend_Description, ref Mutable.WebinterfaceMaxLinesToSend)) + Mutable.WebinterfaceMaxLinesToSend = Math.Clamp(Mutable.WebinterfaceMaxLinesToSend, 1, 10_000); + ImGui.Spacing(); + ImGuiUtil.WrappedTextWithColor(ImGuiColors.DalamudOrange, Language.Webinterface_CurrentPassword); ImGui.AlignTextToFramePadding(); ImGui.TextUnformatted(Mutable.WebinterfacePassword);