Skip to content

Commit

Permalink
add "install testing version" entry to available context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
goaaats committed Jul 2, 2024
1 parent 2219676 commit 64a094f
Showing 1 changed file with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,17 @@ public bool DisplayErrorContinuation(Task task, object state)

return false;
}

private static void EnsureHaveTestingOptIn(IPluginManifest manifest)
{
var configuration = Service<DalamudConfiguration>.Get();

if (configuration.PluginTestingOptIns.Any(x => x.InternalName == manifest.InternalName))
return;

configuration.PluginTestingOptIns.Add(new PluginTestingOptIn(manifest.InternalName));
configuration.QueueSave();
}

private void SetOpenPage(PluginInstallerOpenKind kind)
{
Expand Down Expand Up @@ -456,7 +467,7 @@ private void SetOpenPage(PluginInstallerOpenKind kind)
throw new ArgumentOutOfRangeException(nameof(kind), kind, null);
}
}

private void DrawProgressOverlay()
{
var pluginManager = Service<PluginManager>.Get();
Expand Down Expand Up @@ -782,7 +793,13 @@ private void DrawUpdatePluginsButton()
if (this.updatePluginCount > 0)
{
Service<PluginManager>.Get().PrintUpdatedPlugins(this.updatedPlugins, Locs.PluginUpdateHeader_Chatbox);
notifications.AddNotification(Locs.Notifications_UpdatesInstalled(this.updatePluginCount), Locs.Notifications_UpdatesInstalledTitle, NotificationType.Success);
notifications.AddNotification(new Notification
{
Title = Locs.Notifications_UpdatesInstalledTitle,
Content = Locs.Notifications_UpdatesInstalled(this.updatedPlugins),
Type = NotificationType.Success,
Icon = INotificationIcon.From(FontAwesomeIcon.Download),
});
this.categoryManager.CurrentGroupKind = PluginCategoryManager.GroupKind.Installed;
}
Expand Down Expand Up @@ -2257,7 +2274,7 @@ private void DrawAvailablePlugin(RemotePluginManifest manifest, int index)
if (useTesting || manifest.IsTestingExclusive)
flags |= PluginHeaderFlags.IsTesting;

if (this.DrawPluginCollapsingHeader(label, null, manifest, flags, () => this.DrawAvailablePluginContextMenu(manifest), index))
if (this.DrawPluginCollapsingHeader(label, null, manifest, flags, () => this.DrawAvailablePluginContextMenu(manifest, effectiveApiLevel), index))
{
if (!wasSeen)
configuration.SeenPluginInternalName.Add(manifest.InternalName);
Expand Down Expand Up @@ -2335,13 +2352,28 @@ private void DrawAvailablePlugin(RemotePluginManifest manifest, int index)
ImGui.PopID();
}

private void DrawAvailablePluginContextMenu(PluginManifest manifest)
private void DrawAvailablePluginContextMenu(RemotePluginManifest manifest, int effectiveApiLevel)
{
var configuration = Service<DalamudConfiguration>.Get();
var pluginManager = Service<PluginManager>.Get();

var hasTestingVersionAvailable = configuration.DoPluginTest &&
PluginManager.HasTestingVersion(manifest) &&
manifest.TestingDalamudApiLevel == effectiveApiLevel;

if (ImGui.BeginPopupContextItem("ItemContextMenu"))
{
if (hasTestingVersionAvailable)
{
if (ImGui.Selectable(Locs.PluginContext_InstallTestingVersion))
{
EnsureHaveTestingOptIn(manifest);
this.StartInstall(manifest, true);
}

ImGui.Separator();
}

if (ImGui.Selectable(Locs.PluginContext_MarkAllSeen))
{
configuration.SeenPluginInternalName.AddRange(this.pluginListAvailable.Select(x => x.InternalName));
Expand Down Expand Up @@ -2725,7 +2757,7 @@ private void DrawInstalledPluginContextMenu(LocalPlugin plugin, PluginTestingOpt
}
else
{
configuration.PluginTestingOptIns!.Add(new PluginTestingOptIn(plugin.Manifest.InternalName));
EnsureHaveTestingOptIn(plugin.Manifest);
}

configuration.QueueSave();
Expand Down Expand Up @@ -3818,6 +3850,8 @@ internal static class Locs

public static string PluginContext_TestingOptIn => Loc.Localize("InstallerTestingOptIn", "Receive plugin testing versions");

public static string PluginContext_InstallTestingVersion => Loc.Localize("InstallerInstallTestingVersion", "Install testing version");

public static string PluginContext_MarkAllSeen => Loc.Localize("InstallerMarkAllSeen", "Mark all as seen");

public static string PluginContext_HidePlugin => Loc.Localize("InstallerHidePlugin", "Hide from installer");
Expand Down Expand Up @@ -3941,7 +3975,9 @@ public static string PluginBody_BannedReason(string message) =>

public static string Notifications_UpdatesInstalledTitle => Loc.Localize("NotificationsUpdatesInstalledTitle", "Updates installed!");

public static string Notifications_UpdatesInstalled(int count) => Loc.Localize("NotificationsUpdatesInstalled", "Updates for {0} of your plugins were installed.").Format(count);
public static string Notifications_UpdatesInstalled(List<PluginUpdateStatus> updates)
=> Loc.Localize("NotificationsUpdatesInstalled", "Updates for {0} of your plugins were installed.\n\n{1}")
.Format(updates.Count, string.Join(", ", updates.Select(x => x.InternalName)));

public static string Notifications_PluginDisabledTitle => Loc.Localize("NotificationsPluginDisabledTitle", "Plugin disabled!");

Expand Down

0 comments on commit 64a094f

Please sign in to comment.