- Add chat notification back to AutoUpdate (#2146)

- ImRaii UI elements in AutoUpdate tab
- Fix scoping in IconButton
This commit is contained in:
Infi 2024-12-19 22:19:50 +01:00 committed by GitHub
parent f7ef68d65e
commit 2e6cb6ef00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 166 additions and 114 deletions

View file

@ -484,10 +484,15 @@ internal sealed class DalamudConfiguration : IInternalDisposableService
public AutoUpdateBehavior? AutoUpdateBehavior { get; set; } = null; public AutoUpdateBehavior? AutoUpdateBehavior { get; set; } = null;
/// <summary> /// <summary>
/// Gets or sets a value indicating whether or not users should be notified regularly about pending updates. /// Gets or sets a value indicating whether users should be notified regularly about pending updates.
/// </summary> /// </summary>
public bool CheckPeriodicallyForUpdates { get; set; } = true; public bool CheckPeriodicallyForUpdates { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether users should be notified about updates in chat.
/// </summary>
public bool SendUpdateNotificationToChat { get; set; } = false;
/// <summary> /// <summary>
/// Load a configuration from the provided path. /// Load a configuration from the provided path.
/// </summary> /// </summary>

View file

@ -272,15 +272,14 @@ public static partial class ImGuiComponents
/// <returns>Width.</returns> /// <returns>Width.</returns>
public static float GetIconButtonWithTextWidth(FontAwesomeIcon icon, string text) public static float GetIconButtonWithTextWidth(FontAwesomeIcon icon, string text)
{ {
Vector2 iconSize;
using (ImRaii.PushFont(UiBuilder.IconFont)) using (ImRaii.PushFont(UiBuilder.IconFont))
{ {
var iconSize = ImGui.CalcTextSize(icon.ToIconString()); iconSize = ImGui.CalcTextSize(icon.ToIconString());
var textSize = ImGui.CalcTextSize(text);
var iconPadding = 3 * ImGuiHelpers.GlobalScale;
return iconSize.X + textSize.X + (ImGui.GetStyle().FramePadding.X * 2) + iconPadding;
} }
var textSize = ImGui.CalcTextSize(text);
var iconPadding = 3 * ImGuiHelpers.GlobalScale;
return iconSize.X + textSize.X + (ImGui.GetStyle().FramePadding.X * 2) + iconPadding;
} }
} }

View file

@ -44,7 +44,9 @@ internal static partial class DalamudComponents
ImGui.InputTextWithHint("###pluginPickerSearch", Locs.SearchHint, ref pickerSearch, 255); ImGui.InputTextWithHint("###pluginPickerSearch", Locs.SearchHint, ref pickerSearch, 255);
var currentSearchString = pickerSearch; var currentSearchString = pickerSearch;
if (ImGui.BeginListBox("###pluginPicker", new Vector2(width, width - 80)))
using var listBox = ImRaii.ListBox("###pluginPicker", new Vector2(width, width - 80));
if (listBox.Success)
{ {
// TODO: Plugin searching should be abstracted... installer and this should use the same search // TODO: Plugin searching should be abstracted... installer and this should use the same search
var plugins = pm.InstalledPlugins.Where( var plugins = pm.InstalledPlugins.Where(
@ -56,16 +58,12 @@ internal static partial class DalamudComponents
foreach (var plugin in plugins) foreach (var plugin in plugins)
{ {
using var disabled2 = using var disabled2 = ImRaii.Disabled(pluginDisabled(plugin));
ImRaii.Disabled(pluginDisabled(plugin));
if (ImGui.Selectable($"{plugin.Manifest.Name}{(plugin is LocalDevPlugin ? "(dev plugin)" : string.Empty)}###selector{plugin.Manifest.InternalName}")) if (ImGui.Selectable($"{plugin.Manifest.Name}{(plugin is LocalDevPlugin ? "(dev plugin)" : string.Empty)}###selector{plugin.Manifest.InternalName}"))
{ {
onClicked(plugin); onClicked(plugin);
} }
} }
ImGui.EndListBox();
} }
} }

View file

@ -23,10 +23,11 @@ public class SettingsTabAutoUpdates : SettingsTab
{ {
private AutoUpdateBehavior behavior; private AutoUpdateBehavior behavior;
private bool checkPeriodically; private bool checkPeriodically;
private bool chatNotification;
private string pickerSearch = string.Empty; private string pickerSearch = string.Empty;
private List<AutoUpdatePreference> autoUpdatePreferences = []; private List<AutoUpdatePreference> autoUpdatePreferences = [];
public override SettingsEntry[] Entries { get; } = Array.Empty<SettingsEntry>(); public override SettingsEntry[] Entries { get; } = [];
public override string Title => Loc.Localize("DalamudSettingsAutoUpdates", "Auto-Updates"); public override string Title => Loc.Localize("DalamudSettingsAutoUpdates", "Auto-Updates");
@ -65,6 +66,7 @@ public class SettingsTabAutoUpdates : SettingsTab
ImGuiHelpers.ScaledDummy(8); ImGuiHelpers.ScaledDummy(8);
ImGui.Checkbox(Loc.Localize("DalamudSettingsAutoUpdateChatMessage", "Show notification about updates available in chat"), ref this.chatNotification);
ImGui.Checkbox(Loc.Localize("DalamudSettingsAutoUpdatePeriodically", "Periodically check for new updates while playing"), ref this.checkPeriodically); ImGui.Checkbox(Loc.Localize("DalamudSettingsAutoUpdatePeriodically", "Periodically check for new updates while playing"), ref this.checkPeriodically);
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsAutoUpdatePeriodicallyHint", ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsAutoUpdatePeriodicallyHint",
"Plugins won't update automatically after startup, you will only receive a notification while you are not actively playing.")); "Plugins won't update automatically after startup, you will only receive a notification while you are not actively playing."));
@ -120,9 +122,10 @@ public class SettingsTabAutoUpdates : SettingsTab
if (pmPlugin.IsDev) if (pmPlugin.IsDev)
{ {
ImGui.SetCursorPos(cursorBeforeIcon); ImGui.SetCursorPos(cursorBeforeIcon);
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 0.7f); using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, 0.7f))
ImGui.Image(pic.DevPluginIcon.ImGuiHandle, new Vector2(pluginLineHeight)); {
ImGui.PopStyleVar(); ImGui.Image(pic.DevPluginIcon.ImGuiHandle, new Vector2(pluginLineHeight));
}
} }
ImGui.SameLine(); ImGui.SameLine();
@ -166,19 +169,18 @@ public class SettingsTabAutoUpdates : SettingsTab
} }
ImGui.SetNextItemWidth(ImGuiHelpers.GlobalScale * 250); ImGui.SetNextItemWidth(ImGuiHelpers.GlobalScale * 250);
if (ImGui.BeginCombo( using (var combo = ImRaii.Combo($"###autoUpdateBehavior{preference.WorkingPluginId}", OptKindToString(preference.Kind)))
$"###autoUpdateBehavior{preference.WorkingPluginId}",
OptKindToString(preference.Kind)))
{ {
foreach (var kind in Enum.GetValues<AutoUpdatePreference.OptKind>()) if (combo.Success)
{ {
if (ImGui.Selectable(OptKindToString(kind))) foreach (var kind in Enum.GetValues<AutoUpdatePreference.OptKind>())
{ {
preference.Kind = kind; if (ImGui.Selectable(OptKindToString(kind)))
{
preference.Kind = kind;
}
} }
} }
ImGui.EndCombo();
} }
ImGui.SameLine(); ImGui.SameLine();
@ -235,6 +237,7 @@ public class SettingsTabAutoUpdates : SettingsTab
var configuration = Service<DalamudConfiguration>.Get(); var configuration = Service<DalamudConfiguration>.Get();
this.behavior = configuration.AutoUpdateBehavior ?? AutoUpdateBehavior.None; this.behavior = configuration.AutoUpdateBehavior ?? AutoUpdateBehavior.None;
this.chatNotification = configuration.SendUpdateNotificationToChat;
this.checkPeriodically = configuration.CheckPeriodicallyForUpdates; this.checkPeriodically = configuration.CheckPeriodicallyForUpdates;
this.autoUpdatePreferences = configuration.PluginAutoUpdatePreferences; this.autoUpdatePreferences = configuration.PluginAutoUpdatePreferences;
@ -246,6 +249,7 @@ public class SettingsTabAutoUpdates : SettingsTab
var configuration = Service<DalamudConfiguration>.Get(); var configuration = Service<DalamudConfiguration>.Get();
configuration.AutoUpdateBehavior = this.behavior; configuration.AutoUpdateBehavior = this.behavior;
configuration.SendUpdateNotificationToChat = this.chatNotification;
configuration.CheckPeriodicallyForUpdates = this.checkPeriodically; configuration.CheckPeriodicallyForUpdates = this.checkPeriodically;
configuration.PluginAutoUpdatePreferences = this.autoUpdatePreferences; configuration.PluginAutoUpdatePreferences = this.autoUpdatePreferences;

View file

@ -9,6 +9,10 @@ using Dalamud.Console;
using Dalamud.Game; using Dalamud.Game;
using Dalamud.Game.ClientState; using Dalamud.Game.ClientState;
using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.Gui;
using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.ImGuiNotification; using Dalamud.Interface.ImGuiNotification;
using Dalamud.Interface.ImGuiNotification.EventArgs; using Dalamud.Interface.ImGuiNotification.EventArgs;
@ -78,6 +82,8 @@ internal class AutoUpdateManager : IServiceType
private Task? autoUpdateTask; private Task? autoUpdateTask;
private readonly Task<DalamudLinkPayload> openInstallerWindowLink;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="AutoUpdateManager"/> class. /// Initializes a new instance of the <see cref="AutoUpdateManager"/> class.
/// </summary> /// </summary>
@ -93,6 +99,17 @@ internal class AutoUpdateManager : IServiceType
}); });
Service<Framework>.GetAsync().ContinueWith(t => { t.Result.Update += this.OnUpdate; }); Service<Framework>.GetAsync().ContinueWith(t => { t.Result.Update += this.OnUpdate; });
this.openInstallerWindowLink =
Service<ChatGui>.GetAsync().ContinueWith(
chatGuiTask => chatGuiTask.Result.AddChatLinkHandler(
"Dalamud",
1001,
(_, _) =>
{
Service<DalamudInterface>.GetNullable()?.OpenPluginInstallerTo(PluginInstallerOpenKind.InstalledPlugins);
}));
this.isDryRun = console.AddVariable("dalamud.autoupdate.dry_run", "Simulate updates instead", false); this.isDryRun = console.AddVariable("dalamud.autoupdate.dry_run", "Simulate updates instead", false);
console.AddCommand("dalamud.autoupdate.trigger_login", "Trigger a login event", () => console.AddCommand("dalamud.autoupdate.trigger_login", "Trigger a login event", () =>
{ {
@ -241,6 +258,7 @@ internal class AutoUpdateManager : IServiceType
Log.Error(t.Exception!, "Failed to reload plugin masters for auto-update"); Log.Error(t.Exception!, "Failed to reload plugin masters for auto-update");
} }
Log.Verbose($"Available Updates: {string.Join(", ", this.pluginManager.UpdatablePlugins.Select(s => s.UpdateManifest.InternalName))}");
var updatable = this.GetAvailablePluginUpdates( var updatable = this.GetAvailablePluginUpdates(
DecideUpdateListingRestriction(behavior)); DecideUpdateListingRestriction(behavior));
@ -404,6 +422,34 @@ internal class AutoUpdateManager : IServiceType
this.nextUpdateCheckTime = DateTime.Now + TimeBetweenUpdateChecksIfDismissed; this.nextUpdateCheckTime = DateTime.Now + TimeBetweenUpdateChecksIfDismissed;
Log.Verbose("User dismissed update notification, next check at {Time}", this.nextUpdateCheckTime); Log.Verbose("User dismissed update notification, next check at {Time}", this.nextUpdateCheckTime);
}; };
// Send out a chat message only if the user requested so
if (!this.config.SendUpdateNotificationToChat)
return;
var chatGui = Service<ChatGui>.GetNullable();
if (chatGui == null)
{
Log.Verbose("Unable to get chat gui, discard notification for chat.");
return;
}
chatGui.Print(new XivChatEntry
{
Message = new SeString(new List<Payload>
{
new TextPayload(Locs.NotificationContentUpdatesAvailableMinimized(updatablePlugins.Count)),
new TextPayload(" ["),
new UIForegroundPayload(500),
this.openInstallerWindowLink.Result,
new TextPayload(Loc.Localize("DalamudInstallerHelp", "Open the plugin installer")),
RawPayload.LinkTerminator,
new UIForegroundPayload(0),
new TextPayload("]"),
}),
Type = XivChatType.Urgent,
});
} }
private List<AvailablePluginUpdate> GetAvailablePluginUpdates(UpdateListingRestriction restriction) private List<AvailablePluginUpdate> GetAvailablePluginUpdates(UpdateListingRestriction restriction)