Skip to content

Commit

Permalink
fix: delete plugin button behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Aireil committed Oct 4, 2023
1 parent 1d015c2 commit 66cf8cb
Showing 1 changed file with 45 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2832,68 +2832,66 @@ private void DrawDeletePluginButton(LocalPlugin plugin)

var pluginManager = Service<PluginManager>.Get();

var devNotDeletable = plugin.IsDev && plugin.State != PluginState.Unloaded && plugin.State != PluginState.DependencyResolutionFailed;
var isRemovable = !plugin.HasEverStartedLoad || plugin.State is PluginState.Unloaded or PluginState.DependencyResolutionFailed;
var isDevNotRemovable = plugin.IsDev && !isRemovable;
var isButtonDisabled = plugin.State == PluginState.Loaded || isDevNotRemovable;

ImGui.SameLine();
if (plugin.State == PluginState.Loaded || devNotDeletable)
if (isButtonDisabled)
{
ImGui.PushFont(InterfaceManager.IconFont);
ImGuiComponents.DisabledButton(FontAwesomeIcon.TrashAlt.ToIconString());
ImGui.PopFont();

if (ImGui.IsItemHovered())
{
ImGui.SetTooltip(plugin.State == PluginState.Loaded
? Locs.PluginButtonToolTip_DeletePluginLoaded
: Locs.PluginButtonToolTip_DeletePluginRestricted);
}
ImGuiComponents.DisabledButton(FontAwesomeIcon.TrashAlt);
}
else
else if (ImGuiComponents.IconButton(FontAwesomeIcon.TrashAlt))
{
if (ImGuiComponents.IconButton(FontAwesomeIcon.TrashAlt))
try
{
try
if (plugin.IsDev)
{
if (plugin.IsDev)
{
plugin.DllFile.Delete();
}
else
{
plugin.ScheduleDeletion(!plugin.Manifest.ScheduledForDeletion);
}

if (plugin.State is PluginState.Unloaded or PluginState.DependencyResolutionFailed)
{
pluginManager.RemovePlugin(plugin);
}
plugin.DllFile.Delete();
}
catch (Exception ex)
else
{
Log.Error(ex, $"Plugin installer threw an error during removal of {plugin.Name}");

this.ShowErrorModal(Locs.ErrorModal_DeleteFail(plugin.Name));
plugin.ScheduleDeletion(!plugin.Manifest.ScheduledForDeletion);
}
}

if (ImGui.IsItemHovered())
{
string tooltipMessage;
if (plugin.Manifest.ScheduledForDeletion)
if (isRemovable)
{
tooltipMessage = Locs.PluginButtonToolTip_DeletePluginScheduledCancel;
}
else if (plugin.State is PluginState.Unloaded or PluginState.DependencyResolutionFailed)
{
tooltipMessage = Locs.PluginButtonToolTip_DeletePlugin;
}
else
{
tooltipMessage = Locs.PluginButtonToolTip_DeletePluginScheduled;
pluginManager.RemovePlugin(plugin);
}
}
catch (Exception ex)
{
Log.Error(ex, $"Plugin installer threw an error during removal of {plugin.Name}");

this.ShowErrorModal(Locs.ErrorModal_DeleteFail(plugin.Name));
}
}

ImGui.SetTooltip(tooltipMessage);
if (ImGui.IsItemHovered())
{
string tooltipMessage;
if (plugin.State == PluginState.Loaded)
{
tooltipMessage = Locs.PluginButtonToolTip_DeletePluginLoaded;
}
else if (isDevNotRemovable)
{
tooltipMessage = Locs.PluginButtonToolTip_DeletePluginRestricted;
}
else if (plugin.Manifest.ScheduledForDeletion)
{
tooltipMessage = Locs.PluginButtonToolTip_DeletePluginScheduledCancel;
}
else if (!isRemovable)
{
tooltipMessage = Locs.PluginButtonToolTip_DeletePluginScheduled;
}
else
{
tooltipMessage = Locs.PluginButtonToolTip_DeletePlugin;
}

ImGui.SetTooltip(tooltipMessage);
}
}

Expand Down

0 comments on commit 66cf8cb

Please sign in to comment.