using Avalonia.Controls; namespace LanMountainDesktop.AirAppSdk; /// /// Base class for AirApp desktop component widgets. /// Inherit from this to create custom desktop components. /// public abstract class AirAppWidgetBase : UserControl, IAirAppWidget { private IAirAppComponentContext? _context; /// /// Gets or sets the component context. /// public IAirAppComponentContext Context { get => _context ?? throw new InvalidOperationException("Context has not been set yet."); set { _context = value; OnContextSet(); } } /// /// Called when the context is first set. /// Override this to initialize based on context. /// protected virtual void OnContextSet() { } /// /// Called when the widget is attached to the desktop. /// public void OnAttached() { OnAttachedCore(); } /// /// Called when the widget is detached from the desktop. /// public void OnDetached() { OnDetachedCore(); } /// /// Called when the appearance has changed. /// /// New appearance snapshot public void OnAppearanceChanged(AirAppAppearanceSnapshot snapshot) { OnAppearanceChangedCore(snapshot); } /// /// Override this to handle widget attachment. /// protected virtual void OnAttachedCore() { } /// /// Override this to handle widget detachment. /// protected virtual void OnDetachedCore() { } /// /// Override this to handle appearance changes. /// /// New appearance snapshot protected virtual void OnAppearanceChangedCore(AirAppAppearanceSnapshot snapshot) { } }