don't write to the manifest when reloading dev plugins(fixes #1328)

genericizes the way WorkingPluginId is accessed away from the manifest, since we probably don't want to have it there in the future for regular plugins either
This commit is contained in:
goat 2024-05-14 00:27:11 +02:00
parent 9f32b05587
commit 913d4732b5
8 changed files with 82 additions and 79 deletions

View file

@ -2438,7 +2438,7 @@ internal class PluginInstallerWindow : Window, IDisposable
if (this.hasDevPlugins)
{
ImGuiHelpers.ScaledDummy(3);
ImGui.TextColored(ImGuiColors.DalamudGrey, $"WorkingPluginId: {manifest.WorkingPluginId}");
ImGui.TextColored(ImGuiColors.DalamudGrey, $"WorkingPluginId: {plugin.EffectiveWorkingPluginId}");
ImGuiHelpers.ScaledDummy(3);
}
@ -2621,10 +2621,10 @@ internal class PluginInstallerWindow : Window, IDisposable
var applicableForProfiles = plugin.Manifest.SupportsProfiles /*&& !plugin.IsDev*/;
var profilesThatWantThisPlugin = profileManager.Profiles
.Where(x => x.WantsPlugin(plugin.Manifest.WorkingPluginId) != null)
.Where(x => x.WantsPlugin(plugin.EffectiveWorkingPluginId) != null)
.ToArray();
var isInSingleProfile = profilesThatWantThisPlugin.Length == 1;
var isDefaultPlugin = profileManager.IsInDefaultProfile(plugin.Manifest.WorkingPluginId);
var isDefaultPlugin = profileManager.IsInDefaultProfile(plugin.EffectiveWorkingPluginId);
// Disable everything if the updater is running or another plugin is operating
var disabled = this.updateStatus == OperationStatus.InProgress || this.installStatus == OperationStatus.InProgress;
@ -2659,17 +2659,17 @@ internal class PluginInstallerWindow : Window, IDisposable
foreach (var profile in profileManager.Profiles.Where(x => !x.IsDefaultProfile))
{
var inProfile = profile.WantsPlugin(plugin.Manifest.WorkingPluginId) != null;
var inProfile = profile.WantsPlugin(plugin.EffectiveWorkingPluginId) != null;
if (ImGui.Checkbox($"###profilePick{profile.Guid}{plugin.Manifest.InternalName}", ref inProfile))
{
if (inProfile)
{
Task.Run(() => profile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, true))
Task.Run(() => profile.AddOrUpdateAsync(plugin.EffectiveWorkingPluginId, plugin.Manifest.InternalName, true))
.ContinueWith(this.DisplayErrorContinuation, Locs.Profiles_CouldNotAdd);
}
else
{
Task.Run(() => profile.RemoveAsync(plugin.Manifest.WorkingPluginId))
Task.Run(() => profile.RemoveAsync(plugin.EffectiveWorkingPluginId))
.ContinueWith(this.DisplayErrorContinuation, Locs.Profiles_CouldNotRemove);
}
}
@ -2689,11 +2689,11 @@ internal class PluginInstallerWindow : Window, IDisposable
if (ImGuiComponents.IconButton(FontAwesomeIcon.Times))
{
// TODO: Work this out
Task.Run(() => profileManager.DefaultProfile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, plugin.IsLoaded, false))
Task.Run(() => profileManager.DefaultProfile.AddOrUpdateAsync(plugin.EffectiveWorkingPluginId, plugin.Manifest.InternalName, 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.WorkingPluginId, false))
Task.Run(() => profile.RemoveAsync(plugin.EffectiveWorkingPluginId, false))
.GetAwaiter().GetResult();
}
@ -2718,7 +2718,7 @@ internal class PluginInstallerWindow : Window, IDisposable
if (ImGui.IsItemHovered())
ImGui.SetTooltip(Locs.PluginButtonToolTip_UnloadFailed);
}
else if (this.enableDisableStatus == OperationStatus.InProgress && this.enableDisableWorkingPluginId == plugin.Manifest.WorkingPluginId)
else if (this.enableDisableStatus == OperationStatus.InProgress && this.enableDisableWorkingPluginId == plugin.EffectiveWorkingPluginId)
{
ImGuiComponents.DisabledToggleButton(toggleId, this.loadingIndicatorKind == LoadingIndicatorKind.EnablingSingle);
}
@ -2743,9 +2743,9 @@ internal class PluginInstallerWindow : Window, IDisposable
{
// Reload the devPlugin manifest if it's a dev plugin
// The plugin might rely on changed values in the manifest
if (plugin.IsDev)
if (plugin is LocalDevPlugin devPlugin)
{
plugin.ReloadManifest();
devPlugin.ReloadManifest();
}
}
catch (Exception ex)
@ -2761,13 +2761,13 @@ internal class PluginInstallerWindow : Window, IDisposable
{
this.enableDisableStatus = OperationStatus.InProgress;
this.loadingIndicatorKind = LoadingIndicatorKind.DisablingSingle;
this.enableDisableWorkingPluginId = plugin.Manifest.WorkingPluginId;
this.enableDisableWorkingPluginId = plugin.EffectiveWorkingPluginId;
Task.Run(async () =>
{
await plugin.UnloadAsync();
await applicableProfile.AddOrUpdateAsync(
plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, false, false);
plugin.EffectiveWorkingPluginId, plugin.Manifest.InternalName, false, false);
notifications.AddNotification(Locs.Notifications_PluginDisabled(plugin.Manifest.Name), Locs.Notifications_PluginDisabledTitle, NotificationType.Success);
}).ContinueWith(t =>
@ -2782,9 +2782,9 @@ internal class PluginInstallerWindow : Window, IDisposable
{
this.enableDisableStatus = OperationStatus.InProgress;
this.loadingIndicatorKind = LoadingIndicatorKind.EnablingSingle;
this.enableDisableWorkingPluginId = plugin.Manifest.WorkingPluginId;
this.enableDisableWorkingPluginId = plugin.EffectiveWorkingPluginId;
await applicableProfile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, true, false);
await applicableProfile.AddOrUpdateAsync(plugin.EffectiveWorkingPluginId, plugin.Manifest.InternalName, true, false);
await plugin.LoadAsync(PluginLoadReason.Installer);
notifications.AddNotification(Locs.Notifications_PluginEnabled(plugin.Manifest.Name), Locs.Notifications_PluginEnabledTitle, NotificationType.Success);
@ -2805,7 +2805,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.Manifest.WorkingPluginId, plugin.Manifest.InternalName, true, false);
await applicableProfile.AddOrUpdateAsync(plugin.EffectiveWorkingPluginId, plugin.Manifest.InternalName, true, false);
await this.UpdateSinglePlugin(availableUpdate);
}
else
@ -3076,7 +3076,7 @@ internal class PluginInstallerWindow : Window, IDisposable
if (localPlugin is LocalDevPlugin plugin)
{
var isInDefaultProfile =
Service<ProfileManager>.Get().IsInDefaultProfile(localPlugin.Manifest.WorkingPluginId);
Service<ProfileManager>.Get().IsInDefaultProfile(localPlugin.EffectiveWorkingPluginId);
// https://colorswall.com/palette/2868/
var greenColor = new Vector4(0x5C, 0xB8, 0x5C, 0xFF) / 0xFF;
@ -3426,7 +3426,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.Manifest.WorkingPluginId).CompareTo(profman.IsInDefaultProfile(p2.Manifest.WorkingPluginId)));
this.pluginListInstalled.Sort((p1, p2) => profman.IsInDefaultProfile(p1.EffectiveWorkingPluginId).CompareTo(profman.IsInDefaultProfile(p2.EffectiveWorkingPluginId)));
break;
default:
throw new InvalidEnumArgumentException("Unknown plugin sort type.");

View file

@ -324,7 +324,7 @@ internal class ProfileManagerWidget
if (ImGui.Selectable($"{plugin.Manifest.Name}{(plugin is LocalDevPlugin ? "(dev plugin)" : string.Empty)}###selector{plugin.Manifest.InternalName}"))
{
Task.Run(() => profile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, true, false))
Task.Run(() => profile.AddOrUpdateAsync(plugin.EffectiveWorkingPluginId, plugin.Manifest.InternalName, true, false))
.ContinueWith(this.installer.DisplayErrorContinuation, Locs.ErrorCouldNotChangeState);
}
}
@ -430,7 +430,7 @@ internal class ProfileManagerWidget
foreach (var profileEntry in profile.Plugins.ToArray())
{
didAny = true;
var pmPlugin = pm.InstalledPlugins.FirstOrDefault(x => x.Manifest.WorkingPluginId == profileEntry.WorkingPluginId);
var pmPlugin = pm.InstalledPlugins.FirstOrDefault(x => x.EffectiveWorkingPluginId == profileEntry.WorkingPluginId);
var btnOffset = 2;
if (pmPlugin != null)
@ -485,7 +485,7 @@ internal class ProfileManagerWidget
FontAwesomeIcon.Check,
"Yes, use this one"))
{
profileEntry.WorkingPluginId = firstAvailableInstalled.Manifest.WorkingPluginId;
profileEntry.WorkingPluginId = firstAvailableInstalled.EffectiveWorkingPluginId;
Task.Run(async () =>
{
await profman.ApplyAllWantStatesAsync();