mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-07 15:56:13 +02:00
- Show version number in window title
- Add `PluginName` property to `IPluginData` - Add `PluginPath` property to `IPluginData`
This commit is contained in:
@@ -17,6 +17,7 @@ namespace DesktopMagic
|
|||||||
|
|
||||||
private static string ApplicationName = "Google Calendar API .NET " + MainWindow.AppName;
|
private static string ApplicationName = "Google Calendar API .NET " + MainWindow.AppName;
|
||||||
|
|
||||||
|
[Obsolete]
|
||||||
public (List<string>, List<string>) GetEvents()
|
public (List<string>, List<string>) GetEvents()
|
||||||
{
|
{
|
||||||
List<string> upcomingEventNames = new List<string>();
|
List<string> upcomingEventNames = new List<string>();
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using System.Windows.Media;
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Stone_Red_Utilities.Logging;
|
using Stone_Red_Utilities.Logging;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace DesktopMagic
|
namespace DesktopMagic
|
||||||
{
|
{
|
||||||
@@ -78,7 +79,7 @@ namespace DesktopMagic
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
SetLanguageDictionary();
|
SetLanguageDictionary();
|
||||||
this.Title = AppName;
|
this.Title = $"{AppName} - {Assembly.GetExecutingAssembly().GetName().Version}";
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -974,7 +975,7 @@ namespace DesktopMagic
|
|||||||
|
|
||||||
private void OpenPluginsFolderButton_Click(object sender, RoutedEventArgs e)
|
private void OpenPluginsFolderButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
_ = System.Diagnostics.Process.Start("explorer.exe", applicationDataPath + "\\Plugins");
|
_ = Process.Start("explorer.exe", applicationDataPath + "\\Plugins");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ScrollViewer_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
|
private void ScrollViewer_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ namespace DesktopMagic
|
|||||||
|
|
||||||
public Point WindowPosition => new Point((int)window.Left, (int)window.Top);
|
public Point WindowPosition => new Point((int)window.Left, (int)window.Top);
|
||||||
|
|
||||||
|
public string PluginName => window.PluginName;
|
||||||
|
|
||||||
|
public string PluginPath => window.PluginFolderPath;
|
||||||
|
|
||||||
public void UpdateWindow() => window.UpdatePluginWindow();
|
public void UpdateWindow() => window.UpdatePluginWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,8 +29,8 @@ namespace DesktopMagic
|
|||||||
private System.Timers.Timer valueTimer;
|
private System.Timers.Timer valueTimer;
|
||||||
|
|
||||||
private Plugin pluginClassInstance;
|
private Plugin pluginClassInstance;
|
||||||
private readonly string pluginName = "";
|
public string PluginName { get; private set; }
|
||||||
private string pluginFolderPath = "";
|
public string PluginFolderPath { get; private set; }
|
||||||
private bool stop = false;
|
private bool stop = false;
|
||||||
|
|
||||||
public event Action PluginLoaded;
|
public event Action PluginLoaded;
|
||||||
@@ -60,7 +60,7 @@ namespace DesktopMagic
|
|||||||
t.Elapsed += Elapsed;
|
t.Elapsed += Elapsed;
|
||||||
t.Start();
|
t.Start();
|
||||||
|
|
||||||
this.pluginName = pluginName;
|
this.PluginName = pluginName;
|
||||||
|
|
||||||
key = Registry.CurrentUser.CreateSubKey(@"Software\" + MainWindow.AppName);
|
key = Registry.CurrentUser.CreateSubKey(@"Software\" + MainWindow.AppName);
|
||||||
this.Top = double.Parse(key.GetValue(pluginName + "WindowTop", 100).ToString());
|
this.Top = double.Parse(key.GetValue(pluginName + "WindowTop", 100).ToString());
|
||||||
@@ -117,9 +117,9 @@ namespace DesktopMagic
|
|||||||
|
|
||||||
private void LoadPlugin()
|
private void LoadPlugin()
|
||||||
{
|
{
|
||||||
pluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{MainWindow.AppName}\\Plugins\\{pluginName}";
|
PluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{MainWindow.AppName}\\Plugins\\{PluginName}";
|
||||||
|
|
||||||
if (!File.Exists($"{pluginFolderPath}\\{pluginName}.dll"))
|
if (!File.Exists($"{PluginFolderPath}\\{PluginName}.dll"))
|
||||||
{
|
{
|
||||||
_ = MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
_ = MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
Exit();
|
Exit();
|
||||||
@@ -142,7 +142,7 @@ namespace DesktopMagic
|
|||||||
|
|
||||||
private void ExecuteSource()
|
private void ExecuteSource()
|
||||||
{
|
{
|
||||||
byte[] assemblyBytes = File.ReadAllBytes($"{pluginFolderPath}\\{pluginName}.dll");
|
byte[] assemblyBytes = File.ReadAllBytes($"{PluginFolderPath}\\{PluginName}.dll");
|
||||||
Assembly dll = Assembly.Load(assemblyBytes);
|
Assembly dll = Assembly.Load(assemblyBytes);
|
||||||
Type instanceType = dll.GetTypes().FirstOrDefault(type => type.GetTypeInfo().BaseType == typeof(Plugin));
|
Type instanceType = dll.GetTypes().FirstOrDefault(type => type.GetTypeInfo().BaseType == typeof(Plugin));
|
||||||
|
|
||||||
@@ -190,34 +190,45 @@ namespace DesktopMagic
|
|||||||
|
|
||||||
private void LoadOptions(object instance)
|
private void LoadOptions(object instance)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(instance.GetType().FullName);
|
try
|
||||||
FieldInfo[] props = instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.GetField);
|
|
||||||
|
|
||||||
List<SettingElement> settingElements = new List<SettingElement>();
|
|
||||||
foreach (FieldInfo prop in props)
|
|
||||||
{
|
{
|
||||||
if (prop.GetValue(instance) is Element element)
|
Debug.WriteLine(instance.GetType().FullName);
|
||||||
|
FieldInfo[] props = instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.GetField);
|
||||||
|
|
||||||
|
List<SettingElement> settingElements = new List<SettingElement>();
|
||||||
|
foreach (FieldInfo prop in props)
|
||||||
{
|
{
|
||||||
object[] attrs = prop.GetCustomAttributes(true);
|
if (prop.GetValue(instance) is Element element)
|
||||||
foreach (object attr in attrs)
|
|
||||||
{
|
{
|
||||||
if (attr is ElementAttribute elementAttribute)
|
object[] attrs = prop.GetCustomAttributes(true);
|
||||||
|
foreach (object attr in attrs)
|
||||||
{
|
{
|
||||||
settingElements.Add(new SettingElement(element, elementAttribute.Name, elementAttribute.OrderIndex));
|
if (attr is ElementAttribute elementAttribute)
|
||||||
break;
|
{
|
||||||
|
settingElements.Add(new SettingElement(element, elementAttribute.Name, elementAttribute.OrderIndex));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
settingElements = settingElements.OrderBy(x => x.OrderIndex).ToList();
|
settingElements = settingElements.OrderBy(x => x.OrderIndex).ToList();
|
||||||
if (MainWindow.PluginsSettings.ContainsKey(pluginName))
|
if (MainWindow.PluginsSettings.ContainsKey(PluginName))
|
||||||
{
|
{
|
||||||
MainWindow.PluginsSettings[pluginName] = settingElements;
|
MainWindow.PluginsSettings[PluginName] = settingElements;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MainWindow.PluginsSettings.Add(PluginName, settingElements);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MainWindow.PluginsSettings.Add(pluginName, settingElements);
|
stop = true;
|
||||||
|
MainWindow.Logger.Log(ex.ToString(), "Plugin");
|
||||||
|
_ = MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
Exit();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,14 +300,14 @@ namespace DesktopMagic
|
|||||||
|
|
||||||
private void Window_LocationChanged(object sender, EventArgs e)
|
private void Window_LocationChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
key.SetValue(pluginName + "WindowTop", this.Top);
|
key.SetValue(PluginName + "WindowTop", this.Top);
|
||||||
key.SetValue(pluginName + "WindowLeft", this.Left);
|
key.SetValue(PluginName + "WindowLeft", this.Left);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
|
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||||
{
|
{
|
||||||
key.SetValue(pluginName + "WindowHeight", this.Height);
|
key.SetValue(PluginName + "WindowHeight", this.Height);
|
||||||
key.SetValue(pluginName + "WindowWidth", this.Width);
|
key.SetValue(PluginName + "WindowWidth", this.Width);
|
||||||
tileBar.CaptionHeight = this.ActualHeight - 10;
|
tileBar.CaptionHeight = this.ActualHeight - 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
- [IPluginData](#T-DesktopMagicPluginAPI-IPluginData 'DesktopMagicPluginAPI.IPluginData')
|
- [IPluginData](#T-DesktopMagicPluginAPI-IPluginData 'DesktopMagicPluginAPI.IPluginData')
|
||||||
- [Color](#P-DesktopMagicPluginAPI-IPluginData-Color 'DesktopMagicPluginAPI.IPluginData.Color')
|
- [Color](#P-DesktopMagicPluginAPI-IPluginData-Color 'DesktopMagicPluginAPI.IPluginData.Color')
|
||||||
- [Font](#P-DesktopMagicPluginAPI-IPluginData-Font 'DesktopMagicPluginAPI.IPluginData.Font')
|
- [Font](#P-DesktopMagicPluginAPI-IPluginData-Font 'DesktopMagicPluginAPI.IPluginData.Font')
|
||||||
|
- [PluginName](#P-DesktopMagicPluginAPI-IPluginData-PluginName 'DesktopMagicPluginAPI.IPluginData.PluginName')
|
||||||
|
- [PluginPath](#P-DesktopMagicPluginAPI-IPluginData-PluginPath 'DesktopMagicPluginAPI.IPluginData.PluginPath')
|
||||||
- [WindowPosition](#P-DesktopMagicPluginAPI-IPluginData-WindowPosition 'DesktopMagicPluginAPI.IPluginData.WindowPosition')
|
- [WindowPosition](#P-DesktopMagicPluginAPI-IPluginData-WindowPosition 'DesktopMagicPluginAPI.IPluginData.WindowPosition')
|
||||||
- [WindowSize](#P-DesktopMagicPluginAPI-IPluginData-WindowSize 'DesktopMagicPluginAPI.IPluginData.WindowSize')
|
- [WindowSize](#P-DesktopMagicPluginAPI-IPluginData-WindowSize 'DesktopMagicPluginAPI.IPluginData.WindowSize')
|
||||||
- [UpdateWindow()](#M-DesktopMagicPluginAPI-IPluginData-UpdateWindow 'DesktopMagicPluginAPI.IPluginData.UpdateWindow')
|
- [UpdateWindow()](#M-DesktopMagicPluginAPI-IPluginData-UpdateWindow 'DesktopMagicPluginAPI.IPluginData.UpdateWindow')
|
||||||
@@ -325,6 +327,20 @@ Gets the color of the main application.
|
|||||||
|
|
||||||
Gets the font of the main application.
|
Gets the font of the main application.
|
||||||
|
|
||||||
|
<a name='P-DesktopMagicPluginAPI-IPluginData-PluginName'></a>
|
||||||
|
### PluginName `property`
|
||||||
|
|
||||||
|
##### Summary
|
||||||
|
|
||||||
|
Gets the name of the plugin.
|
||||||
|
|
||||||
|
<a name='P-DesktopMagicPluginAPI-IPluginData-PluginPath'></a>
|
||||||
|
### PluginPath `property`
|
||||||
|
|
||||||
|
##### Summary
|
||||||
|
|
||||||
|
Gets the path of the parent directory of the plugin.
|
||||||
|
|
||||||
<a name='P-DesktopMagicPluginAPI-IPluginData-WindowPosition'></a>
|
<a name='P-DesktopMagicPluginAPI-IPluginData-WindowPosition'></a>
|
||||||
### WindowPosition `property`
|
### WindowPosition `property`
|
||||||
|
|
||||||
|
|||||||
@@ -281,6 +281,16 @@
|
|||||||
Gets the window position of the plugin window.
|
Gets the window position of the plugin window.
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:DesktopMagicPluginAPI.IPluginData.PluginName">
|
||||||
|
<summary>
|
||||||
|
Gets the name of the plugin.
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:DesktopMagicPluginAPI.IPluginData.PluginPath">
|
||||||
|
<summary>
|
||||||
|
Gets the path of the parent directory of the plugin.
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="M:DesktopMagicPluginAPI.IPluginData.UpdateWindow">
|
<member name="M:DesktopMagicPluginAPI.IPluginData.UpdateWindow">
|
||||||
<summary>
|
<summary>
|
||||||
Updates the plugin window.
|
Updates the plugin window.
|
||||||
|
|||||||
@@ -27,6 +27,16 @@ namespace DesktopMagicPluginAPI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
Point WindowPosition { get; }
|
Point WindowPosition { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the name of the plugin.
|
||||||
|
/// </summary>
|
||||||
|
string PluginName { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the path of the parent directory of the plugin.
|
||||||
|
/// </summary>
|
||||||
|
string PluginPath { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the plugin window.
|
/// Updates the plugin window.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user