Merge remote-tracking branch 'origin/master' into v9-rollup

This commit is contained in:
github-actions[bot] 2023-09-10 21:53:08 +00:00
commit 38a4a7f580
36 changed files with 1336 additions and 279 deletions

View file

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Dalamud.Networking.Http;
using Dalamud.Plugin.Internal;
using Dalamud.Utility;
using Serilog;
namespace Dalamud.Interface.Internal.Windows.PluginInstaller;
@ -44,27 +45,35 @@ internal class DalamudChangelogManager
this.Changelogs = null;
var dalamudChangelogs = await client.GetFromJsonAsync<List<DalamudChangelog>>(DalamudChangelogUrl);
var changelogs = dalamudChangelogs.Select(x => new DalamudChangelogEntry(x)).Cast<IChangelogEntry>();
var changelogs = dalamudChangelogs.Select(x => new DalamudChangelogEntry(x)).Cast<IChangelogEntry>().ToList();
foreach (var plugin in this.manager.InstalledPlugins)
{
if (!plugin.IsThirdParty)
if (!plugin.IsThirdParty && !plugin.IsDev)
{
var pluginChangelogs = await client.GetFromJsonAsync<PluginHistory>(string.Format(
PluginChangelogUrl,
plugin.Manifest.InternalName,
plugin.Manifest.Dip17Channel));
try
{
var pluginChangelogs = await client.GetFromJsonAsync<PluginHistory>(string.Format(
PluginChangelogUrl,
plugin.Manifest.InternalName,
plugin.Manifest.Dip17Channel));
changelogs = changelogs.Concat(pluginChangelogs.Versions
.Where(x => x.Dip17Track == plugin.Manifest.Dip17Channel)
.Select(x => new PluginChangelogEntry(plugin, x)));
changelogs.AddRange(pluginChangelogs.Versions
.Where(x => x.Dip17Track ==
plugin.Manifest.Dip17Channel)
.Select(x => new PluginChangelogEntry(plugin, x)));
}
catch (Exception ex)
{
Log.Error(ex, "Failed to load changelog for {PluginName}", plugin.Manifest.Name);
}
}
else
{
if (plugin.Manifest.Changelog.IsNullOrWhitespace())
continue;
changelogs = changelogs.Append(new PluginChangelogEntry(plugin));
changelogs.Add(new PluginChangelogEntry(plugin));
}
}

View file

@ -109,7 +109,9 @@ internal class PluginInstallerWindow : Window, IDisposable
private OperationStatus installStatus = OperationStatus.Idle;
private OperationStatus updateStatus = OperationStatus.Idle;
private OperationStatus enableDisableStatus = OperationStatus.Idle;
private Guid enableDisableWorkingPluginId = Guid.Empty;
private LoadingIndicatorKind loadingIndicatorKind = LoadingIndicatorKind.Unknown;
@ -968,7 +970,14 @@ internal class PluginInstallerWindow : Window, IDisposable
{
this.dalamudChangelogRefreshTaskCts = new CancellationTokenSource();
this.dalamudChangelogRefreshTask =
Task.Run(this.dalamudChangelogManager.ReloadChangelogAsync, this.dalamudChangelogRefreshTaskCts.Token);
Task.Run(this.dalamudChangelogManager.ReloadChangelogAsync, this.dalamudChangelogRefreshTaskCts.Token)
.ContinueWith(t =>
{
if (!t.IsCompletedSuccessfully)
{
Log.Error(t.Exception, "Failed to load changelogs.");
}
});
}
return;
@ -1431,7 +1440,7 @@ internal class PluginInstallerWindow : Window, IDisposable
ImGui.Button($"{buttonText}##{buttonText}testing");
}
this.DrawVisitRepoUrlButton("https://google.com");
this.DrawVisitRepoUrlButton("https://google.com", true);
if (this.testerImages != null)
{
@ -1948,6 +1957,7 @@ internal class PluginInstallerWindow : Window, IDisposable
}
else
{
using var color = ImRaii.PushColor(ImGuiCol.Button, ImGuiColors.DalamudRed.Darken(0.3f).Fade(0.4f));
var buttonText = Locs.PluginButton_InstallVersion(versionString);
if (ImGui.Button($"{buttonText}##{buttonText}{index}"))
{
@ -1955,11 +1965,19 @@ internal class PluginInstallerWindow : Window, IDisposable
}
}
this.DrawVisitRepoUrlButton(manifest.RepoUrl);
ImGui.SameLine();
ImGuiHelpers.ScaledDummy(10);
ImGui.SameLine();
this.DrawVisitRepoUrlButton(manifest.RepoUrl, true);
ImGui.SameLine();
ImGuiHelpers.ScaledDummy(3);
ImGui.SameLine();
if (!manifest.SourceRepo.IsThirdParty && manifest.AcceptsFeedback)
{
this.DrawSendFeedbackButton(manifest, false);
this.DrawSendFeedbackButton(manifest, false, true);
}
ImGuiHelpers.ScaledDummy(5);
@ -2143,6 +2161,7 @@ internal class PluginInstallerWindow : Window, IDisposable
ImGui.PushID($"installed{index}{plugin.Manifest.InternalName}");
var hasChangelog = !plugin.Manifest.Changelog.IsNullOrEmpty();
var didDrawChangelogInsideCollapsible = false;
if (this.DrawPluginCollapsingHeader(label, plugin, plugin.Manifest, plugin.IsThirdParty, trouble, availablePluginUpdate != default, false, false, plugin.IsOrphaned, () => this.DrawInstalledPluginContextMenu(plugin, testingOptIn), index))
{
@ -2220,18 +2239,20 @@ internal class PluginInstallerWindow : Window, IDisposable
{
ImGuiHelpers.SafeTextWrapped($"{command.Key} → {command.Value.HelpMessage}");
}
ImGuiHelpers.ScaledDummy(3);
}
}
// Controls
this.DrawPluginControlButton(plugin, availablePluginUpdate);
this.DrawDevPluginButtons(plugin);
this.DrawVisitRepoUrlButton(plugin.Manifest.RepoUrl, false);
this.DrawDeletePluginButton(plugin);
this.DrawVisitRepoUrlButton(plugin.Manifest.RepoUrl);
if (canFeedback)
{
this.DrawSendFeedbackButton(plugin.Manifest, plugin.IsTesting);
this.DrawSendFeedbackButton(plugin.Manifest, plugin.IsTesting, false);
}
if (availablePluginUpdate != default && !plugin.IsDev)
@ -2251,6 +2272,7 @@ internal class PluginInstallerWindow : Window, IDisposable
{
if (ImGui.TreeNode(Locs.PluginBody_CurrentChangeLog(plugin.EffectiveVersion)))
{
didDrawChangelogInsideCollapsible = true;
this.DrawInstalledPluginChangelog(plugin.Manifest);
ImGui.TreePop();
}
@ -2267,7 +2289,7 @@ internal class PluginInstallerWindow : Window, IDisposable
}
}
if (thisWasUpdated && hasChangelog)
if (thisWasUpdated && hasChangelog && !didDrawChangelogInsideCollapsible)
{
this.DrawInstalledPluginChangelog(plugin.Manifest);
}
@ -2360,6 +2382,10 @@ internal class PluginInstallerWindow : Window, IDisposable
var config = Service<DalamudConfiguration>.Get();
var applicableForProfiles = plugin.Manifest.SupportsProfiles && !plugin.IsDev;
var profilesThatWantThisPlugin = profileManager.Profiles
.Where(x => x.WantsPlugin(plugin.InternalName) != null)
.ToArray();
var isInSingleProfile = profilesThatWantThisPlugin.Length == 1;
var isDefaultPlugin = profileManager.IsInDefaultProfile(plugin.Manifest.InternalName);
// Disable everything if the updater is running or another plugin is operating
@ -2443,6 +2469,10 @@ internal class PluginInstallerWindow : Window, IDisposable
ImGui.EndPopup();
}
var inMultipleProfiles = !isDefaultPlugin && !isInSingleProfile;
var inSingleNonDefaultProfileWhichIsDisabled =
isInSingleProfile && !profilesThatWantThisPlugin.First().IsEnabled;
if (plugin.State is PluginState.UnloadError or PluginState.LoadError or PluginState.DependencyResolutionFailed && !plugin.IsDev)
{
ImGuiComponents.DisabledButton(FontAwesomeIcon.Frown);
@ -2450,80 +2480,83 @@ internal class PluginInstallerWindow : Window, IDisposable
if (ImGui.IsItemHovered())
ImGui.SetTooltip(Locs.PluginButtonToolTip_UnloadFailed);
}
else if (disabled || !isDefaultPlugin)
else if (this.enableDisableStatus == OperationStatus.InProgress && this.enableDisableWorkingPluginId == plugin.Manifest.WorkingPluginId)
{
ImGuiComponents.DisabledToggleButton(toggleId, this.loadingIndicatorKind == LoadingIndicatorKind.EnablingSingle);
}
else if (disabled || inMultipleProfiles || inSingleNonDefaultProfileWhichIsDisabled)
{
ImGuiComponents.DisabledToggleButton(toggleId, isLoadedAndUnloadable);
if (!isDefaultPlugin && ImGui.IsItemHovered())
ImGui.SetTooltip(Locs.PluginButtonToolTip_NeedsToBeInDefault);
if (inMultipleProfiles && ImGui.IsItemHovered())
ImGui.SetTooltip(Locs.PluginButtonToolTip_NeedsToBeInSingleProfile);
else if (inSingleNonDefaultProfileWhichIsDisabled && ImGui.IsItemHovered())
ImGui.SetTooltip(Locs.PluginButtonToolTip_SingleProfileDisabled(profilesThatWantThisPlugin.First().Name));
}
else
{
if (ImGuiComponents.ToggleButton(toggleId, ref isLoadedAndUnloadable))
{
// TODO: We can technically let profile manager take care of unloading/loading the plugin, but we should figure out error handling first.
var applicableProfile = profilesThatWantThisPlugin.First();
Log.Verbose("Switching {InternalName} in {Profile} to {State}",
plugin.InternalName, applicableProfile, isLoadedAndUnloadable);
try
{
// Reload the devPlugin manifest if it's a dev plugin
// The plugin might rely on changed values in the manifest
if (plugin.IsDev)
{
plugin.ReloadManifest();
}
}
catch (Exception ex)
{
Log.Error(ex, "Could not reload DevPlugin manifest");
}
// NOTE: We don't use the profile manager to actually handle loading/unloading here,
// because that might cause us to show an error if a plugin we don't actually care about
// fails to load/unload. Instead, we just do it ourselves and then update the profile.
// There is probably a smarter way to handle this, but it's probably more code.
if (!isLoadedAndUnloadable)
{
this.enableDisableStatus = OperationStatus.InProgress;
this.loadingIndicatorKind = LoadingIndicatorKind.DisablingSingle;
this.enableDisableWorkingPluginId = plugin.Manifest.WorkingPluginId;
Task.Run(() =>
Task.Run(async () =>
{
if (plugin.IsDev)
{
plugin.ReloadManifest();
}
var unloadTask = Task.Run(() => plugin.UnloadAsync())
.ContinueWith(this.DisplayErrorContinuation, Locs.ErrorModal_UnloadFail(plugin.Name));
unloadTask.Wait();
if (!unloadTask.Result)
{
this.enableDisableStatus = OperationStatus.Complete;
return;
}
// TODO: Work this out
Task.Run(() => profileManager.DefaultProfile.AddOrUpdateAsync(plugin.Manifest.InternalName, false, false))
.GetAwaiter().GetResult();
this.enableDisableStatus = OperationStatus.Complete;
await plugin.UnloadAsync();
await applicableProfile.AddOrUpdateAsync(
plugin.Manifest.InternalName, false, false);
notifications.AddNotification(Locs.Notifications_PluginDisabled(plugin.Manifest.Name), Locs.Notifications_PluginDisabledTitle, NotificationType.Success);
}).ContinueWith(t =>
{
this.enableDisableStatus = OperationStatus.Complete;
this.DisplayErrorContinuation(t, Locs.ErrorModal_UnloadFail(plugin.Name));
});
}
else
{
var enabler = new Task(() =>
async Task Enabler()
{
this.enableDisableStatus = OperationStatus.InProgress;
this.loadingIndicatorKind = LoadingIndicatorKind.EnablingSingle;
this.enableDisableWorkingPluginId = plugin.Manifest.WorkingPluginId;
if (plugin.IsDev)
{
plugin.ReloadManifest();
}
await applicableProfile.AddOrUpdateAsync(plugin.Manifest.InternalName, true, false);
await plugin.LoadAsync(PluginLoadReason.Installer);
// TODO: Work this out
Task.Run(() => profileManager.DefaultProfile.AddOrUpdateAsync(plugin.Manifest.InternalName, true, false))
.GetAwaiter().GetResult();
notifications.AddNotification(Locs.Notifications_PluginEnabled(plugin.Manifest.Name), Locs.Notifications_PluginEnabledTitle, NotificationType.Success);
}
var loadTask = Task.Run(() => plugin.LoadAsync(PluginLoadReason.Installer))
.ContinueWith(
this.DisplayErrorContinuation,
Locs.ErrorModal_LoadFail(plugin.Name));
loadTask.Wait();
var continuation = (Task t) =>
{
this.enableDisableStatus = OperationStatus.Complete;
if (!loadTask.Result)
return;
notifications.AddNotification(
Locs.Notifications_PluginEnabled(plugin.Manifest.Name),
Locs.Notifications_PluginEnabledTitle,
NotificationType.Success);
});
this.DisplayErrorContinuation(t, Locs.ErrorModal_LoadFail(plugin.Name));
};
if (availableUpdate != default && !availableUpdate.InstalledPlugin.IsDev)
{
@ -2533,17 +2566,19 @@ internal class PluginInstallerWindow : Window, IDisposable
if (shouldUpdate)
{
// We need to update the profile right here, because PM will not enable the plugin otherwise
await applicableProfile.AddOrUpdateAsync(plugin.InternalName, true, false);
await this.UpdateSinglePlugin(availableUpdate);
}
else
{
enabler.Start();
_ = Task.Run(Enabler).ContinueWith(continuation);
}
});
}
else
{
enabler.Start();
_ = Task.Run(Enabler).ContinueWith(continuation);
}
}
}
@ -2558,6 +2593,9 @@ internal class PluginInstallerWindow : Window, IDisposable
{
// Only if the plugin isn't broken.
this.DrawOpenPluginSettingsButton(plugin);
ImGui.SameLine();
ImGuiHelpers.ScaledDummy(5, 0);
}
if (applicableForProfiles && config.ProfilesEnabled)
@ -2622,10 +2660,39 @@ internal class PluginInstallerWindow : Window, IDisposable
private void DrawOpenPluginSettingsButton(LocalPlugin plugin)
{
if (plugin.DalamudInterface?.UiBuilder?.HasConfigUi ?? false)
var hasMainUi = plugin.DalamudInterface?.UiBuilder.HasMainUi ?? false;
var hasConfig = plugin.DalamudInterface?.UiBuilder.HasConfigUi ?? false;
if (hasMainUi)
{
ImGui.SameLine();
if (ImGuiComponents.IconButton(FontAwesomeIcon.Cog))
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.ArrowUpRightFromSquare, Locs.PluginButton_OpenUi))
{
try
{
plugin.DalamudInterface.UiBuilder.OpenMain();
}
catch (Exception ex)
{
Log.Error(ex, $"Error during OpenMain(): {plugin.Name}");
}
}
if (ImGui.IsItemHovered())
{
ImGui.SetTooltip(Locs.PluginButtonToolTip_OpenUi);
}
}
if (hasConfig)
{
if (hasMainUi)
{
ImGui.SameLine();
ImGuiHelpers.ScaledDummy(5, 0);
}
ImGui.SameLine();
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Cog, Locs.PluginButton_OpenSettings))
{
try
{
@ -2633,7 +2700,7 @@ internal class PluginInstallerWindow : Window, IDisposable
}
catch (Exception ex)
{
Log.Error(ex, $"Error during OpenConfigUi: {plugin.Name}");
Log.Error(ex, $"Error during OpenConfig: {plugin.Name}");
}
}
@ -2644,10 +2711,15 @@ internal class PluginInstallerWindow : Window, IDisposable
}
}
private void DrawSendFeedbackButton(IPluginManifest manifest, bool isTesting)
private void DrawSendFeedbackButton(IPluginManifest manifest, bool isTesting, bool big)
{
ImGui.SameLine();
if (ImGuiComponents.IconButton(FontAwesomeIcon.Comment))
var clicked = big ?
ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Comment, Locs.FeedbackModal_Title) :
ImGuiComponents.IconButton(FontAwesomeIcon.Comment);
if (clicked)
{
this.feedbackPlugin = manifest;
this.feedbackModalOnNextFrame = true;
@ -2793,12 +2865,16 @@ internal class PluginInstallerWindow : Window, IDisposable
}
}
private void DrawVisitRepoUrlButton(string? repoUrl)
private void DrawVisitRepoUrlButton(string? repoUrl, bool big)
{
if (!string.IsNullOrEmpty(repoUrl) && repoUrl.StartsWith("https://"))
{
ImGui.SameLine();
if (ImGuiComponents.IconButton(FontAwesomeIcon.Globe))
var clicked = big ?
ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Globe, "Open website") :
ImGuiComponents.IconButton(FontAwesomeIcon.Globe);
if (clicked)
{
try
{
@ -3221,12 +3297,18 @@ internal class PluginInstallerWindow : Window, IDisposable
public static string PluginButton_Unload => Loc.Localize("InstallerUnload", "Unload");
public static string PluginButton_SafeMode => Loc.Localize("InstallerSafeModeButton", "Can't change in safe mode");
public static string PluginButton_OpenUi => Loc.Localize("InstallerOpenPluginUi", "Open");
public static string PluginButton_OpenSettings => Loc.Localize("InstallerOpenPluginSettings", "Settings");
#endregion
#region Plugin button tooltips
public static string PluginButtonToolTip_OpenUi => Loc.Localize("InstallerTooltipOpenUi", "Open this plugin's interface");
public static string PluginButtonToolTip_OpenConfiguration => Loc.Localize("InstallerOpenConfig", "Open Configuration");
public static string PluginButtonToolTip_OpenConfiguration => Loc.Localize("InstallerTooltipOpenConfig", "Open this plugin's settings");
public static string PluginButtonToolTip_PickProfiles => Loc.Localize("InstallerPickProfiles", "Pick collections for this plugin");
@ -3253,6 +3335,10 @@ internal class PluginInstallerWindow : Window, IDisposable
public static string PluginButtonToolTip_UnloadFailed => Loc.Localize("InstallerLoadUnloadFailedTooltip", "Plugin load/unload failed, please restart your game and try again.");
public static string PluginButtonToolTip_NeedsToBeInDefault => Loc.Localize("InstallerUnloadNeedsToBeInDefault", "This plugin is in one or more collections. If you want to enable or disable it, please do so by enabling or disabling the collections it is in.\nIf you want to manage it manually, remove it from all collections.");
public static string PluginButtonToolTip_NeedsToBeInSingleProfile => Loc.Localize("InstallerUnloadNeedsToBeInSingleProfile", "This plugin is in more than one collection. If you want to enable or disable it, please do so by enabling or disabling the collections it is in.\nIf you want to manage it here, make sure it is only in a single collection.");
public static string PluginButtonToolTip_SingleProfileDisabled(string name) => Loc.Localize("InstallerSingleProfileDisabled", "The collection '{0}' which contains this plugin is disabled.\nPlease enable it in the collections manager to toggle the plugin individually.").Format(name);
#endregion

View file

@ -79,7 +79,7 @@ internal class ProfileManagerWidget
private void DrawTutorial(string modalTitle)
{
var open = true;
ImGui.SetNextWindowSize(new Vector2(450, 350), ImGuiCond.Appearing);
ImGui.SetNextWindowSize(new Vector2(650, 550), ImGuiCond.Appearing);
using (var popup = ImRaii.PopupModal(modalTitle, ref open))
{
if (popup)