mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Sidebar - Added category reordering
Sidebar - Fix disabled profiles not fading Sidebar - Fix module missing when editing existing profile configs Profile - Remove old undo/redo code
This commit is contained in:
1 parent
5873df250d
commit
b6e0c0fb66
8 files changed
+71
-216
No files matched your search
@@ -10,11 +10,6 @@ namespace Artemis.Core.Services
|
||||
/// </summary>
|
||||
public interface IProfileService : IArtemisService
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the JSON serializer settings used to create profile mementos
|
||||
/// </summary>
|
||||
public static JsonSerializerSettings MementoSettings { get; } = new() {TypeNameHandling = TypeNameHandling.All};
|
||||
|
||||
/// <summary>
|
||||
/// Gets the JSON serializer settings used to import/export profiles
|
||||
/// </summary>
|
||||
@@ -101,26 +96,14 @@ namespace Artemis.Core.Services
|
||||
/// Saves the current icon of this profile
|
||||
/// </summary>
|
||||
void SaveProfileConfigurationIcon(ProfileConfiguration profileConfiguration);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Writes the profile to persistent storage
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
/// <param name="includeChildren"></param>
|
||||
void SaveProfile(Profile profile, bool includeChildren);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to restore the profile to the state it had before the last <see cref="SaveProfile" /> call.
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
bool UndoSaveProfile(Profile profile);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to restore the profile to the state it had before the last <see cref="UndoSaveProfile" /> call.
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
bool RedoSaveProfile(Profile profile);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Exports the profile described in the given <see cref="ProfileConfiguration" /> into an export model
|
||||
/// </summary>
|
||||
|
||||
@@ -442,88 +442,24 @@ namespace Artemis.Core.Services
|
||||
_profileCategories.Sort((a, b) => a.Order - b.Order);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SaveProfile(Profile profile, bool includeChildren)
|
||||
{
|
||||
string memento = JsonConvert.SerializeObject(profile.ProfileEntity, IProfileService.MementoSettings);
|
||||
_logger.Debug("Updating profile - Saving {Profile}", profile);
|
||||
profile.Save();
|
||||
if (includeChildren)
|
||||
{
|
||||
foreach (RenderProfileElement child in profile.GetAllRenderElements())
|
||||
child.Save();
|
||||
}
|
||||
|
||||
// If there are no changes, don't bother saving
|
||||
string updatedMemento = JsonConvert.SerializeObject(profile.ProfileEntity, IProfileService.MementoSettings);
|
||||
if (memento.Equals(updatedMemento))
|
||||
{
|
||||
_logger.Debug("Updating profile - Skipping save, no changes");
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.Debug("Updating profile - Saving " + profile);
|
||||
profile.RedoStack.Clear();
|
||||
profile.UndoStack.Push(memento);
|
||||
|
||||
|
||||
// At this point the user made actual changes, save that
|
||||
profile.IsFreshImport = false;
|
||||
profile.ProfileEntity.IsFreshImport = false;
|
||||
|
||||
_profileRepository.Save(profile.ProfileEntity);
|
||||
}
|
||||
|
||||
public bool UndoSaveProfile(Profile profile)
|
||||
{
|
||||
// Keep the profile from being rendered by locking it
|
||||
lock (profile)
|
||||
{
|
||||
if (profile.UndoStack.Count == 0)
|
||||
{
|
||||
_logger.Debug("Undo profile update - Failed, undo stack empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
string top = profile.UndoStack.Pop();
|
||||
string memento = JsonConvert.SerializeObject(profile.ProfileEntity, IProfileService.MementoSettings);
|
||||
profile.RedoStack.Push(memento);
|
||||
profile.ProfileEntity =
|
||||
JsonConvert.DeserializeObject<ProfileEntity>(top, IProfileService.MementoSettings)
|
||||
?? throw new InvalidOperationException("Failed to deserialize memento");
|
||||
|
||||
profile.Load();
|
||||
profile.PopulateLeds(_rgbService.EnabledDevices);
|
||||
}
|
||||
|
||||
_logger.Debug("Undo profile update - Success");
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool RedoSaveProfile(Profile profile)
|
||||
{
|
||||
// Keep the profile from being rendered by locking it
|
||||
lock (profile)
|
||||
{
|
||||
if (profile.RedoStack.Count == 0)
|
||||
{
|
||||
_logger.Debug("Redo profile update - Failed, redo empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
string top = profile.RedoStack.Pop();
|
||||
string memento = JsonConvert.SerializeObject(profile.ProfileEntity, IProfileService.MementoSettings);
|
||||
profile.UndoStack.Push(memento);
|
||||
profile.ProfileEntity =
|
||||
JsonConvert.DeserializeObject<ProfileEntity>(top, IProfileService.MementoSettings)
|
||||
?? throw new InvalidOperationException("Failed to deserialize memento");
|
||||
|
||||
profile.Load();
|
||||
profile.PopulateLeds(_rgbService.EnabledDevices);
|
||||
|
||||
_logger.Debug("Redo profile update - Success");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ProfileConfigurationExportModel ExportProfile(ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
// The profile may not be active and in that case lets activate it real quick
|
||||
@@ -596,8 +532,6 @@ namespace Artemis.Core.Services
|
||||
/// <inheritdoc />
|
||||
public void AdaptProfile(Profile profile)
|
||||
{
|
||||
string memento = JsonConvert.SerializeObject(profile.ProfileEntity, IProfileService.MementoSettings);
|
||||
|
||||
List<ArtemisDevice> devices = _rgbService.EnabledDevices.ToList();
|
||||
foreach (Layer layer in profile.GetAllLayers())
|
||||
layer.Adapter.Adapt(devices);
|
||||
@@ -608,9 +542,6 @@ namespace Artemis.Core.Services
|
||||
renderProfileElement.Save();
|
||||
|
||||
_logger.Debug("Adapt profile - Saving " + profile);
|
||||
profile.RedoStack.Clear();
|
||||
profile.UndoStack.Push(memento);
|
||||
|
||||
_profileRepository.Save(profile.ProfileEntity);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user