Add plugin methods for changed themes, settings showing message boxes and logging

This commit is contained in:
Stone_Red
2025-12-25 01:22:39 +01:00
parent 4778f5673f
commit 43c77e6a36
7 changed files with 115 additions and 49 deletions
+15 -10
View File
@@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Drawing;
namespace DesktopMagic.Api;
@@ -8,14 +7,6 @@ namespace DesktopMagic.Api;
/// </summary>
public interface IPluginData
{
/// <summary>
/// Occurs when the application's theme has changed.
/// </summary>
/// <remarks>Subscribe to this event to be notified when the theme changes, allowing UI elements or
/// components to update their appearance accordingly. The event is raised after the theme change has been
/// applied.</remarks>
event EventHandler? ThemeChanged;
/// <summary>
/// Gets the current theme setting of the main application.
/// </summary>
@@ -45,4 +36,18 @@ public interface IPluginData
/// Updates the plugin window.
/// </summary>
void UpdateWindow();
/// <summary>
/// Logs a message to the application log.
/// </summary>
/// <param name="message">The message to log.</param>
/// <param name="level">The log level (Info, Warning, Error).</param>
void Log(string message, LogLevel level = LogLevel.Info);
/// <summary>
/// Shows a message box to the user.
/// </summary>
/// <param name="message">The message to display.</param>
/// <param name="title">The title of the message box.</param>
void ShowMessage(string message, string title);
}
+22
View File
@@ -0,0 +1,22 @@
namespace DesktopMagic.Api;
/// <summary>
/// Specifies the severity level of a log message.
/// </summary>
public enum LogLevel
{
/// <summary>
/// Informational message for general information.
/// </summary>
Info,
/// <summary>
/// Warning message indicating a potential issue.
/// </summary>
Warning,
/// <summary>
/// Error message indicating a failure or critical issue.
/// </summary>
Error
}
+22 -2
View File
@@ -7,8 +7,14 @@ using System.Drawing;
namespace DesktopMagic.Api;
/// <summary>
/// The plugin class.
/// Provides an abstract base class for creating plugins that can be integrated into the application, supporting periodic updates,
/// rendering, and user interaction.
/// </summary>
/// <remarks>Derive from this class to implement custom plugin functionality. The class defines lifecycle methods
/// such as <see cref="Start"/>, <see cref="Stop"/>, and <see cref="Main"/> for activation, deactivation, and periodic
/// execution. It also provides event handlers for mouse and theme interactions, as well as access to application data
/// and rendering configuration. Implementations should override relevant methods to respond to user input, update
/// intervals, and configuration changes as needed.</remarks>
public abstract class Plugin
{
[Setting("desktopmagic-horizontal-alignment", "Horizontal Alignment", -999)]
@@ -86,4 +92,18 @@ public abstract class Plugin
public virtual void OnMouseWheel(Point position, int delta)
{
}
}
/// <summary>
/// Occurs when the application's theme has changed.
/// </summary>
public virtual void OnThemeChanged()
{
}
/// <summary>
/// Invoked when the settings have changed to allow derived classes to respond to configuration updates.
/// </summary>
public virtual void OnSettingsChanged()
{
}
}