Refactored plugin settings handling for maintainability (#515)

This commit is contained in:
Thorsten Sommer 2025-06-27 22:52:34 +02:00 committed by GitHub
parent 1b8ed286e7
commit 7df0b3e6e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 1 deletions

View File

@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
using System.Text.Json; using System.Text.Json;
using AIStudio.Provider; using AIStudio.Provider;
@ -347,4 +348,21 @@ public sealed class SettingsManager
return ConfidenceLevel.UNKNOWN; return ConfidenceLevel.UNKNOWN;
} }
} }
public static string ToSettingName<T>(Expression<Func<T, object>> propertyExpression)
{
MemberExpression? memberExpr;
// Handle the case where the expression is a unary expression (e.g., when using Convert):
if (propertyExpression.Body is UnaryExpression { NodeType: ExpressionType.Convert } unaryExpr)
memberExpr = unaryExpr.Operand as MemberExpression;
else
memberExpr = propertyExpression.Body as MemberExpression;
if (memberExpr is null)
throw new ArgumentException("Expression must be a property access", nameof(propertyExpression));
// Return the full name of the property, including the class name:
return $"{typeof(T).Name}.{memberExpr.Member.Name}";
}
} }

View File

@ -48,7 +48,7 @@ public sealed class PluginConfiguration(bool isInternal, LuaState state, PluginT
return false; return false;
} }
if (settingsTable.TryGetValue("DataApp.UpdateBehavior", out var updateBehaviorValue) && updateBehaviorValue.TryRead<string>(out var updateBehaviorText) && Enum.TryParse<UpdateBehavior>(updateBehaviorText, true, out var updateBehavior)) if (settingsTable.TryGetValue(SettingsManager.ToSettingName<DataApp>(x => x.UpdateBehavior), out var updateBehaviorValue) && updateBehaviorValue.TryRead<string>(out var updateBehaviorText) && Enum.TryParse<UpdateBehavior>(updateBehaviorText, true, out var updateBehavior))
{ {
SETTINGS_LOCKER.Register<DataApp>(x => x.UpdateBehavior, this.Id); SETTINGS_LOCKER.Register<DataApp>(x => x.UpdateBehavior, this.Id);
SETTINGS_MANAGER.ConfigurationData.App.UpdateBehavior = updateBehavior; SETTINGS_MANAGER.ConfigurationData.App.UpdateBehavior = updateBehavior;

View File

@ -2,6 +2,7 @@
- Added a library by Nils Kruthoff (`nilskruthoff`) that allows AI Studio to read PowerPoint files. This feature is not yet available in the UI, but it will soon be available. Thanks, Nils, for that great contribution. - Added a library by Nils Kruthoff (`nilskruthoff`) that allows AI Studio to read PowerPoint files. This feature is not yet available in the UI, but it will soon be available. Thanks, Nils, for that great contribution.
- Improved the loading of some components that require data fetching, resulting in a more responsive UI. - Improved the loading of some components that require data fetching, resulting in a more responsive UI.
- Improved some awkward phrasings in English and German. - Improved some awkward phrasings in English and German.
- Improved the implementation of configuration plugins to enhance long-term maintainability.
- Changed the timestamp display to use the local datetime format for the chats and assistants. - Changed the timestamp display to use the local datetime format for the chats and assistants.
- Fixed a bug when editing data sources that caused the selected retrieval process of an ERI data source to not load correctly. - Fixed a bug when editing data sources that caused the selected retrieval process of an ERI data source to not load correctly.
- Upgraded to Rust 1.88.0. - Upgraded to Rust 1.88.0.