remove plugins from deleting profile synchronously

This commit is contained in:
goat 2023-04-10 20:25:46 +02:00
parent 2ed215b74b
commit 7fe004c875
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
2 changed files with 8 additions and 4 deletions

View file

@ -243,7 +243,9 @@ internal class ProfileManagerWidget
if (ImGuiComponents.IconButton(FontAwesomeIcon.Trash)) if (ImGuiComponents.IconButton(FontAwesomeIcon.Trash))
{ {
Task.Run(() => profman.DeleteProfile(profile)) // DeleteProfile() is sync, it doesn't apply and we are modifying the plugins collection. Will throw below when iterating
profman.DeleteProfile(profile);
Task.Run(() => profman.ApplyAllWantStates())
.ContinueWith(t => .ContinueWith(t =>
{ {
this.Reset(); this.Reset();

View file

@ -232,13 +232,16 @@ internal class ProfileManager : IServiceType
} }
/// <summary> /// <summary>
/// Delete a profile and re-apply all profiles. /// Delete a profile.
/// </summary> /// </summary>
/// <remarks>
/// You should definitely apply states after this. It doesn't do it for you.
/// </remarks>
/// <param name="profile">The profile to delete.</param> /// <param name="profile">The profile to delete.</param>
public void DeleteProfile(Profile profile) public void DeleteProfile(Profile profile)
{ {
// We need to remove all plugins from the profile first, so that they are re-added to the default profile if needed // We need to remove all plugins from the profile first, so that they are re-added to the default profile if needed
foreach (var plugin in profile.Plugins) foreach (var plugin in profile.Plugins.ToArray())
{ {
profile.Remove(plugin.InternalName, false); profile.Remove(plugin.InternalName, false);
} }
@ -246,7 +249,6 @@ internal class ProfileManager : IServiceType
Debug.Assert(this.config.SavedProfiles!.Remove(profile.Model), "this.config.SavedProfiles!.Remove(profile.Model)"); Debug.Assert(this.config.SavedProfiles!.Remove(profile.Model), "this.config.SavedProfiles!.Remove(profile.Model)");
Debug.Assert(this.profiles.Remove(profile), "this.profiles.Remove(profile)"); Debug.Assert(this.profiles.Remove(profile), "this.profiles.Remove(profile)");
this.ApplyAllWantStates();
this.config.QueueSave(); this.config.QueueSave();
} }