fix: don't auto-update disabled plugins, don't let styles modify our toggle switch

This commit is contained in:
goat 2022-07-17 15:39:41 +02:00
parent 8c066451ec
commit f65ccca675
No known key found for this signature in database
GPG key ID: 7773BB5B43BA52E5
6 changed files with 112 additions and 18 deletions

View file

@ -292,7 +292,7 @@ namespace Dalamud.Game
this.hasAutoUpdatedPlugins = true; this.hasAutoUpdatedPlugins = true;
Task.Run(() => pluginManager.UpdatePluginsAsync(!this.configuration.AutoUpdatePlugins)).ContinueWith(task => Task.Run(() => pluginManager.UpdatePluginsAsync(true, !this.configuration.AutoUpdatePlugins)).ContinueWith(task =>
{ {
if (task.IsFaulted) if (task.IsFaulted)
{ {
@ -301,7 +301,7 @@ namespace Dalamud.Game
} }
var updatedPlugins = task.Result; var updatedPlugins = task.Result;
if (updatedPlugins != null && updatedPlugins.Any()) if (updatedPlugins.Any())
{ {
if (this.configuration.AutoUpdatePlugins) if (this.configuration.AutoUpdatePlugins)
{ {

View file

@ -36,10 +36,10 @@ namespace Dalamud.Interface.Components
} }
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
drawList.AddRectFilled(p, new Vector2(p.X + width, p.Y + height), ImGui.GetColorU32(v ? colors[(int)ImGuiCol.ButtonActive] : new Vector4(0.78f, 0.78f, 0.78f, 1.0f)), height * 0.5f); drawList.AddRectFilled(p, new Vector2(p.X + width, p.Y + height), ImGui.GetColorU32(!v ? colors[(int)ImGuiCol.ButtonActive] : new Vector4(0.78f, 0.78f, 0.78f, 1.0f)), height * 0.5f);
else else
drawList.AddRectFilled(p, new Vector2(p.X + width, p.Y + height), ImGui.GetColorU32(v ? colors[(int)ImGuiCol.Button] : new Vector4(0.55f, 0.55f, 0.55f, 1.0f)), height * 0.50f); drawList.AddRectFilled(p, new Vector2(p.X + width, p.Y + height), ImGui.GetColorU32(!v ? colors[(int)ImGuiCol.Button] * 0.6f : new Vector4(0.35f, 0.35f, 0.35f, 1.0f)), height * 0.50f);
drawList.AddCircleFilled(new Vector2(p.X + radius + ((v ? 1 : 0) * (width - (radius * 2.0f))), p.Y + radius), radius - 1.5f, ImGui.ColorConvertFloat4ToU32(new Vector4(255, 255, 255, 255))); drawList.AddCircleFilled(new Vector2(p.X + radius + ((v ? 1 : 0) * (width - (radius * 2.0f))), p.Y + radius), radius - 1.5f, ImGui.ColorConvertFloat4ToU32(new Vector4(1, 1, 1, 1)));
return changed; return changed;
} }
@ -60,13 +60,12 @@ namespace Dalamud.Interface.Components
var radius = height * 0.50f; var radius = height * 0.50f;
// TODO: animate // TODO: animate
// TODO: dim colors
ImGui.InvisibleButton(id, new Vector2(width, height)); ImGui.InvisibleButton(id, new Vector2(width, height));
var dimFactor = 0.5f; var dimFactor = 0.5f;
drawList.AddRectFilled(p, new Vector2(p.X + width, p.Y + height), ImGui.GetColorU32(v ? colors[(int)ImGuiCol.Button] * dimFactor : new Vector4(0.55f, 0.55f, 0.55f, 1.0f) * dimFactor), height * 0.50f); drawList.AddRectFilled(p, new Vector2(p.X + width, p.Y + height), ImGui.GetColorU32(v ? colors[(int)ImGuiCol.Button] * dimFactor : new Vector4(0.55f, 0.55f, 0.55f, 1.0f) * dimFactor), height * 0.50f);
drawList.AddCircleFilled(new Vector2(p.X + radius + ((v ? 1 : 0) * (width - (radius * 2.0f))), p.Y + radius), radius - 1.5f, ImGui.ColorConvertFloat4ToU32(new Vector4(255, 255, 255, 255) * dimFactor)); drawList.AddCircleFilled(new Vector2(p.X + radius + ((v ? 1 : 0) * (width - (radius * 2.0f))), p.Y + radius), radius - 1.5f, ImGui.ColorConvertFloat4ToU32(new Vector4(1, 1, 1, 1) * dimFactor));
} }
} }
} }

View file

@ -14,6 +14,7 @@ using Dalamud.Game.Command;
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
using Dalamud.Interface.Components; using Dalamud.Interface.Components;
using Dalamud.Interface.Internal.Notifications; using Dalamud.Interface.Internal.Notifications;
using Dalamud.Interface.Style;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Logging.Internal; using Dalamud.Logging.Internal;
using Dalamud.Plugin; using Dalamud.Plugin;
@ -420,7 +421,7 @@ namespace Dalamud.Interface.Internal.Windows.PluginInstaller
this.updateStatus = OperationStatus.InProgress; this.updateStatus = OperationStatus.InProgress;
this.loadingIndicatorKind = LoadingIndicatorKind.UpdatingAll; this.loadingIndicatorKind = LoadingIndicatorKind.UpdatingAll;
Task.Run(() => pluginManager.UpdatePluginsAsync()) Task.Run(() => pluginManager.UpdatePluginsAsync(true, false))
.ContinueWith(task => .ContinueWith(task =>
{ {
this.updateStatus = OperationStatus.Complete; this.updateStatus = OperationStatus.Complete;
@ -1816,6 +1817,8 @@ namespace Dalamud.Interface.Internal.Windows.PluginInstaller
var isLoadedAndUnloadable = plugin.State == PluginState.Loaded || var isLoadedAndUnloadable = plugin.State == PluginState.Loaded ||
plugin.State == PluginState.DependencyResolutionFailed; plugin.State == PluginState.DependencyResolutionFailed;
StyleModelV1.DalamudStandard.Push();
if (plugin.State == PluginState.UnloadError) if (plugin.State == PluginState.UnloadError)
{ {
ImGuiComponents.DisabledButton(FontAwesomeIcon.Frown); ImGuiComponents.DisabledButton(FontAwesomeIcon.Frown);
@ -1886,6 +1889,8 @@ namespace Dalamud.Interface.Internal.Windows.PluginInstaller
} }
} }
StyleModelV1.DalamudStandard.Pop();
ImGui.SameLine(); ImGui.SameLine();
ImGuiHelpers.ScaledDummy(15, 0); ImGuiHelpers.ScaledDummy(15, 0);

View file

@ -1,10 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Numerics;
using Dalamud.Configuration.Internal; using Dalamud.Configuration.Internal;
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
using Dalamud.Utility; using Dalamud.Utility;
using ImGuiNET;
using Newtonsoft.Json; using Newtonsoft.Json;
using Serilog; using Serilog;
@ -15,6 +16,10 @@ namespace Dalamud.Interface.Style
/// </summary> /// </summary>
public abstract class StyleModel public abstract class StyleModel
{ {
private static int NumPushedStyles = 0;
private static int NumPushedColors = 0;
private static bool HasPushedOnce = false;
/// <summary> /// <summary>
/// Gets or sets the name of the style model. /// Gets or sets the name of the style model.
/// </summary> /// </summary>
@ -84,7 +89,7 @@ namespace Dalamud.Interface.Style
configuration.SavedStyles = new List<StyleModel>(); configuration.SavedStyles = new List<StyleModel>();
configuration.SavedStyles.AddRange(configuration.SavedStylesOld); configuration.SavedStyles.AddRange(configuration.SavedStylesOld);
Log.Information("Transferred {0} styles", configuration.SavedStyles.Count); Log.Information("Transferred {NumStyles} styles", configuration.SavedStyles.Count);
configuration.SavedStylesOld = null; configuration.SavedStylesOld = null;
configuration.Save(); configuration.Save();
@ -123,6 +128,60 @@ namespace Dalamud.Interface.Style
/// <summary> /// <summary>
/// Pop this style model from the ImGui style/color stack. /// Pop this style model from the ImGui style/color stack.
/// </summary> /// </summary>
public abstract void Pop(); public void Pop()
{
if (!HasPushedOnce)
throw new InvalidOperationException("Wasn't pushed at least once.");
ImGui.PopStyleVar(NumPushedStyles);
ImGui.PopStyleColor(NumPushedColors);
}
/// <summary>
/// Push a style var.
/// </summary>
/// <param name="style">Style kind.</param>
/// <param name="arg">Style var.</param>
protected void PushStyleHelper(ImGuiStyleVar style, float arg)
{
ImGui.PushStyleVar(style, arg);
if (!HasPushedOnce)
NumPushedStyles++;
}
/// <summary>
/// Push a style var.
/// </summary>
/// <param name="style">Style kind.</param>
/// <param name="arg">Style var.</param>
protected void PushStyleHelper(ImGuiStyleVar style, Vector2 arg)
{
ImGui.PushStyleVar(style, arg);
if (!HasPushedOnce)
NumPushedStyles++;
}
/// <summary>
/// Push a style color.
/// </summary>
/// <param name="color">Color kind.</param>
/// <param name="value">Color value.</param>
protected void PushColorHelper(ImGuiCol color, Vector4 value)
{
ImGui.PushStyleColor(color, value);
if (!HasPushedOnce)
NumPushedColors++;
}
/// <summary>
/// Indicate that you have pushed.
/// </summary>
protected void DonePushing()
{
HasPushedOnce = true;
}
} }
} }

View file

@ -487,13 +487,41 @@ namespace Dalamud.Interface.Style
/// <inheritdoc/> /// <inheritdoc/>
public override void Push() public override void Push()
{ {
throw new NotImplementedException(); this.PushStyleHelper(ImGuiStyleVar.Alpha, this.Alpha);
} this.PushStyleHelper(ImGuiStyleVar.WindowPadding, this.WindowPadding);
this.PushStyleHelper(ImGuiStyleVar.WindowRounding, this.WindowRounding);
this.PushStyleHelper(ImGuiStyleVar.WindowBorderSize, this.WindowBorderSize);
this.PushStyleHelper(ImGuiStyleVar.WindowTitleAlign, this.WindowTitleAlign);
this.PushStyleHelper(ImGuiStyleVar.ChildRounding, this.ChildRounding);
this.PushStyleHelper(ImGuiStyleVar.ChildBorderSize, this.ChildBorderSize);
this.PushStyleHelper(ImGuiStyleVar.PopupRounding, this.PopupRounding);
this.PushStyleHelper(ImGuiStyleVar.PopupBorderSize, this.PopupBorderSize);
this.PushStyleHelper(ImGuiStyleVar.FramePadding, this.FramePadding);
this.PushStyleHelper(ImGuiStyleVar.FrameRounding, this.FrameRounding);
this.PushStyleHelper(ImGuiStyleVar.FrameBorderSize, this.FrameBorderSize);
this.PushStyleHelper(ImGuiStyleVar.ItemSpacing, this.ItemSpacing);
this.PushStyleHelper(ImGuiStyleVar.ItemInnerSpacing, this.ItemInnerSpacing);
this.PushStyleHelper(ImGuiStyleVar.CellPadding, this.CellPadding);
this.PushStyleHelper(ImGuiStyleVar.IndentSpacing, this.IndentSpacing);
this.PushStyleHelper(ImGuiStyleVar.ScrollbarSize, this.ScrollbarSize);
this.PushStyleHelper(ImGuiStyleVar.ScrollbarRounding, this.ScrollbarRounding);
this.PushStyleHelper(ImGuiStyleVar.GrabMinSize, this.GrabMinSize);
this.PushStyleHelper(ImGuiStyleVar.GrabRounding, this.GrabRounding);
this.PushStyleHelper(ImGuiStyleVar.TabRounding, this.TabRounding);
this.PushStyleHelper(ImGuiStyleVar.ButtonTextAlign, this.ButtonTextAlign);
this.PushStyleHelper(ImGuiStyleVar.SelectableTextAlign, this.SelectableTextAlign);
/// <inheritdoc/> foreach (var imGuiCol in Enum.GetValues<ImGuiCol>())
public override void Pop() {
{ if (imGuiCol == ImGuiCol.COUNT)
throw new NotImplementedException(); {
continue;
}
this.PushColorHelper(imGuiCol, this.Colors[imGuiCol.ToString()]);
}
this.DonePushing();
} }
} }
} }

View file

@ -884,7 +884,7 @@ internal partial class PluginManager : IDisposable, IServiceType
/// </summary> /// </summary>
/// <param name="dryRun">Perform a dry run, don't install anything.</param> /// <param name="dryRun">Perform a dry run, don't install anything.</param>
/// <returns>Success or failure and a list of updated plugin metadata.</returns> /// <returns>Success or failure and a list of updated plugin metadata.</returns>
public async Task<List<PluginUpdateStatus>> UpdatePluginsAsync(bool dryRun = false) public async Task<List<PluginUpdateStatus>> UpdatePluginsAsync(bool ignoreDisabled, bool dryRun)
{ {
Log.Information("Starting plugin update"); Log.Information("Starting plugin update");
@ -897,6 +897,9 @@ internal partial class PluginManager : IDisposable, IServiceType
if (plugin.InstalledPlugin.IsDev) if (plugin.InstalledPlugin.IsDev)
continue; continue;
if (plugin.InstalledPlugin.Manifest.Disabled && ignoreDisabled)
continue;
var result = await this.UpdateSinglePluginAsync(plugin, false, dryRun); var result = await this.UpdateSinglePluginAsync(plugin, false, dryRun);
if (result != null) if (result != null)
updatedList.Add(result); updatedList.Add(result);