From 285d3bed42642081dd04acc6d811116558f4303e Mon Sep 17 00:00:00 2001 From: goat Date: Tue, 16 Apr 2024 00:58:12 +0200 Subject: [PATCH] pi: properly support changelogs for testing plugins --- .../PluginInstaller/PluginInstallerWindow.cs | 63 +++++++++++-------- .../Types/Manifest/RemotePluginManifest.cs | 5 ++ 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs index 455c8e4d3..601348d07 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs @@ -1128,34 +1128,33 @@ internal class PluginInstallerWindow : Window, IDisposable this.DrawChangelog(logEntry); } } - - private record PluginInstallerAvailablePluginProxy(RemotePluginManifest? RemoteManifest, LocalPlugin? LocalPlugin); - + #pragma warning disable SA1201 - private void DrawAvailablePluginList() -#pragma warning restore SA1201 + private record PluginInstallerAvailablePluginProxy(RemotePluginManifest? RemoteManifest, LocalPlugin? LocalPlugin); + + private IEnumerable GatherProxies() { + var proxies = new List(); + var availableManifests = this.pluginListAvailable; var installedPlugins = this.pluginListInstalled.ToList(); // Copy intended if (availableManifests.Count == 0) { ImGui.TextColored(ImGuiColors.DalamudGrey, Locs.TabBody_SearchNoCompatible); - return; + return proxies; } var filteredAvailableManifests = availableManifests - .Where(rm => !this.IsManifestFiltered(rm)) - .ToList(); + .Where(rm => !this.IsManifestFiltered(rm)) + .ToList(); if (filteredAvailableManifests.Count == 0) { ImGui.TextColored(ImGuiColors.DalamudGrey2, Locs.TabBody_SearchNoMatching); - return; + return proxies; } - var proxies = new List(); - // Go through all AVAILABLE manifests, associate them with a NON-DEV local plugin, if one is available, and remove it from the pile foreach (var availableManifest in this.categoryManager.GetCurrentCategoryContent(filteredAvailableManifests).Cast()) { @@ -1168,7 +1167,7 @@ internal class PluginInstallerWindow : Window, IDisposable if (plugin != null) { installedPlugins.Remove(plugin); - proxies.Add(new PluginInstallerAvailablePluginProxy(null, plugin)); + proxies.Add(new PluginInstallerAvailablePluginProxy(availableManifest, plugin)); continue; } @@ -1187,8 +1186,14 @@ internal class PluginInstallerWindow : Window, IDisposable proxies.Add(new PluginInstallerAvailablePluginProxy(null, installedPlugin)); } + return proxies; + } +#pragma warning restore SA1201 + + private void DrawAvailablePluginList() + { var i = 0; - foreach (var proxy in proxies) + foreach (var proxy in this.GatherProxies()) { IPluginManifest applicableManifest = proxy.LocalPlugin != null ? proxy.LocalPlugin.Manifest : proxy.RemoteManifest; @@ -1199,7 +1204,7 @@ internal class PluginInstallerWindow : Window, IDisposable if (proxy.LocalPlugin != null) { - this.DrawInstalledPlugin(proxy.LocalPlugin, i++, true); + this.DrawInstalledPlugin(proxy.LocalPlugin, i++, proxy.RemoteManifest, true); } else if (proxy.RemoteManifest != null) { @@ -1237,7 +1242,12 @@ internal class PluginInstallerWindow : Window, IDisposable if (filterTesting && !manager.HasTestingOptIn(plugin.Manifest)) continue; - this.DrawInstalledPlugin(plugin, i++); + // Find the applicable remote manifest + var remoteManifest = this.pluginListAvailable + .FirstOrDefault(rm => rm.InternalName == plugin.Manifest.InternalName && + rm.RepoUrl == plugin.Manifest.RepoUrl); + + this.DrawInstalledPlugin(plugin, i++, remoteManifest); } } @@ -1266,7 +1276,7 @@ internal class PluginInstallerWindow : Window, IDisposable var i = 0; foreach (var plugin in filteredList) { - this.DrawInstalledPlugin(plugin, i++); + this.DrawInstalledPlugin(plugin, i++, null); } } @@ -2251,7 +2261,7 @@ internal class PluginInstallerWindow : Window, IDisposable } } - private void DrawInstalledPlugin(LocalPlugin plugin, int index, bool showInstalled = false) + private void DrawInstalledPlugin(LocalPlugin plugin, int index, RemotePluginManifest? remoteManifest, bool showInstalled = false) { var configuration = Service.Get(); var commandManager = Service.Get(); @@ -2376,7 +2386,9 @@ internal class PluginInstallerWindow : Window, IDisposable } ImGui.PushID($"installed{index}{plugin.Manifest.InternalName}"); - var hasChangelog = !plugin.Manifest.Changelog.IsNullOrEmpty(); + + var applicableChangelog = plugin.IsTesting ? remoteManifest?.Changelog : remoteManifest?.TestingChangelog; + var hasChangelog = !applicableChangelog.IsNullOrWhitespace(); var didDrawChangelogInsideCollapsible = false; if (this.DrawPluginCollapsingHeader(label, plugin, plugin.Manifest, plugin.IsThirdParty, trouble, availablePluginUpdate != default, false, false, plugin.IsOrphaned, () => this.DrawInstalledPluginContextMenu(plugin, testingOptIn), index)) @@ -2489,12 +2501,12 @@ internal class PluginInstallerWindow : Window, IDisposable ImGui.Unindent(); - if (hasChangelog) + if (!applicableChangelog.IsNullOrWhitespace()) { if (ImGui.TreeNode(Locs.PluginBody_CurrentChangeLog(plugin.EffectiveVersion))) { didDrawChangelogInsideCollapsible = true; - this.DrawInstalledPluginChangelog(plugin.Manifest); + this.DrawInstalledPluginChangelog(applicableChangelog); ImGui.TreePop(); } } @@ -2502,9 +2514,10 @@ internal class PluginInstallerWindow : Window, IDisposable if (availablePluginUpdate != default && !availablePluginUpdate.UpdateManifest.Changelog.IsNullOrWhitespace()) { var availablePluginUpdateVersion = availablePluginUpdate.UseTesting ? availablePluginUpdate.UpdateManifest.TestingAssemblyVersion : availablePluginUpdate.UpdateManifest.AssemblyVersion; - if (ImGui.TreeNode(Locs.PluginBody_UpdateChangeLog(availablePluginUpdateVersion))) + var availableChangelog = availablePluginUpdate.UseTesting ? availablePluginUpdate.UpdateManifest.TestingChangelog : availablePluginUpdate.UpdateManifest.Changelog; + if (!availableChangelog.IsNullOrWhitespace() && ImGui.TreeNode(Locs.PluginBody_UpdateChangeLog(availablePluginUpdateVersion))) { - this.DrawInstalledPluginChangelog(availablePluginUpdate.UpdateManifest); + this.DrawInstalledPluginChangelog(availableChangelog); ImGui.TreePop(); } } @@ -2512,13 +2525,13 @@ internal class PluginInstallerWindow : Window, IDisposable if (thisWasUpdated && hasChangelog && !didDrawChangelogInsideCollapsible) { - this.DrawInstalledPluginChangelog(plugin.Manifest); + this.DrawInstalledPluginChangelog(applicableChangelog); } ImGui.PopID(); } - private void DrawInstalledPluginChangelog(IPluginManifest manifest) + private void DrawInstalledPluginChangelog(string changelog) { ImGuiHelpers.ScaledDummy(5); @@ -2531,7 +2544,7 @@ internal class PluginInstallerWindow : Window, IDisposable { ImGui.Text("Changelog:"); ImGuiHelpers.ScaledDummy(2); - ImGuiHelpers.SafeTextWrapped(manifest.Changelog!); + ImGuiHelpers.SafeTextWrapped(changelog!); } ImGui.EndChild(); diff --git a/Dalamud/Plugin/Internal/Types/Manifest/RemotePluginManifest.cs b/Dalamud/Plugin/Internal/Types/Manifest/RemotePluginManifest.cs index 952650c72..e3d99a85a 100644 --- a/Dalamud/Plugin/Internal/Types/Manifest/RemotePluginManifest.cs +++ b/Dalamud/Plugin/Internal/Types/Manifest/RemotePluginManifest.cs @@ -16,6 +16,11 @@ internal record RemotePluginManifest : PluginManifest /// [JsonIgnore] public PluginRepository SourceRepo { get; set; } = null!; + + /// + /// Gets or sets the changelog to be shown when obtaining the testing version of the plugin. + /// + public string? TestingChangelog { get; set; } /// /// Gets a value indicating whether this plugin is eligible for testing.