mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Data models - Added ClearDynamicChildren method
Plugins - Added async support for timed updates Plugins - Added dialog host to plugin settings window Data model visualization - Fixed some null references Data model visualization - Added check to ensure parameterless getters are present
This commit is contained in:
parent
c095f329c4
commit
17d41647b6
@ -67,10 +67,8 @@ namespace Artemis.Core.DataModelExpansions
|
||||
if (key.Contains('.'))
|
||||
throw new ArtemisCoreException("The provided key contains an illegal character (.)");
|
||||
if (_dynamicDataModels.ContainsKey(key))
|
||||
{
|
||||
throw new ArtemisCoreException($"Cannot add a dynamic data model with key '{key}' " +
|
||||
"because the key is already in use on by another dynamic property this data model.");
|
||||
}
|
||||
|
||||
if (_dynamicDataModels.ContainsValue(dynamicDataModel))
|
||||
{
|
||||
@ -80,10 +78,8 @@ namespace Artemis.Core.DataModelExpansions
|
||||
}
|
||||
|
||||
if (GetType().GetProperty(key) != null)
|
||||
{
|
||||
throw new ArtemisCoreException($"Cannot add a dynamic data model with key '{key}' " +
|
||||
"because the key is already in use by a static property on this data model.");
|
||||
}
|
||||
|
||||
dynamicDataModel.PluginInfo = PluginInfo;
|
||||
dynamicDataModel.DataModelDescription = new DataModelPropertyAttribute
|
||||
@ -125,6 +121,15 @@ namespace Artemis.Core.DataModelExpansions
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all dynamic data models from this data model
|
||||
/// </summary>
|
||||
public void ClearDynamicChildren()
|
||||
{
|
||||
while (_dynamicDataModels.Any())
|
||||
RemoveDynamicChildByKey(_dynamicDataModels.First().Key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a dynamic data model of type <typeparamref name="T" /> by its key
|
||||
/// </summary>
|
||||
|
||||
@ -23,12 +23,6 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public PluginConfigurationDialog ConfigurationDialog { get; protected set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
DisablePlugin();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the plugin is activated
|
||||
/// </summary>
|
||||
@ -40,11 +34,15 @@ namespace Artemis.Core
|
||||
public abstract void DisablePlugin();
|
||||
|
||||
/// <summary>
|
||||
/// Registers a timed update that whenever the plugin is enabled calls the provided <paramref name="action" /> at the provided
|
||||
/// Registers a timed update that whenever the plugin is enabled calls the provided <paramref name="action" /> at the
|
||||
/// provided
|
||||
/// <paramref name="interval" />
|
||||
/// </summary>
|
||||
/// <param name="interval">The interval at which the update should occur</param>
|
||||
/// <param name="action">The action to call every time the interval has passed. The delta time parameter represents the time passed since the last update in seconds</param>
|
||||
/// <param name="action">
|
||||
/// The action to call every time the interval has passed. The delta time parameter represents the
|
||||
/// time passed since the last update in seconds
|
||||
/// </param>
|
||||
/// <returns>The resulting plugin update registration</returns>
|
||||
public PluginUpdateRegistration AddTimedUpdate(TimeSpan interval, Action<double> action)
|
||||
{
|
||||
@ -53,6 +51,24 @@ namespace Artemis.Core
|
||||
return new PluginUpdateRegistration(PluginInfo, interval, action);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers a timed update that whenever the plugin is enabled calls the provided <paramref name="action" /> at the
|
||||
/// provided
|
||||
/// <paramref name="interval" />
|
||||
/// </summary>
|
||||
/// <param name="interval">The interval at which the update should occur</param>
|
||||
/// <param name="asyncAction">
|
||||
/// The async action to call every time the interval has passed. The delta time parameter
|
||||
/// represents the time passed since the last update in seconds
|
||||
/// </param>
|
||||
/// <returns>The resulting plugin update registration</returns>
|
||||
public PluginUpdateRegistration AddTimedUpdate(TimeSpan interval, Func<double, Task> asyncAction)
|
||||
{
|
||||
if (asyncAction == null)
|
||||
throw new ArgumentNullException(nameof(asyncAction));
|
||||
return new PluginUpdateRegistration(PluginInfo, interval, asyncAction);
|
||||
}
|
||||
|
||||
internal void SetEnabled(bool enable, bool isAutoEnable = false)
|
||||
{
|
||||
if (enable && !Enabled)
|
||||
@ -123,6 +139,12 @@ namespace Artemis.Core
|
||||
DisablePlugin();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
DisablePlugin();
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using Artemis.Core.Modules;
|
||||
|
||||
@ -24,6 +25,19 @@ namespace Artemis.Core
|
||||
Start();
|
||||
}
|
||||
|
||||
internal PluginUpdateRegistration(PluginInfo pluginInfo, TimeSpan interval, Func<double, Task> asyncAction)
|
||||
{
|
||||
PluginInfo = pluginInfo;
|
||||
Interval = interval;
|
||||
AsyncAction = asyncAction;
|
||||
|
||||
PluginInfo.Instance.PluginEnabled += InstanceOnPluginEnabled;
|
||||
PluginInfo.Instance.PluginDisabled += InstanceOnPluginDisabled;
|
||||
if (PluginInfo.Instance.Enabled)
|
||||
Start();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin info of the plugin this registration is associated with
|
||||
/// </summary>
|
||||
@ -40,7 +54,12 @@ namespace Artemis.Core
|
||||
public Action<double> Action { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Starts calling the <see cref="Action" /> at the configured <see cref="Interval" />
|
||||
/// Gets the task that gets called each time the update event fires
|
||||
/// </summary>
|
||||
public Func<double, Task> AsyncAction { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Starts calling the <see cref="Action" /> or <see cref="AsyncAction"/> at the configured <see cref="Interval" />
|
||||
/// <para>Note: Called automatically when the plugin enables</para>
|
||||
/// </summary>
|
||||
public void Start()
|
||||
@ -61,7 +80,7 @@ namespace Artemis.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops calling the <see cref="Action" /> at the configured <see cref="Interval" />
|
||||
/// Stops calling the <see cref="Action" /> or <see cref="AsyncAction"/> at the configured <see cref="Interval" />
|
||||
/// <para>Note: Called automatically when the plugin disables</para>
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
@ -90,7 +109,13 @@ namespace Artemis.Core
|
||||
if (PluginInfo.Instance is Module module && !module.IsUpdateAllowed)
|
||||
return;
|
||||
|
||||
Action(interval.TotalSeconds);
|
||||
if (Action != null)
|
||||
Action(interval.TotalSeconds);
|
||||
else if (AsyncAction != null)
|
||||
{
|
||||
Task task = AsyncAction(interval.TotalSeconds);
|
||||
task.Wait();
|
||||
}
|
||||
}
|
||||
|
||||
private void InstanceOnPluginEnabled(object sender, EventArgs e)
|
||||
|
||||
@ -121,7 +121,7 @@ namespace Artemis.UI.Shared
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[List] {DisplayPath ?? Path} - {List.Count} item(s)";
|
||||
return $"[List] {DisplayPath ?? Path} - {List?.Count ?? 0} item(s)";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -57,7 +57,9 @@ namespace Artemis.UI.Shared
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[{DisplayValueType.Name}] {DisplayPath ?? Path} - {DisplayValue}";
|
||||
if (DisplayValueType != null)
|
||||
return $"[{DisplayValueType.Name}] {DisplayPath ?? Path} - {DisplayValue}";
|
||||
return $"{DisplayPath ?? Path} - {DisplayValue}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -193,6 +193,9 @@ namespace Artemis.UI.Shared
|
||||
continue;
|
||||
if (propertyInfo.GetCustomAttribute<DataModelIgnoreAttribute>() != null)
|
||||
continue;
|
||||
MethodInfo getMethod = propertyInfo.GetGetMethod();
|
||||
if (getMethod == null || getMethod.GetParameters().Any())
|
||||
continue;
|
||||
|
||||
DataModelVisualizationViewModel child = CreateChild(dataModelUIService, childPath, GetChildDepth());
|
||||
if (child != null)
|
||||
|
||||
@ -18,13 +18,18 @@
|
||||
d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:PluginSettingsWindowViewModel}"
|
||||
Icon="/Resources/Images/Logo/logo-512.png">
|
||||
<DockPanel>
|
||||
<controls:AppBar Type="Dense" Title="{Binding ActiveItem.Plugin.PluginInfo.Name}" DockPanel.Dock="Top" Margin="-18 0 0 0" ShowShadow="False">
|
||||
<controls:AppBar.AppIcon>
|
||||
<materialDesign:PackIcon Kind="{Binding Icon}" Width="20" Height="28" />
|
||||
</controls:AppBar.AppIcon>
|
||||
</controls:AppBar>
|
||||
<materialDesign:DialogHost IsTabStop="False"
|
||||
Focusable="False"
|
||||
Identifier="PluginSettingsDialog"
|
||||
DialogTheme="Inherit">
|
||||
<DockPanel>
|
||||
<controls:AppBar Type="Dense" Title="{Binding ActiveItem.Plugin.PluginInfo.Name}" DockPanel.Dock="Top" Margin="-18 0 0 0" ShowShadow="False">
|
||||
<controls:AppBar.AppIcon>
|
||||
<materialDesign:PackIcon Kind="{Binding Icon}" Width="20" Height="28" />
|
||||
</controls:AppBar.AppIcon>
|
||||
</controls:AppBar>
|
||||
|
||||
<ContentControl s:View.Model="{Binding ActiveItem}" />
|
||||
</DockPanel>
|
||||
<ContentControl s:View.Model="{Binding ActiveItem}" />
|
||||
</DockPanel>
|
||||
</materialDesign:DialogHost>
|
||||
</controls:MaterialWindow>
|
||||
@ -7,12 +7,20 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
{
|
||||
public class PluginSettingsWindowViewModel : Conductor<PluginConfigurationViewModel>
|
||||
{
|
||||
private readonly PluginConfigurationViewModel _configurationViewModel;
|
||||
|
||||
public PluginSettingsWindowViewModel(PluginConfigurationViewModel configurationViewModel, PackIconKind icon)
|
||||
{
|
||||
_configurationViewModel = configurationViewModel ?? throw new ArgumentNullException(nameof(configurationViewModel));
|
||||
Icon = icon;
|
||||
ActiveItem = configurationViewModel ?? throw new ArgumentNullException(nameof(configurationViewModel));
|
||||
}
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
ActiveItem = _configurationViewModel;
|
||||
ActiveItem.Closed += ActiveItemOnClosed;
|
||||
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
public PackIconKind Icon { get; }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user