mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 08:56:15 +02:00
Rename Plugin & API namespaces and implement saving/loading of setting
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.31205.134
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.8.34309.116
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopMagic", "DesktopMagic\DesktopMagic.csproj", "{B56B4CCC-CF92-4C05-9DEA-57666D81889A}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopMagicPluginAPI", "DesktopMagicPluginAPI\DesktopMagicPluginAPI.csproj", "{9D193A10-3E8E-447F-89F1-4B316C2EE37D}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopMagic.Api", "DesktopMagicPluginAPI\DesktopMagic.Api.csproj", "{9D193A10-3E8E-447F-89F1-4B316C2EE37D}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopMagicPlugin.Test", "DesktopMagicPlugin.Test\DesktopMagicPlugin.Test.csproj", "{EF8407AB-28AE-4B5E-AC2E-D4C4A575FBC7}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopMagic.PluginTest", "DesktopMagicPlugin.Test\DesktopMagic.PluginTest.csproj", "{EF8407AB-28AE-4B5E-AC2E-D4C4A575FBC7}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopMagic.Installer", "DesktopMagic.Installer\DesktopMagic.Installer.csproj", "{A06BD685-7F92-4799-846B-3EC38345108E}"
|
||||
EndProject
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using DesktopMagicPluginAPI;
|
||||
using DesktopMagicPluginAPI.Inputs;
|
||||
using DesktopMagicPluginAPI.Settings;
|
||||
using DesktopMagic.Api;
|
||||
using DesktopMagic.Api.Settings;
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
@@ -10,16 +9,16 @@ namespace DesktopMagic.BuiltInWindowElements;
|
||||
|
||||
internal class DatePlugin : Plugin
|
||||
{
|
||||
[Setting("Short date")]
|
||||
[Setting("short-date", "Short date")]
|
||||
private readonly CheckBox shortDatecheckBox = new CheckBox(true);
|
||||
|
||||
private DateTime oldDateTime = DateTime.MinValue;
|
||||
private Color oldColor = Color.White;
|
||||
private string oldFont;
|
||||
private string oldFont = string.Empty;
|
||||
private bool oldShortDatecheckBoxValue;
|
||||
public override int UpdateInterval => 1000;
|
||||
|
||||
public override Bitmap Main()
|
||||
public override Bitmap? Main()
|
||||
{
|
||||
if (oldDateTime.Date == DateTime.Now.Date && oldColor == Application.Theme.PrimaryColor && oldFont == Application.Theme.Font && oldShortDatecheckBoxValue == shortDatecheckBox.Value)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using DesktopMagic.Helpers;
|
||||
|
||||
using DesktopMagicPluginAPI;
|
||||
using DesktopMagicPluginAPI.Inputs;
|
||||
using DesktopMagicPluginAPI.Settings;
|
||||
using DesktopMagic.Api;
|
||||
using DesktopMagic.Api.Settings;
|
||||
using DesktopMagic.Helpers;
|
||||
|
||||
using NAudio.Wave;
|
||||
|
||||
@@ -22,22 +20,22 @@ internal class MusicVisualizerPlugin : Plugin
|
||||
|
||||
private readonly Bitmap output = new Bitmap(880, 300);
|
||||
|
||||
[Setting("Mirror")]
|
||||
[Setting("mirror", "Mirror")]
|
||||
private readonly CheckBox mirrorMode = new CheckBox(false);
|
||||
|
||||
[Setting("Line")]
|
||||
[Setting("line", "Line")]
|
||||
private readonly CheckBox lineMode = new CheckBox(false);
|
||||
|
||||
[Setting("Spectrum Mode")]
|
||||
[Setting("spectrum-mode", "Spectrum Mode")]
|
||||
private readonly ComboBox spectrumMode = new ComboBox("Bottom", "Middle", "Top");
|
||||
|
||||
[Setting("Amplification")]
|
||||
[Setting("amplification", "Amplification")]
|
||||
private readonly IntegerUpDown amplifierLevel = new IntegerUpDown(-50, 50, 0);
|
||||
|
||||
[Setting("Line thickness")]
|
||||
[Setting("line-thickness", "Line thickness")]
|
||||
private readonly IntegerUpDown lineThickness = new IntegerUpDown(1, 10, 1);
|
||||
|
||||
private WasapiLoopbackCapture waveIn;
|
||||
private WasapiLoopbackCapture waveIn = null!;
|
||||
private volatile bool calculate = true;
|
||||
private List<double> lastFft = [];
|
||||
public override int UpdateInterval => 0;
|
||||
@@ -64,7 +62,7 @@ internal class MusicVisualizerPlugin : Plugin
|
||||
waveIn?.StopRecording();
|
||||
}
|
||||
|
||||
private void OnDataAvailable(object sender, WaveInEventArgs e)
|
||||
private void OnDataAvailable(object? sender, WaveInEventArgs e)
|
||||
{
|
||||
if (calculate)
|
||||
{
|
||||
@@ -80,7 +78,7 @@ internal class MusicVisualizerPlugin : Plugin
|
||||
}
|
||||
}
|
||||
|
||||
private void FftCalculated(object sender, FftEventArgs e)
|
||||
private void FftCalculated(object? sender, FftEventArgs e)
|
||||
{
|
||||
if (!calculate)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using DesktopMagicPluginAPI;
|
||||
using DesktopMagicPluginAPI.Inputs;
|
||||
using DesktopMagicPluginAPI.Settings;
|
||||
using DesktopMagic.Api;
|
||||
using DesktopMagic.Api.Settings;
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
@@ -10,13 +9,13 @@ namespace DesktopMagic.BuiltInWindowElements;
|
||||
|
||||
internal class TimePlugin : Plugin
|
||||
{
|
||||
[Setting("Display Seconds")]
|
||||
[Setting("display-seconds", "Display Seconds")]
|
||||
private readonly CheckBox displaySecondsCheckBox = new CheckBox(true);
|
||||
|
||||
public override int UpdateInterval => 1000;
|
||||
|
||||
private string? oldFont = null;
|
||||
private float maxWidth = 0;
|
||||
public override int UpdateInterval => 1000;
|
||||
|
||||
public override Bitmap Main()
|
||||
{
|
||||
string time = displaySecondsCheckBox.Value ? DateTime.Now.ToLongTimeString() : DateTime.Now.ToShortTimeString();
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DesktopMagicPluginAPI\DesktopMagicPluginAPI.csproj" />
|
||||
<ProjectReference Include="..\DesktopMagicPluginAPI\DesktopMagic.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -10,11 +10,11 @@ internal class SettingElementGenerator(ComboBox optionsComboBox)
|
||||
{
|
||||
private readonly ComboBox optionsComboBox = optionsComboBox;
|
||||
|
||||
public void Generate(InputElement settingElement, DockPanel dockPanel, TextBlock textBlock)
|
||||
public void Generate(SettingElement settingElement, DockPanel dockPanel, TextBlock textBlock)
|
||||
{
|
||||
dockPanel.UpdateLayout();
|
||||
textBlock.UpdateLayout();
|
||||
if (settingElement.Input is DesktopMagicPluginAPI.Inputs.Label eLabel)
|
||||
if (settingElement.Input is DesktopMagic.Api.Settings.Label eLabel)
|
||||
{
|
||||
textBlock.Text = eLabel.Value;
|
||||
textBlock.Margin = new Thickness(0, 5, 3, 0);
|
||||
@@ -33,7 +33,7 @@ internal class SettingElementGenerator(ComboBox optionsComboBox)
|
||||
});
|
||||
};
|
||||
}
|
||||
else if (settingElement.Input is DesktopMagicPluginAPI.Settings.Button eButton)
|
||||
else if (settingElement.Input is DesktopMagic.Api.Settings.Button eButton)
|
||||
{
|
||||
Button button = new()
|
||||
{
|
||||
@@ -66,7 +66,7 @@ internal class SettingElementGenerator(ComboBox optionsComboBox)
|
||||
|
||||
_ = dockPanel.Children.Add(button);
|
||||
}
|
||||
else if (settingElement.Input is DesktopMagicPluginAPI.Settings.CheckBox eCheckBox)
|
||||
else if (settingElement.Input is DesktopMagic.Api.Settings.CheckBox eCheckBox)
|
||||
{
|
||||
CheckBox checkBox = new()
|
||||
{
|
||||
@@ -96,7 +96,7 @@ internal class SettingElementGenerator(ComboBox optionsComboBox)
|
||||
|
||||
_ = dockPanel.Children.Add(checkBox);
|
||||
}
|
||||
else if (settingElement.Input is DesktopMagicPluginAPI.Settings.TextBox eTextBox)
|
||||
else if (settingElement.Input is DesktopMagic.Api.Settings.TextBox eTextBox)
|
||||
{
|
||||
TextBox textBox = new()
|
||||
{
|
||||
@@ -125,7 +125,7 @@ internal class SettingElementGenerator(ComboBox optionsComboBox)
|
||||
};
|
||||
_ = dockPanel.Children.Add(textBox);
|
||||
}
|
||||
else if (settingElement.Input is DesktopMagicPluginAPI.Settings.IntegerUpDown eIntegerUpDown)
|
||||
else if (settingElement.Input is DesktopMagic.Api.Settings.IntegerUpDown eIntegerUpDown)
|
||||
{
|
||||
Xceed.Wpf.Toolkit.IntegerUpDown integerUpDown = new()
|
||||
{
|
||||
@@ -155,7 +155,7 @@ internal class SettingElementGenerator(ComboBox optionsComboBox)
|
||||
};
|
||||
_ = dockPanel.Children.Add(integerUpDown);
|
||||
}
|
||||
else if (settingElement.Input is DesktopMagicPluginAPI.Settings.Slider eSlider)
|
||||
else if (settingElement.Input is DesktopMagic.Api.Settings.Slider eSlider)
|
||||
{
|
||||
Slider slider = new()
|
||||
{
|
||||
@@ -188,7 +188,7 @@ internal class SettingElementGenerator(ComboBox optionsComboBox)
|
||||
|
||||
_ = dockPanel.Children.Add(slider);
|
||||
}
|
||||
else if (settingElement.Input is DesktopMagicPluginAPI.Settings.ComboBox eComboBox)
|
||||
else if (settingElement.Input is DesktopMagic.Api.Settings.ComboBox eComboBox)
|
||||
{
|
||||
ComboBox comboBox = new()
|
||||
{
|
||||
@@ -196,14 +196,14 @@ internal class SettingElementGenerator(ComboBox optionsComboBox)
|
||||
IsEditable = false,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch,
|
||||
SelectedIndex = 0
|
||||
SelectedItem = eComboBox.Value
|
||||
};
|
||||
|
||||
comboBox.SelectionChanged += (_s, _e) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
eComboBox.Value = comboBox.SelectedItem.ToString();
|
||||
eComboBox.Value = comboBox.SelectedItem.ToString() ?? string.Empty;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -224,7 +224,7 @@ internal class SettingElementGenerator(ComboBox optionsComboBox)
|
||||
{
|
||||
App.Logger.Log(message, "PluginInput");
|
||||
_ = MessageBox.Show("File execution error:\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
int index = MainWindow.WindowNames.IndexOf(optionsComboBox.SelectedItem.ToString());
|
||||
int index = MainWindow.WindowNames.IndexOf(optionsComboBox.SelectedItem.ToString() ?? string.Empty);
|
||||
|
||||
PluginWindow window = MainWindow.Windows[index];
|
||||
window?.Exit();
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
Loaded="Window_Loaded">
|
||||
|
||||
<Grid x:Name="grid">
|
||||
<TextBlock x:Name="textBlock" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" FontFamily="Comic Sans MS" Loaded="TextBlock_Loaded" Foreground="Transparent" />
|
||||
<TextBlock TextWrapping="Wrap" Text="0" VerticalAlignment="Top" FontFamily="Comic Sans MS" Loaded="TextBlock_Loaded" Foreground="Transparent" />
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
|
||||
@@ -4,17 +4,12 @@ using DesktopMagic.Helpers;
|
||||
using DesktopMagic.Plugins;
|
||||
using DesktopMagic.Settings;
|
||||
|
||||
using Microsoft.Win32;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -29,17 +24,18 @@ namespace DesktopMagic
|
||||
private readonly System.Windows.Forms.NotifyIcon notifyIcon = new();
|
||||
|
||||
private readonly MainWindowDataContext mainWindowDataContext = new();
|
||||
private bool loaded = false;
|
||||
private bool blockWindowsClosing = true;
|
||||
public static List<PluginWindow> Windows { get; } = [];
|
||||
public static List<string> WindowNames { get; } = [];
|
||||
|
||||
private Dictionary<string, Type> builtInPlugins = new()
|
||||
private readonly Dictionary<string, Type> builtInPlugins = new()
|
||||
{
|
||||
{"Music Visualizer", typeof(MusicVisualizerPlugin)},
|
||||
{"Time", typeof(TimePlugin)},
|
||||
{"Date", typeof(DatePlugin)}
|
||||
};
|
||||
|
||||
private bool loaded = false;
|
||||
private bool blockWindowsClosing = true;
|
||||
public static List<PluginWindow> Windows { get; } = [];
|
||||
public static List<string> WindowNames { get; } = [];
|
||||
internal static bool EditMode { get; set; } = false;
|
||||
|
||||
private DesktopMagicSettings Settings
|
||||
@@ -184,7 +180,7 @@ namespace DesktopMagic
|
||||
|
||||
if (builtInPlugins.TryGetValue(pluginName, out Type? pluginType))
|
||||
{
|
||||
window = new PluginWindow((DesktopMagicPluginAPI.Plugin)Activator.CreateInstance(pluginType)!, pluginName, pluginSettings)
|
||||
window = new PluginWindow((DesktopMagic.Api.Plugin)Activator.CreateInstance(pluginType)!, pluginName, pluginSettings)
|
||||
{
|
||||
Title = pluginName
|
||||
};
|
||||
@@ -337,7 +333,7 @@ namespace DesktopMagic
|
||||
|
||||
SettingElementGenerator settingElementGenerator = new SettingElementGenerator(optionsComboBox);
|
||||
|
||||
foreach (InputElement settingElement in pluginSettings.Settings)
|
||||
foreach (SettingElement settingElement in pluginSettings.Settings)
|
||||
{
|
||||
DockPanel dockPanel = new()
|
||||
{
|
||||
@@ -466,8 +462,14 @@ namespace DesktopMagic
|
||||
InputDialog inputDialog = new((string)FindResource("enterLayoutName"));
|
||||
if (inputDialog.ShowDialog() == true)
|
||||
{
|
||||
Settings.Layouts.Add(new Layout(inputDialog.ResponseText));
|
||||
Settings.CurrentLayoutName = inputDialog.ResponseText;
|
||||
if (Settings.Layouts.Any(l => l.Name.Trim() == inputDialog.ResponseText.Trim()))
|
||||
{
|
||||
_ = MessageBox.Show((string)FindResource("layoutAlreadyExists"));
|
||||
return;
|
||||
}
|
||||
|
||||
Settings.Layouts.Add(new Layout(inputDialog.ResponseText.Trim()));
|
||||
Settings.CurrentLayoutName = inputDialog.ResponseText.Trim();
|
||||
SaveSettings();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
using DesktopMagicPluginAPI.Settings;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace DesktopMagic.Plugins;
|
||||
|
||||
public class InputElement
|
||||
{
|
||||
public Setting Input { get; }
|
||||
public string Name { get; }
|
||||
public int OrderIndex { get; }
|
||||
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
|
||||
public InputElement(Setting input, string name, int orderIndex)
|
||||
{
|
||||
Input = input;
|
||||
Name = name;
|
||||
OrderIndex = orderIndex;
|
||||
}
|
||||
|
||||
[JsonConstructor]
|
||||
private InputElement()
|
||||
{
|
||||
}
|
||||
|
||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using DesktopMagic.Settings;
|
||||
|
||||
using DesktopMagicPluginAPI;
|
||||
using DesktopMagic.Api;
|
||||
using DesktopMagic.Settings;
|
||||
|
||||
using System.Drawing;
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
using DesktopMagic.Helpers;
|
||||
using DesktopMagic.Api;
|
||||
using DesktopMagic.Api.Drawing;
|
||||
using DesktopMagic.Api.Settings;
|
||||
using DesktopMagic.Helpers;
|
||||
using DesktopMagic.Plugins;
|
||||
using DesktopMagic.Settings;
|
||||
|
||||
using DesktopMagicPluginAPI;
|
||||
using DesktopMagicPluginAPI.Drawing;
|
||||
using DesktopMagicPluginAPI.Inputs;
|
||||
using DesktopMagicPluginAPI.Settings;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
@@ -254,7 +252,7 @@ public partial class PluginWindow : Window
|
||||
FieldInfo[] props = instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.GetField);
|
||||
#pragma warning restore S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
|
||||
|
||||
List<InputElement> settingElements = [];
|
||||
List<SettingElement> settingElements = [];
|
||||
foreach (FieldInfo prop in props)
|
||||
{
|
||||
if (prop.GetValue(instance) is Setting element)
|
||||
@@ -264,7 +262,15 @@ public partial class PluginWindow : Window
|
||||
{
|
||||
if (attribute is SettingAttribute elementAttribute)
|
||||
{
|
||||
settingElements.Add(new InputElement(element, elementAttribute.Name, elementAttribute.OrderIndex));
|
||||
SettingElement settingElement = new SettingElement(element, elementAttribute.Id, elementAttribute.Name, elementAttribute.OrderIndex);
|
||||
|
||||
if (settings.Settings.Exists(e => e.Id == elementAttribute.Id))
|
||||
{
|
||||
SettingElement settingsSettingElement = settings.Settings.First(e => e.Id == elementAttribute.Id);
|
||||
settingElement.JsonValue = settingsSettingElement.JsonValue;
|
||||
}
|
||||
|
||||
settingElements.Add(settingElement);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using DesktopMagic.Api.Settings;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace DesktopMagic.Plugins;
|
||||
|
||||
public class SettingElement
|
||||
{
|
||||
private string jsonValue = string.Empty;
|
||||
|
||||
[JsonIgnore]
|
||||
public Setting Input { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
public int OrderIndex { get; set; }
|
||||
|
||||
public string Id { get; set; }
|
||||
|
||||
public string JsonValue
|
||||
{
|
||||
get => Input?.GetJsonValue() ?? jsonValue;
|
||||
set
|
||||
{
|
||||
if (Input is null)
|
||||
{
|
||||
jsonValue = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
Input.SetJsonValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SettingElement(Setting input, string id, string name, int orderIndex)
|
||||
{
|
||||
Input = input;
|
||||
Id = id;
|
||||
Name = name;
|
||||
OrderIndex = orderIndex;
|
||||
}
|
||||
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
|
||||
[JsonConstructor]
|
||||
private SettingElement()
|
||||
{
|
||||
}
|
||||
|
||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using DesktopMagic.Helpers;
|
||||
|
||||
using DesktopMagicPluginAPI;
|
||||
using DesktopMagic.Api;
|
||||
using DesktopMagic.Helpers;
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<system:String x:Key="ok">Ok</system:String>
|
||||
<system:String x:Key="cancel">Abbrechen</system:String>
|
||||
<system:String x:Key="enterLayoutName">Layoutnamen eingeben:</system:String>
|
||||
<system:String x:Key="layoutAlreadyExists">Layout exestiert bereits!</system:String>
|
||||
<col:ArrayList x:Key="musicVisualizerOptionsComboboxItems">
|
||||
<system:String>Unten</system:String>
|
||||
<system:String>Mitte</system:String>
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<system:String x:Key="ok">Ok</system:String>
|
||||
<system:String x:Key="cancel">Cancel</system:String>
|
||||
<system:String x:Key="enterLayoutName">Enter layout name</system:String>
|
||||
<system:String x:Key="layoutAlreadyExists">Layout already exists!</system:String>
|
||||
<col:ArrayList x:Key="musicVisualizerOptionsComboboxItems">
|
||||
<system:String>Bottom</system:String>
|
||||
<system:String>Middle</system:String>
|
||||
|
||||
@@ -13,7 +13,7 @@ public class PluginSettings : INotifyPropertyChanged
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
private readonly Theme? theme;
|
||||
private List<InputElement> settings = [];
|
||||
private List<SettingElement> settings = [];
|
||||
private bool enabled = false;
|
||||
private Point position = new Point(100, 100);
|
||||
private Point size = new Point(300, 300);
|
||||
@@ -21,7 +21,7 @@ public class PluginSettings : INotifyPropertyChanged
|
||||
[JsonIgnore]
|
||||
public Theme Theme => theme is null ? MainWindowDataContext.GetSettings().CurrentLayout.Theme : theme;
|
||||
|
||||
public List<InputElement> Settings
|
||||
public List<SettingElement> Settings
|
||||
{
|
||||
get => settings;
|
||||
set
|
||||
|
||||
+1
-1
@@ -10,6 +10,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DesktopMagicPluginAPI\DesktopMagicPluginAPI.csproj" />
|
||||
<ProjectReference Include="..\DesktopMagicPluginAPI\DesktopMagic.Api.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,6 +1,5 @@
|
||||
using DesktopMagicPluginAPI;
|
||||
using DesktopMagicPluginAPI.Inputs;
|
||||
using DesktopMagicPluginAPI.Settings;
|
||||
using DesktopMagic.Api;
|
||||
using DesktopMagic.Api.Settings;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -9,16 +8,16 @@ using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DesktopMagicPlugin.Test;
|
||||
namespace DesktopMagic.PluginTest;
|
||||
|
||||
public class GifPlugin : Plugin
|
||||
{
|
||||
private const string SaveFilePath = "gifPath.txt";
|
||||
|
||||
[Setting("Gif path:")]
|
||||
[Setting("gif-path", "Gif path:")]
|
||||
private readonly TextBox input = new TextBox("");
|
||||
|
||||
[Setting]
|
||||
[Setting("info")]
|
||||
private readonly Label info = new Label("");
|
||||
|
||||
private readonly List<Bitmap> bitmaps = [];
|
||||
@@ -64,7 +63,7 @@ public class GifPlugin : Plugin
|
||||
|
||||
PropertyItem item = gif.GetPropertyItem(0x5100); // FrameDelay in libgdiplus
|
||||
|
||||
UpdateInterval = (item.Value[0] + (item.Value[1] * 256)) * 10; //FrameDelay in ms
|
||||
UpdateInterval = (item.Value[0] + item.Value[1] * 256) * 10; //FrameDelay in ms
|
||||
bitmaps.Clear();
|
||||
for (int i = 0; i < gif.GetFrameCount(FrameDimension.Time); i++)
|
||||
{
|
||||
|
||||
+1
@@ -11,6 +11,7 @@
|
||||
<AssemblyVersion>0.0.0.5</AssemblyVersion>
|
||||
<PackageProjectUrl></PackageProjectUrl>
|
||||
<FileVersion>0.0.0.5</FileVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Drawing;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Drawing;
|
||||
namespace DesktopMagic.Api.Drawing;
|
||||
|
||||
internal class FontComparer : IEqualityComparer<Font>
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Drawing;
|
||||
namespace DesktopMagic.Api.Drawing;
|
||||
|
||||
/// <summary>
|
||||
/// Extensions for the <see cref="Graphics"/> class.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace DesktopMagicPluginAPI.Drawing;
|
||||
namespace DesktopMagic.Api.Drawing;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies which render quality is used to display the bitmap images.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace DesktopMagicPluginAPI;
|
||||
namespace DesktopMagic.Api;
|
||||
|
||||
/// <summary>
|
||||
/// Defines properties and methods that provide information about the main application.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace DesktopMagicPluginAPI;
|
||||
namespace DesktopMagic.Api;
|
||||
|
||||
/// <summary>
|
||||
/// The theme settings of the main application.
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using DesktopMagicPluginAPI.Drawing;
|
||||
using DesktopMagicPluginAPI.Inputs;
|
||||
using DesktopMagic.Api.Drawing;
|
||||
using DesktopMagic.Api.Settings;
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace DesktopMagicPluginAPI;
|
||||
namespace DesktopMagic.Api;
|
||||
|
||||
/// <summary>
|
||||
/// The plugin class.
|
||||
@@ -50,7 +50,7 @@ public abstract class Plugin
|
||||
/// Occurs when the <see cref="UpdateInterval"/> elapses.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract Bitmap Main();
|
||||
public abstract Bitmap? Main();
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the window is clicked by the mouse.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Settings;
|
||||
namespace DesktopMagic.Api.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a button control.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace DesktopMagicPluginAPI.Settings;
|
||||
namespace DesktopMagic.Api.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a check box control.
|
||||
@@ -31,4 +31,15 @@ public class CheckBox : Setting
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
internal override string GetJsonValue()
|
||||
{
|
||||
return Value.ToString();
|
||||
}
|
||||
|
||||
internal override void SetJsonValue(string value)
|
||||
{
|
||||
_ = bool.TryParse(value, out bool result);
|
||||
Value = result;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
using DesktopMagicPluginAPI.Inputs;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json;
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Settings;
|
||||
namespace DesktopMagic.Api.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a selection control with a drop-down list.
|
||||
@@ -44,4 +43,25 @@ public class ComboBox : Setting
|
||||
Items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
internal override string GetJsonValue()
|
||||
{
|
||||
return JsonSerializer.Serialize(new { Value, Items });
|
||||
}
|
||||
|
||||
internal override void SetJsonValue(string value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
JsonElement json = JsonSerializer.Deserialize<JsonElement>(value);
|
||||
Items.Clear();
|
||||
foreach (JsonElement item in json.GetProperty(nameof(Items)).EnumerateArray())
|
||||
{
|
||||
Items.Add(item.GetString() ?? string.Empty);
|
||||
}
|
||||
Value = json.GetProperty(nameof(Value)).GetString() ?? string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Settings;
|
||||
namespace DesktopMagic.Api.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a up-down control.
|
||||
@@ -61,4 +61,15 @@ public class IntegerUpDown : Setting
|
||||
Maximum = max;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
internal override string GetJsonValue()
|
||||
{
|
||||
return Value.ToString();
|
||||
}
|
||||
|
||||
internal override void SetJsonValue(string value)
|
||||
{
|
||||
_ = int.TryParse(value, out int result);
|
||||
Value = result;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using DesktopMagicPluginAPI.Settings;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Inputs;
|
||||
namespace DesktopMagic.Api.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a label control.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace DesktopMagicPluginAPI.Inputs;
|
||||
namespace DesktopMagic.Api.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Mouse Buttons
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Settings;
|
||||
[assembly: InternalsVisibleTo("DesktopMagic")]
|
||||
|
||||
namespace DesktopMagic.Api.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// The element base class.
|
||||
@@ -10,7 +13,15 @@ public abstract class Setting
|
||||
/// <summary>
|
||||
/// Occurs when the value has been changed.
|
||||
/// </summary>
|
||||
public event Action OnValueChanged;
|
||||
public event Action? OnValueChanged;
|
||||
|
||||
internal virtual string GetJsonValue()
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
internal virtual void SetJsonValue(string value)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Triggers the <see cref="OnValueChanged"/> event.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Inputs;
|
||||
namespace DesktopMagic.Api.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Marks a Property as element.
|
||||
@@ -11,20 +11,27 @@ public class SettingAttribute : Attribute
|
||||
/// <summary>
|
||||
/// The name of the element.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The order index of the element.
|
||||
/// </summary>
|
||||
public int OrderIndex { get; }
|
||||
public int OrderIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The id of the element.
|
||||
/// </summary>
|
||||
public string Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Marks a Property as element with the provided <paramref name="name"/> and <paramref name="orderIndex"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the element.</param>
|
||||
/// <param name="name">The name of the element.</param>
|
||||
/// <param name="orderIndex">The order index of the element.</param>
|
||||
public SettingAttribute(string name, int orderIndex = 0)
|
||||
public SettingAttribute(string id, string name, int orderIndex = 0)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
OrderIndex = orderIndex;
|
||||
}
|
||||
@@ -32,14 +39,17 @@ public class SettingAttribute : Attribute
|
||||
/// <summary>
|
||||
/// Marks a Property as element with the provided <paramref name="orderIndex"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the element.</param>
|
||||
/// <param name="orderIndex">The order index of the element.</param>
|
||||
public SettingAttribute(int orderIndex)
|
||||
public SettingAttribute(string id, int orderIndex)
|
||||
{
|
||||
Id = id;
|
||||
OrderIndex = orderIndex;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="SettingAttribute"/>
|
||||
public SettingAttribute()
|
||||
public SettingAttribute(string id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Settings;
|
||||
namespace DesktopMagic.Api.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a slider control.
|
||||
@@ -60,4 +60,15 @@ public sealed class Slider : Setting
|
||||
Maximum = max;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
internal override string GetJsonValue()
|
||||
{
|
||||
return Value.ToString();
|
||||
}
|
||||
|
||||
internal override void SetJsonValue(string value)
|
||||
{
|
||||
_ = double.TryParse(value, out double result);
|
||||
Value = result;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace DesktopMagicPluginAPI.Settings;
|
||||
namespace DesktopMagic.Api.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a text box control.
|
||||
@@ -31,4 +31,14 @@ public class TextBox : Setting
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
internal override string GetJsonValue()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
internal override void SetJsonValue(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user