This commit is contained in:
goaaats 2024-01-18 21:51:18 +01:00
commit b446fcc191
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
10 changed files with 223 additions and 100 deletions

View file

@ -2528,10 +2528,10 @@ internal class PluginInstallerWindow : Window, IDisposable
var applicableForProfiles = plugin.Manifest.SupportsProfiles && !plugin.IsDev;
var profilesThatWantThisPlugin = profileManager.Profiles
.Where(x => x.WantsPlugin(plugin.InternalName) != null)
.Where(x => x.WantsPlugin(plugin.Manifest.WorkingPluginId) != null)
.ToArray();
var isInSingleProfile = profilesThatWantThisPlugin.Length == 1;
var isDefaultPlugin = profileManager.IsInDefaultProfile(plugin.Manifest.InternalName);
var isDefaultPlugin = profileManager.IsInDefaultProfile(plugin.Manifest.WorkingPluginId);
// Disable everything if the updater is running or another plugin is operating
var disabled = this.updateStatus == OperationStatus.InProgress || this.installStatus == OperationStatus.InProgress;
@ -2566,17 +2566,17 @@ internal class PluginInstallerWindow : Window, IDisposable
foreach (var profile in profileManager.Profiles.Where(x => !x.IsDefaultProfile))
{
var inProfile = profile.WantsPlugin(plugin.Manifest.InternalName) != null;
var inProfile = profile.WantsPlugin(plugin.Manifest.WorkingPluginId) != null;
if (ImGui.Checkbox($"###profilePick{profile.Guid}{plugin.Manifest.InternalName}", ref inProfile))
{
if (inProfile)
{
Task.Run(() => profile.AddOrUpdateAsync(plugin.Manifest.InternalName, true))
Task.Run(() => profile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, true))
.ContinueWith(this.DisplayErrorContinuation, Locs.Profiles_CouldNotAdd);
}
else
{
Task.Run(() => profile.RemoveAsync(plugin.Manifest.InternalName))
Task.Run(() => profile.RemoveAsync(plugin.Manifest.WorkingPluginId))
.ContinueWith(this.DisplayErrorContinuation, Locs.Profiles_CouldNotRemove);
}
}
@ -2596,11 +2596,11 @@ internal class PluginInstallerWindow : Window, IDisposable
if (ImGuiComponents.IconButton(FontAwesomeIcon.Times))
{
// TODO: Work this out
Task.Run(() => profileManager.DefaultProfile.AddOrUpdateAsync(plugin.Manifest.InternalName, plugin.IsLoaded, false))
Task.Run(() => profileManager.DefaultProfile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, plugin.IsLoaded, false))
.GetAwaiter().GetResult();
foreach (var profile in profileManager.Profiles.Where(x => !x.IsDefaultProfile && x.Plugins.Any(y => y.InternalName == plugin.Manifest.InternalName)))
{
Task.Run(() => profile.RemoveAsync(plugin.Manifest.InternalName, false))
Task.Run(() => profile.RemoveAsync(plugin.Manifest.WorkingPluginId, false))
.GetAwaiter().GetResult();
}
@ -2674,7 +2674,7 @@ internal class PluginInstallerWindow : Window, IDisposable
{
await plugin.UnloadAsync();
await applicableProfile.AddOrUpdateAsync(
plugin.Manifest.InternalName, false, false);
plugin.Manifest.WorkingPluginId, false, false);
notifications.AddNotification(Locs.Notifications_PluginDisabled(plugin.Manifest.Name), Locs.Notifications_PluginDisabledTitle, NotificationType.Success);
}).ContinueWith(t =>
@ -2691,7 +2691,7 @@ internal class PluginInstallerWindow : Window, IDisposable
this.loadingIndicatorKind = LoadingIndicatorKind.EnablingSingle;
this.enableDisableWorkingPluginId = plugin.Manifest.WorkingPluginId;
await applicableProfile.AddOrUpdateAsync(plugin.Manifest.InternalName, true, false);
await applicableProfile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, true, false);
await plugin.LoadAsync(PluginLoadReason.Installer);
notifications.AddNotification(Locs.Notifications_PluginEnabled(plugin.Manifest.Name), Locs.Notifications_PluginEnabledTitle, NotificationType.Success);
@ -2712,7 +2712,7 @@ internal class PluginInstallerWindow : Window, IDisposable
if (shouldUpdate)
{
// We need to update the profile right here, because PM will not enable the plugin otherwise
await applicableProfile.AddOrUpdateAsync(plugin.InternalName, true, false);
await applicableProfile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, true, false);
await this.UpdateSinglePlugin(availableUpdate);
}
else
@ -2893,7 +2893,7 @@ internal class PluginInstallerWindow : Window, IDisposable
if (localPlugin is LocalDevPlugin plugin)
{
var isInDefaultProfile =
Service<ProfileManager>.Get().IsInDefaultProfile(localPlugin.Manifest.InternalName);
Service<ProfileManager>.Get().IsInDefaultProfile(localPlugin.Manifest.WorkingPluginId);
// https://colorswall.com/palette/2868/
var greenColor = new Vector4(0x5C, 0xB8, 0x5C, 0xFF) / 0xFF;
@ -3237,7 +3237,7 @@ internal class PluginInstallerWindow : Window, IDisposable
this.pluginListAvailable.Sort((p1, p2) => p1.Name.CompareTo(p2.Name));
var profman = Service<ProfileManager>.Get();
this.pluginListInstalled.Sort((p1, p2) => profman.IsInDefaultProfile(p1.InternalName).CompareTo(profman.IsInDefaultProfile(p2.InternalName)));
this.pluginListInstalled.Sort((p1, p2) => profman.IsInDefaultProfile(p1.Manifest.WorkingPluginId).CompareTo(profman.IsInDefaultProfile(p2.Manifest.WorkingPluginId)));
break;
default:
throw new InvalidEnumArgumentException("Unknown plugin sort type.");

View file

@ -252,7 +252,7 @@ internal class ProfileManagerWidget
if (ImGuiComponents.IconButton($"###exportButton{profile.Guid}", FontAwesomeIcon.FileExport))
{
ImGui.SetClipboardText(profile.Model.Serialize());
ImGui.SetClipboardText(profile.Model.SerializeForShare());
Service<NotificationManager>.Get().AddNotification(Locs.CopyToClipboardNotification, type: NotificationType.Success);
}
@ -323,7 +323,7 @@ internal class ProfileManagerWidget
if (ImGui.Selectable($"{plugin.Manifest.Name}###selector{plugin.Manifest.InternalName}"))
{
Task.Run(() => profile.AddOrUpdateAsync(plugin.Manifest.InternalName, true, false))
Task.Run(() => profile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, true, false))
.ContinueWith(this.installer.DisplayErrorContinuation, Locs.ErrorCouldNotChangeState);
}
}
@ -350,7 +350,7 @@ internal class ProfileManagerWidget
if (ImGuiComponents.IconButton(FontAwesomeIcon.FileExport))
{
ImGui.SetClipboardText(profile.Model.Serialize());
ImGui.SetClipboardText(profile.Model.SerializeForShare());
Service<NotificationManager>.Get().AddNotification(Locs.CopyToClipboardNotification, type: NotificationType.Success);
}
@ -423,13 +423,13 @@ internal class ProfileManagerWidget
if (pluginListChild)
{
var pluginLineHeight = 32 * ImGuiHelpers.GlobalScale;
string? wantRemovePluginInternalName = null;
Guid? wantRemovePluginGuid = null;
using var syncScope = profile.GetSyncScope();
foreach (var plugin in profile.Plugins.ToArray())
{
didAny = true;
var pmPlugin = pm.InstalledPlugins.FirstOrDefault(x => x.Manifest.InternalName == plugin.InternalName);
var pmPlugin = pm.InstalledPlugins.FirstOrDefault(x => x.Manifest.WorkingPluginId == plugin.WorkingPluginId);
var btnOffset = 2;
if (pmPlugin != null)
@ -460,26 +460,33 @@ internal class ProfileManagerWidget
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (pluginLineHeight / 2) - (textHeight.Y / 2));
ImGui.TextUnformatted(text);
var available =
var firstAvailableInstalled = pm.InstalledPlugins.FirstOrDefault(x => x.InternalName == plugin.InternalName);
var installable =
pm.AvailablePlugins.FirstOrDefault(
x => x.InternalName == plugin.InternalName && !x.SourceRepo.IsThirdParty);
if (available != null)
if (firstAvailableInstalled != null)
{
// TODO
ImGui.Text("GOAT WAS TOO LAZY TO IMPLEMENT THIS");
}
else if (installable != null)
{
ImGui.SameLine();
ImGui.SetCursorPosX(windowSize.X - (ImGuiHelpers.GlobalScale * 30 * 2) - 2);
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (pluginLineHeight / 2) - (ImGui.GetFrameHeight() / 2));
btnOffset = 3;
if (ImGuiComponents.IconButton($"###installMissingPlugin{available.InternalName}", FontAwesomeIcon.Download))
if (ImGuiComponents.IconButton($"###installMissingPlugin{installable.InternalName}", FontAwesomeIcon.Download))
{
this.installer.StartInstall(available, false);
this.installer.StartInstall(installable, false);
}
if (ImGui.IsItemHovered())
ImGui.SetTooltip(Locs.InstallPlugin);
}
ImGui.SetCursorPos(before);
}
@ -490,7 +497,7 @@ internal class ProfileManagerWidget
var enabled = plugin.IsEnabled;
if (ImGui.Checkbox($"###{this.editingProfileGuid}-{plugin.InternalName}", ref enabled))
{
Task.Run(() => profile.AddOrUpdateAsync(plugin.InternalName, enabled))
Task.Run(() => profile.AddOrUpdateAsync(plugin.WorkingPluginId, enabled))
.ContinueWith(this.installer.DisplayErrorContinuation, Locs.ErrorCouldNotChangeState);
}
@ -500,17 +507,17 @@ internal class ProfileManagerWidget
if (ImGuiComponents.IconButton($"###removePlugin{plugin.InternalName}", FontAwesomeIcon.Trash))
{
wantRemovePluginInternalName = plugin.InternalName;
wantRemovePluginGuid = plugin.WorkingPluginId;
}
if (ImGui.IsItemHovered())
ImGui.SetTooltip(Locs.RemovePlugin);
}
if (wantRemovePluginInternalName != null)
if (wantRemovePluginGuid != null)
{
// TODO: handle error
Task.Run(() => profile.RemoveAsync(wantRemovePluginInternalName, false))
Task.Run(() => profile.RemoveAsync(wantRemovePluginGuid.Value, false))
.ContinueWith(this.installer.DisplayErrorContinuation, Locs.ErrorCouldNotRemove);
}