From f482badd8ee009cabb2568195669249aefd9d011 Mon Sep 17 00:00:00 2001 From: goaaats Date: Fri, 25 Apr 2025 18:53:30 +0200 Subject: [PATCH] Add progress bar to boot plugin loads, show which are pending --- .../Interface/Internal/DalamudInterface.cs | 7 +- .../PluginInstaller/PluginInstallerWindow.cs | 69 ++++++++++++------- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/Dalamud/Interface/Internal/DalamudInterface.cs b/Dalamud/Interface/Internal/DalamudInterface.cs index 42907016f..f010e3496 100644 --- a/Dalamud/Interface/Internal/DalamudInterface.cs +++ b/Dalamud/Interface/Internal/DalamudInterface.cs @@ -9,7 +9,6 @@ using System.Runtime.InteropServices; using CheapLoc; using Dalamud.Configuration.Internal; using Dalamud.Console; -using Dalamud.Data; using Dalamud.Game.Addon.Lifecycle; using Dalamud.Game.ClientState; using Dalamud.Game.ClientState.Conditions; @@ -46,12 +45,10 @@ using ImPlotNET; using PInvoke; using Serilog.Events; -using Task = System.Threading.Tasks.Task; - namespace Dalamud.Interface.Internal; /// -/// This plugin implements all of the Dalamud interface separately, to allow for reloading of the interface and rapid prototyping. +/// This plugin implements all the Dalamud interface separately, to allow for reloading of the interface and rapid prototyping. /// [ServiceManager.EarlyLoadedService] internal class DalamudInterface : IInternalDisposableService @@ -1015,7 +1012,7 @@ internal class DalamudInterface : IInternalDisposableService if (ImGui.MenuItem("Scan dev plugins")) { - Task.Run(pluginManager.ScanDevPluginsAsync); + _ = pluginManager.ScanDevPluginsAsync(); } ImGui.Separator(); diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs index 6868827b4..091142bc3 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs @@ -473,6 +473,36 @@ internal class PluginInstallerWindow : Window, IDisposable configuration.QueueSave(); } + private static void DrawProgressBar(IEnumerable items, Func pendingFunc, Func totalFunc, Action renderPending) + { + var windowSize = ImGui.GetWindowSize(); + + var numLoaded = 0; + var total = 0; + + var itemsArray = items as T[] ?? items.ToArray(); + var allPending = itemsArray.Where(pendingFunc) + .ToArray(); + var allLoadedOrLoading = itemsArray.Count(totalFunc); + + // Cap number of items we show to avoid clutter + const int maxShown = 3; + foreach (var repo in allPending.Take(maxShown)) + { + renderPending(repo); + } + + ImGuiHelpers.ScaledDummy(10); + + numLoaded += allLoadedOrLoading - allPending.Length; + total += allLoadedOrLoading; + if (numLoaded != total) + { + ImGui.SetCursorPosX(windowSize.X / 3); + ImGui.ProgressBar(numLoaded / (float)total, new Vector2(windowSize.X / 3, 50), $"{numLoaded}/{total}"); + } + } + private void SetOpenPage(PluginInstallerOpenKind kind) { switch (kind) @@ -576,40 +606,29 @@ internal class PluginInstallerWindow : Window, IDisposable if (pluginManager.PluginsReady && !pluginManager.ReposReady) { ImGuiHelpers.CenteredText("Loading repositories..."); + ImGuiHelpers.ScaledDummy(10); + + DrawProgressBar(pluginManager.Repos, x => x.State != PluginRepositoryState.Success && + x.State != PluginRepositoryState.Fail && + x.IsEnabled, + x => x.IsEnabled, + x => ImGuiHelpers.CenteredText($"Loading {x.PluginMasterUrl}")); } else if (!pluginManager.PluginsReady && pluginManager.ReposReady) { ImGuiHelpers.CenteredText("Loading installed plugins..."); + ImGuiHelpers.ScaledDummy(10); + + DrawProgressBar(pluginManager.InstalledPlugins, x => x.State == PluginState.Loading, + x => x.State is PluginState.Loaded or + PluginState.LoadError or + PluginState.Loading, + x => ImGuiHelpers.CenteredText($"Loading {x.Name}")); } else { ImGuiHelpers.CenteredText("Loading repositories and plugins..."); } - - var currentProgress = 0; - var total = 0; - - var pendingRepos = pluginManager.Repos.ToArray() - .Where(x => (x.State != PluginRepositoryState.Success && - x.State != PluginRepositoryState.Fail) && - x.IsEnabled) - .ToArray(); - var allRepoCount = - pluginManager.Repos.Count(x => x.State != PluginRepositoryState.Fail && x.IsEnabled); - - foreach (var repo in pendingRepos) - { - ImGuiHelpers.CenteredText($"{repo.PluginMasterUrl}: {repo.State}"); - } - - currentProgress += allRepoCount - pendingRepos.Length; - total += allRepoCount; - - if (currentProgress != total) - { - ImGui.SetCursorPosX(windowSize.X / 3); - ImGui.ProgressBar(currentProgress / (float)total, new Vector2(windowSize.X / 3, 50)); - } } break;