Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow feedback to unofficial endpoints #2176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ internal class PluginInstallerWindow : Window, IDisposable
private bool feedbackModalIncludeException = false;
private IPluginManifest? feedbackPlugin = null;
private bool feedbackIsTesting = false;
private bool feedbackIsCustomRepo = false;

private int updatePluginCount = 0;
private List<PluginUpdateStatus>? updatedPlugins;
Expand Down Expand Up @@ -1071,6 +1072,11 @@ private void DrawFeedbackModal()

ImGui.TextColored(ImGuiColors.DalamudRed, Locs.FeedbackModal_ContactInformationWarning);

if (this.feedbackPlugin?.FeedbackWebhook != null && this.feedbackIsCustomRepo)
{
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudRed, Locs.FeedbackModal_IPAddressWarning);
}

ImGui.Spacing();

ImGui.Checkbox(Locs.FeedbackModal_IncludeLastError, ref this.feedbackModalIncludeException);
Expand Down Expand Up @@ -1101,6 +1107,7 @@ private void DrawFeedbackModal()
Task.Run(async () => await BugBait.SendFeedback(
this.feedbackPlugin,
this.feedbackIsTesting,
this.feedbackIsCustomRepo,
this.feedbackModalBody,
this.feedbackModalContact,
this.feedbackModalIncludeException))
Expand Down Expand Up @@ -2444,10 +2451,13 @@ private void DrawAvailablePlugin(RemotePluginManifest manifest, int index)
ImGuiHelpers.ScaledDummy(3);
}

if (!manifest.SourceRepo.IsThirdParty && manifest.AcceptsFeedback && !isOutdated)
var feedbackEligible = manifest.AcceptsFeedback &&
(!manifest.SourceRepo.IsThirdParty || manifest.FeedbackWebhook != null);

if (feedbackEligible && !isOutdated)
{
ImGui.SameLine();
this.DrawSendFeedbackButton(manifest, false, true);
this.DrawSendFeedbackButton(manifest, false, manifest.SourceRepo.IsThirdParty, true);
}

ImGuiHelpers.ScaledDummy(5);
Expand Down Expand Up @@ -2717,16 +2727,12 @@ private void DrawInstalledPlugin(LocalPlugin plugin, int index, RemotePluginMani
ImGui.SameLine();
ImGui.TextColored(ImGuiColors.DalamudGrey3, downloadText);

var acceptsFeedback =
this.pluginListAvailable.Any(x => x.InternalName == plugin.InternalName && x.AcceptsFeedback);

var isThirdParty = plugin.IsThirdParty;
var canFeedback = !isThirdParty &&
!plugin.IsDev &&
var canFeedback = !plugin.IsDev &&
!plugin.IsOrphaned &&
(plugin.Manifest.DalamudApiLevel == PluginManager.DalamudApiLevel ||
(plugin.Manifest.TestingDalamudApiLevel == PluginManager.DalamudApiLevel && hasTestingAvailable)) &&
acceptsFeedback &&
plugin.Manifest.AcceptsFeedback && (!plugin.IsThirdParty || plugin.Manifest.FeedbackWebhook != null) &&
availablePluginUpdate == default;

// Installed from
Expand Down Expand Up @@ -2793,7 +2799,7 @@ private void DrawInstalledPlugin(LocalPlugin plugin, int index, RemotePluginMani
if (canFeedback)
{
ImGui.SameLine();
this.DrawSendFeedbackButton(plugin.Manifest, plugin.IsTesting, false);
this.DrawSendFeedbackButton(plugin.Manifest, plugin.IsTesting, plugin.IsThirdParty, false);
}

if (availablePluginUpdate != default && !plugin.IsDev)
Expand Down Expand Up @@ -3275,7 +3281,7 @@ private void DrawOpenPluginSettingsButton(LocalPlugin plugin)
}
}

private void DrawSendFeedbackButton(IPluginManifest manifest, bool isTesting, bool big)
private void DrawSendFeedbackButton(IPluginManifest manifest, bool isTesting, bool isCustomRepo, bool big)
{
var clicked = big ?
ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Comment, Locs.FeedbackModal_Title) :
Expand All @@ -3286,6 +3292,7 @@ private void DrawSendFeedbackButton(IPluginManifest manifest, bool isTesting, bo
this.feedbackPlugin = manifest;
this.feedbackModalOnNextFrame = true;
this.feedbackIsTesting = isTesting;
this.feedbackIsCustomRepo = isCustomRepo;
}

if (ImGui.IsItemHovered())
Expand Down Expand Up @@ -3753,7 +3760,7 @@ private void ResortPlugins()
case PluginSortKind.EnabledDisabled:
this.pluginListAvailable.Sort((p1, p2) =>
{
bool IsEnabled(PluginManifest manifest)
bool IsEnabled(IPluginManifest manifest)
{
return this.pluginListInstalled.Any(x => x.Manifest.InternalName == manifest.InternalName);
}
Expand Down Expand Up @@ -4255,6 +4262,8 @@ public static string Notifications_UpdatesInstalled(List<PluginUpdateStatus> upd

public static string FeedbackModal_Hint => Loc.Localize("InstallerFeedbackHint", "All plugin developers will be able to see your feedback.\nPlease never include any personal or revealing information.\nIf you chose to include the last error message, information like your Windows username may be included.\n\nThe collected feedback is not stored on our end and immediately relayed to Discord.");

public static string FeedbackModal_IPAddressWarning => Loc.Localize("InstallerFeedbackIPAddressWarning", "This plugin is configured to send feedback to a server defined by its maintainer, which may log your IP address. Please ensure you trust the author of this plugin!");

public static string FeedbackModal_NotificationSuccess => Loc.Localize("InstallerFeedbackNotificationSuccess", "Your feedback was sent successfully!");

public static string FeedbackModal_NotificationError => Loc.Localize("InstallerFeedbackNotificationError", "Your feedback could not be sent.");
Expand Down
23 changes: 17 additions & 6 deletions Dalamud/Plugin/Internal/Types/Manifest/IPluginManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IPluginManifest
/// Gets the public name of the plugin.
/// </summary>
public string Name { get; }

/// <summary>
/// Gets a punchline of the plugins functions.
/// </summary>
Expand All @@ -26,7 +26,7 @@ public interface IPluginManifest
/// Gets the author/s of the plugin.
/// </summary>
public string Author { get; }

/// <summary>
/// Gets a value indicating whether the plugin can be unloaded asynchronously.
/// </summary>
Expand All @@ -41,17 +41,17 @@ public interface IPluginManifest
/// Gets the assembly version of the plugin's testing variant.
/// </summary>
public Version? TestingAssemblyVersion { get; }

/// <summary>
/// Gets the DIP17 channel name.
/// </summary>
public string? Dip17Channel { get; }

/// <summary>
/// Gets the last time this plugin was updated.
/// </summary>
public long LastUpdate { get; }

/// <summary>
/// Gets a changelog, null if none exists.
/// </summary>
Expand Down Expand Up @@ -88,17 +88,28 @@ public interface IPluginManifest
/// Gets an URL to the website or source code of the plugin.
/// </summary>
public string? RepoUrl { get; }

/// <summary>
/// Gets a description of the plugins functions.
/// </summary>
public string? Description { get; }

/// <summary>
/// Gets a value indicating whether this plugin accepts feedback.
/// </summary>
public bool AcceptsFeedback { get; }

/// <summary>
/// Gets a message that is shown to users when sending feedback.
/// </summary>
public string? FeedbackMessage { get; }

/// <summary>
/// Gets the URL to submit plugin feedback to.
/// For mainline plugins, the WebServices API will be responsible for relaying feedback regardless of this value.
/// </summary>
public string? FeedbackWebhook { get; }

/// <summary>
/// Gets a value indicating whether the plugin is only available for testing.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal record RemotePluginManifest : PluginManifest
/// </summary>
[JsonIgnore]
public PluginRepository SourceRepo { get; set; } = null!;

/// <summary>
/// Gets or sets the changelog to be shown when obtaining the testing version of the plugin.
/// </summary>
Expand Down
7 changes: 4 additions & 3 deletions Dalamud/Plugin/Internal/Types/PluginManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,15 @@ internal record PluginManifest : IPluginManifest
/// <inheritdoc/>
public string? IconUrl { get; init; }

/// <summary>
/// Gets a value indicating whether this plugin accepts feedback.
/// </summary>
/// <inheritdoc/>
public bool AcceptsFeedback { get; init; } = true;

/// <inheritdoc/>
public string? FeedbackMessage { get; init; }

/// <inheritdoc/>
public string? FeedbackWebhook { get; init; }

/// <inheritdoc/>
[JsonProperty("_Dip17Channel")]
public string? Dip17Channel { get; init; }
Expand Down
10 changes: 6 additions & 4 deletions Dalamud/Support/BugBait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Dalamud.Support;
/// </summary>
internal static class BugBait
{
private const string BugBaitUrl = "https://kiko.goats.dev/feedback";
private const string BugBaitUrl = "https://api.dalamud.dev/feedback";

/// <summary>
/// Send feedback to Discord.
Expand All @@ -25,7 +25,7 @@ internal static class BugBait
/// <param name="reporter">The reporter name.</param>
/// <param name="includeException">Whether or not the most recent exception to occur should be included in the report.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public static async Task SendFeedback(IPluginManifest plugin, bool isTesting, string content, string reporter, bool includeException)
public static async Task SendFeedback(IPluginManifest plugin, bool isTesting, bool isCustomRepo, string content, string reporter, bool includeException)
{
if (content.IsNullOrWhitespace())
return;
Expand All @@ -43,11 +43,13 @@ public static async Task SendFeedback(IPluginManifest plugin, bool isTesting, st
{
model.Exception = Troubleshooting.LastException == null ? "Was included, but none happened" : Troubleshooting.LastException?.ToString();
}

var httpClient = Service<HappyHttpClient>.Get().SharedHttpClient;

var feedbackUrl = !isCustomRepo ? BugBaitUrl : plugin.FeedbackWebhook ?? BugBaitUrl;

var postContent = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync(BugBaitUrl, postContent);
var response = await httpClient.PostAsync(feedbackUrl, postContent);

response.EnsureSuccessStatusCode();
}
Expand Down
Loading