using System; using System.Drawing; using System.Threading; using System.Threading.Tasks; namespace DesktopMagic.Api; /// /// Provides an abstract base class for creating asynchronous plugins that can be integrated into the application, supporting periodic updates, /// rendering, and user interaction. /// /// Derive from this class to implement custom plugin functionality. The class defines lifecycle methods /// such as , , and 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. public abstract class AsyncPlugin : Plugin { /// /// Occurs once when the plugin gets activated. Override for async initialization. /// /// Token signaled when the host requests cancellation. public virtual Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask; /// /// Occurs once when the plugin gets deactivated. Override for async cleanup. /// /// Token signaled when the host requests cancellation. public virtual Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; /// /// Occurs when the elapses. /// /// public abstract Task MainAsync(CancellationToken cancellationToken); /// /// This method should not be called directly! Override and use for asynchronous plugin operations. /// /// This method only exists to fulfill base class requirements. /// Calling it will always result in an . /// Thrown if this method is called directly. Use MainAsync for plugin execution instead. public sealed override Bitmap? Main() { throw new InvalidOperationException($"AsyncPlugin.Main() should not be called directly. Override {nameof(MainAsync)} instead."); } }