using Avalonia; using Avalonia.Controls; namespace LanMountainDesktop.AirAppSdk; /// /// Base class for AirApp windows. /// public abstract class AirAppWindowBase : Window, IAirAppWindow { /// /// Gets the window descriptor. /// Override this to customize window configuration. /// public virtual AirAppWindowDescriptor Descriptor => new() { Width = 800, Height = 600, MinWidth = 400, MinHeight = 300, ChromeMode = AirAppWindowChromeMode.Standard, CanResize = true, ShowInTaskbar = true, ShowAsDialog = false }; /// /// Initializes a new instance of AirAppWindowBase. /// protected AirAppWindowBase() { ApplyDescriptor(Descriptor); } /// /// Called before the window is opened. /// public virtual Task OnWindowOpeningAsync() { return Task.CompletedTask; } /// /// Called after the window has been opened. /// public virtual void OnWindowOpened() { } /// /// Called when the window is closing. /// public virtual void OnWindowClosing(WindowClosingEventArgs e) { } /// /// Called after the window has been closed. /// public virtual void OnWindowClosed() { } /// /// Apply the window descriptor configuration. /// private void ApplyDescriptor(AirAppWindowDescriptor descriptor) { Width = descriptor.Width; Height = descriptor.Height; MinWidth = descriptor.MinWidth; MinHeight = descriptor.MinHeight; CanResize = descriptor.CanResize; ShowInTaskbar = descriptor.ShowInTaskbar; ShowAsDialog = descriptor.ShowAsDialog; // Apply chrome mode switch (descriptor.ChromeMode) { case AirAppWindowChromeMode.Standard: SystemDecorations = SystemDecorations.Full; break; case AirAppWindowChromeMode.Borderless: SystemDecorations = SystemDecorations.BorderOnly; break; case AirAppWindowChromeMode.FullScreen: SystemDecorations = SystemDecorations.None; WindowState = WindowState.FullScreen; break; case AirAppWindowChromeMode.Tool: SystemDecorations = SystemDecorations.Full; ShowInTaskbar = false; break; } } }